From: Andrew Morton <akpm@osdl.org>
To: Martin Peschke <mp3@de.ibm.com>
Cc: linux-kernel@vger.kernel.org, ak@suse.de, hch@infradead.org,
arjan@infradead.org, James.Smart@Emulex.Com,
James.Bottomley@SteelEye.com
Subject: Re: [RFC] [Patch 2/8] statistics infrastructure - prerequisite: parser enhancement
Date: Tue, 16 May 2006 11:11:41 -0700 [thread overview]
Message-ID: <20060516111141.1cff68e9.akpm@osdl.org> (raw)
In-Reply-To: <446A0FBE.2030105@de.ibm.com>
Martin Peschke <mp3@de.ibm.com> wrote:
>
> This patch adds two match_* derivates for 64 bit operands to the parser
> library.
>
> 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);
Your email client does space-stuffing, so this won't apply (ok, it might
apply if my email client knew how to space-unstuff, but it doesn't).
> 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-15 17:56:25.000000000 +0200
> @@ -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;
> +}
These are identical. If we _really_ need one for signed and one for
unsigned then we could at least do
match_s64(..., s64 *result, ...)
{
return match_u64(..., (u64 *)result, ...);
}
That's if we do need one for signed and one for unsigned..
next prev parent reply other threads:[~2006-05-16 18:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-16 17:45 Martin Peschke
2006-05-16 18:11 ` Andrew Morton [this message]
2006-05-17 12:54 ` Martin Peschke
2006-05-16 18:35 ` Chase Venters
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=20060516111141.1cff68e9.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=James.Bottomley@SteelEye.com \
--cc=James.Smart@Emulex.Com \
--cc=ak@suse.de \
--cc=arjan@infradead.org \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mp3@de.ibm.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
all inboxes | Powered by JetHome®