From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail144.messagelabs.com (mail144.messagelabs.com [216.82.254.51]) by kanga.kvack.org (Postfix) with SMTP id 01C0F6B0011 for ; Wed, 27 Apr 2011 12:28:44 -0400 (EDT) Date: Wed, 27 Apr 2011 09:28:41 -0700 From: Randy Dunlap Subject: Re: [RFC PATCH 1/3] Add string parsing function get_next_ulong Message-Id: <20110427092841.1442fe5f.rdunlap@xenotime.net> In-Reply-To: <1303921007-1769-2-git-send-email-sassmann@kpanic.de> References: <1303921007-1769-1-git-send-email-sassmann@kpanic.de> <1303921007-1769-2-git-send-email-sassmann@kpanic.de> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Stefan Assmann Cc: linux-mm@kvack.org, tony.luck@intel.com, andi@firstfloor.org, mingo@elte.hu, hpa@zytor.com, rick@vanrein.org, akpm@linux-foundation.org, lwoodman@redhat.com, riel@redhat.com On Wed, 27 Apr 2011 18:16:45 +0200 Stefan Assmann wrote: > Adding this function to allow easy parsing of unsigned long values from the > beginning of strings. Convenience function to parse pointers from the kernel > command line. > > Signed-off-by: Stefan Assmann > --- > include/linux/kernel.h | 1 + > lib/cmdline.c | 35 +++++++++++++++++++++++++++++++++++ > 2 files changed, 36 insertions(+), 0 deletions(-) > > diff --git a/include/linux/kernel.h b/include/linux/kernel.h > index 2fe6e84..b6ded39 100644 > --- a/include/linux/kernel.h > +++ b/include/linux/kernel.h > @@ -218,6 +218,7 @@ extern int vsscanf(const char *, const char *, va_list) > > extern int get_option(char **str, int *pint); > extern char *get_options(const char *str, int nints, int *ints); > +extern int get_next_ulong(char **str, unsigned long *val, char sep, int base); > extern unsigned long long memparse(const char *ptr, char **retptr); > > extern int core_kernel_text(unsigned long addr); > diff --git a/lib/cmdline.c b/lib/cmdline.c > index f5f3ad8..82a6616 100644 > --- a/lib/cmdline.c > +++ b/lib/cmdline.c > @@ -114,6 +114,41 @@ char *get_options(const char *str, int nints, int *ints) > } > > /** > + * get_next_ulong - Parse unsigned long at the beginning of a string > + * @strp: (output) String to be parsed ^ input/output > + * @val: (output) unsigned long carrying the result > + * @sep: character specifying the separator > + * @base: number system of the parsed value > + * > + * This function parses an unsigned long value at the beginning of a > + * string. The string may begin with a separator or an unsigned long > + * value. > + * After the function is run val will contain the parsed value and strp @val @strp > + * will point to the character *after* the parsed unsigned long. > + * > + * In the error case 0 is returned, val and *strp stay unaltered. @val and @strp > + * Otherwise return 1. > + */ > +int get_next_ulong(char **strp, unsigned long *val, char sep, int base) > +{ > + char *tmp; > + > + if (!strp || !(*strp)) > + return 0; > + > + tmp = *strp; > + if (*tmp == sep) > + tmp++; > + > + *val = simple_strtoul(tmp, strp, base); > + > + if (tmp == *strp) > + return 0; /* no new value parsed */ > + else > + return 1; > +} > + > +/** > * memparse - parse a string with mem suffixes into a number > * @ptr: Where parse begins > * @retptr: (output) Optional pointer to next char after parse completes > -- --- ~Randy *** Remember to use Documentation/SubmitChecklist when testing your code *** -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: email@kvack.org