[patch 2/6] statistics infrastructure - prerequisite: parser enhancement
- From: Martin Peschke <mp3@xxxxxxxxxx>
- Date: Wed, 14 Dec 2005 17:13:47 +0100
[patch 2/6] statistics infrastructure - prerequisite: parser enhancement
This patch adds two match_* derivates for 64 bit operands to the parser
library.
Signed-off-by: Martin Peschke <mp3@xxxxxxxxxx>
---
include/linux/parser.h | 2 +
lib/parser.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff -Nurp b/include/linux/parser.h c/include/linux/parser.h
--- b/include/linux/parser.h 2005-10-28 02:02:08.000000000 +0200
+++ c/include/linux/parser.h 2005-12-14 13:44:09.000000000 +0100
@@ -31,3 +31,5 @@ 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_u64(substring_t *, u64 *result, int);
+int match_s64(substring_t *, s64 *result, int);
diff -Nurp b/lib/parser.c c/lib/parser.c
--- b/lib/parser.c 2005-10-28 02:02:08.000000000 +0200
+++ c/lib/parser.c 2005-12-14 13:44:09.000000000 +0100
@@ -140,6 +140,64 @@ static int match_number(substring_t *s,
}
/**
+ * match_u64: 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 u64 represented
+ * by the string and returns 0. Returns either -ENOMEM or -EINVAL on failure.
+ */
+int match_u64(substring_t *s, u64 *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_strtoull(buf, &endp, base);
+ ret = 0;
+ if (endp == buf)
+ ret = -EINVAL;
+ kfree(buf);
+ return ret;
+}
+
+/**
+ * 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 +276,5 @@ EXPORT_SYMBOL(match_octal);
EXPORT_SYMBOL(match_hex);
EXPORT_SYMBOL(match_strcpy);
EXPORT_SYMBOL(match_strdup);
+EXPORT_SYMBOL(match_u64);
+EXPORT_SYMBOL(match_s64);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Relevant Pages
- i2c_use_client broken
... int i2c_use_client(struct i2c_client *client) ... because i2c_inc_use_client returns 0 on success. ... send the line "unsubscribe linux-kernel" in ... (Linux-Kernel) - Re: Request critique of first program
... Returns a pointer to an asplit_result struct (unless unable to ... Success is indicated by SUCCESS, ... const char *out_file_b, ... const long int num_lines); ... (comp.lang.c) - Re: Evaluation of C program
... because the 10th character in the trial substring does not match ... compared to the current char. ... Once the (lgh - 1)th char ... void initnext(int *next, const char *id, int lgh) ... (comp.lang.c) - Copy and Paste in a DataGridView with Ctrl-C and Ctrl-V
... private bool _shiftDown = false; ... const int WM_KEYDOWN = 0x0100; ... handledMessage = PerformPaste; ... bool success = false; ... (microsoft.public.dotnet.framework.windowsforms) - Request critique of first program
... long int num_rem_lines; ... Returns a pointer to an asplit_result struct (unless unable to ... Success is indicated by SUCCESS, ... Read from standard input, writing first 100 lines to output1 ... (comp.lang.c) |
|