linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Peschke <mp3@de.ibm.com>
To: Andrew Morton <akpm@osdl.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [Patch 2/6] statistics infrastructure - prerequisite: parser enhancement
Date: Wed, 24 May 2006 14:30:45 +0200	[thread overview]
Message-ID: <1148473845.2934.13.camel@dyn-9-152-230-71.boeblingen.de.ibm.com> (raw)

This patch adds a match_* derivate for 64 bit operands to the parser library.

Signed-off-by: Martin Peschke <mp3@de.ibm.com>
---

 include/linux/parser.h |    1 +
 lib/parser.c           |   30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff -Nurp a/lib/parser.c b/lib/parser.c
--- a/lib/parser.c	2006-03-20 06:53:29.000000000 +0100
+++ b/lib/parser.c	2006-05-19 16:01:48.000000000 +0200
@@ -140,6 +140,35 @@ static int match_number(substring_t *s, 
 }
 
 /**
+ * match_s64: scan a number in the given base from a substring_t
+ * @s: substring to be scanned
+ * @result: resulting integer on success
+ * @base: base to use when converting string
+ *
+ * Description: Given a &substring_t and a base, attempts to parse the substring
+ * as a number in that base. On success, sets @result to the s64 represented
+ * by the string and returns 0. Returns either -ENOMEM or -EINVAL on failure.
+ */
+int match_s64(substring_t *s, s64 *result, int base)
+{
+	char *endp;
+	char *buf;
+	int ret;
+
+	buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+	memcpy(buf, s->from, s->to - s->from);
+	buf[s->to - s->from] = '\0';
+	*result = simple_strtoll(buf, &endp, base);
+	ret = 0;
+	if (endp == buf)
+		ret = -EINVAL;
+	kfree(buf);
+	return ret;
+}
+
+/**
  * match_int: - scan a decimal representation of an integer from a substring_t
  * @s: substring_t to be scanned
  * @result: resulting integer on success
@@ -218,3 +247,4 @@ EXPORT_SYMBOL(match_octal);
 EXPORT_SYMBOL(match_hex);
 EXPORT_SYMBOL(match_strcpy);
 EXPORT_SYMBOL(match_strdup);
+EXPORT_SYMBOL(match_s64);
diff -Nurp a/include/linux/parser.h b/include/linux/parser.h
--- a/include/linux/parser.h	2006-03-20 06:53:29.000000000 +0100
+++ b/include/linux/parser.h	2006-05-19 16:01:48.000000000 +0200
@@ -31,3 +31,4 @@ int match_octal(substring_t *, int *resu
 int match_hex(substring_t *, int *result);
 void match_strcpy(char *, substring_t *);
 char *match_strdup(substring_t *);
+int match_s64(substring_t *, s64 *result, int);



             reply	other threads:[~2006-05-24 12:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-24 12:30 Martin Peschke [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-05-19 16:10 [Patch 2/6] statistics infrastructure - prerequisite: parser enhancement Martin Peschke
2006-05-23 12:54 ` Balbir Singh
2006-05-23 13:13   ` Martin Peschke
2005-12-14 16:13 [patch " Martin Peschke

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=1148473845.2934.13.camel@dyn-9-152-230-71.boeblingen.de.ibm.com \
    --to=mp3@de.ibm.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /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).