linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Assmann <sassmann@kpanic.de>
To: linux-mm@kvack.org
Cc: 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, sassmann@kpanic.de
Subject: [RFC PATCH 1/3] Add string parsing function get_next_ulong
Date: Wed, 27 Apr 2011 18:16:45 +0200	[thread overview]
Message-ID: <1303921007-1769-2-git-send-email-sassmann@kpanic.de> (raw)
In-Reply-To: <1303921007-1769-1-git-send-email-sassmann@kpanic.de>

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 <sassmann@kpanic.de>
---
 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
+ *	@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
+ *	will point to the character *after* the parsed unsigned long.
+ *
+ *	In the error case 0 is returned, val and *strp stay unaltered.
+ *	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
-- 
1.7.4

--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2011-04-27 16:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-27 16:16 [RFC PATCH 0/3] support for broken memory modules (BadRAM) Stefan Assmann
2011-04-27 16:16 ` Stefan Assmann [this message]
2011-04-27 16:28   ` [RFC PATCH 1/3] Add string parsing function get_next_ulong Randy Dunlap
2011-04-27 16:16 ` [RFC PATCH 2/3] support for broken memory modules (BadRAM) Stefan Assmann
2011-04-27 21:12   ` Andi Kleen
2011-04-28  6:34     ` Stefan Assmann
2011-04-28 15:08       ` Andi Kleen
2011-04-28 15:51         ` Stefan Assmann
2011-04-28 17:44           ` Luck, Tony
2011-04-29  9:14           ` Stefan Assmann
2011-04-27 16:16 ` [RFC PATCH 3/3] Add documentation and credits for BadRAM Stefan Assmann
2011-04-27 16:49   ` Randy Dunlap
2011-04-27 20:05     ` Stefan Assmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1303921007-1769-2-git-send-email-sassmann@kpanic.de \
    --to=sassmann@kpanic.de \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=hpa@zytor.com \
    --cc=linux-mm@kvack.org \
    --cc=lwoodman@redhat.com \
    --cc=mingo@elte.hu \
    --cc=rick@vanrein.org \
    --cc=riel@redhat.com \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).