Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 115176
b: refs/heads/master
c: 9d85db2
h: refs/heads/master
v: v3
  • Loading branch information
Harvey Harrison authored and Linus Torvalds committed Oct 16, 2008
1 parent 012f084 commit 0e723cf
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 50 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 22d27051b4b2a2650c54fa3f08c2c271c6234a2f
refs/heads/master: 9d85db2244d71fa4f2f9747a090c1920f07a8b4b
117 changes: 68 additions & 49 deletions trunk/lib/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base)
return simple_strtoull(cp, endp, base);
}


/**
* strict_strtoul - convert a string to an unsigned long strictly
* @cp: The string to be converted
Expand All @@ -158,7 +157,27 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base)
* simple_strtoul just ignores the successive invalid characters and
* return the converted value of prefix part of the string.
*/
int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)
{
char *tail;
unsigned long val;
size_t len;

*res = 0;
len = strlen(cp);
if (len == 0)
return -EINVAL;

val = simple_strtoul(cp, &tail, base);
if ((*tail == '\0') ||
((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
*res = val;
return 0;
}

return -EINVAL;
}
EXPORT_SYMBOL(strict_strtoul);

/**
* strict_strtol - convert a string to a long strictly
Expand All @@ -172,7 +191,20 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
* It returns 0 if conversion is successful and *res is set to the converted
* value, otherwise it returns -EINVAL and *res is set to 0.
*/
int strict_strtol(const char *cp, unsigned int base, long *res);
int strict_strtol(const char *cp, unsigned int base, long *res)
{
int ret;
if (*cp == '-') {
ret = strict_strtoul(cp + 1, base, (unsigned long *)res);
if (!ret)
*res = -(*res);
} else {
ret = strict_strtoul(cp, base, (unsigned long *)res);
}

return ret;
}
EXPORT_SYMBOL(strict_strtol);

/**
* strict_strtoull - convert a string to an unsigned long long strictly
Expand All @@ -196,7 +228,27 @@ int strict_strtol(const char *cp, unsigned int base, long *res);
* simple_strtoull just ignores the successive invalid characters and
* return the converted value of prefix part of the string.
*/
int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res);
int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res)
{
char *tail;
unsigned long long val;
size_t len;

*res = 0;
len = strlen(cp);
if (len == 0)
return -EINVAL;

val = simple_strtoull(cp, &tail, base);
if ((*tail == '\0') ||
((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
*res = val;
return 0;
}

return -EINVAL;
}
EXPORT_SYMBOL(strict_strtoull);

/**
* strict_strtoll - convert a string to a long long strictly
Expand All @@ -210,53 +262,20 @@ int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res);
* It returns 0 if conversion is successful and *res is set to the converted
* value, otherwise it returns -EINVAL and *res is set to 0.
*/
int strict_strtoll(const char *cp, unsigned int base, long long *res);

#define define_strict_strtoux(type, valtype) \
int strict_strtou##type(const char *cp, unsigned int base, valtype *res)\
{ \
char *tail; \
valtype val; \
size_t len; \
\
*res = 0; \
len = strlen(cp); \
if (len == 0) \
return -EINVAL; \
\
val = simple_strtou##type(cp, &tail, base); \
if ((*tail == '\0') || \
((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {\
*res = val; \
return 0; \
} \
\
return -EINVAL; \
} \

#define define_strict_strtox(type, valtype) \
int strict_strto##type(const char *cp, unsigned int base, valtype *res) \
{ \
int ret; \
if (*cp == '-') { \
ret = strict_strtou##type(cp+1, base, res); \
if (!ret) \
*res = -(*res); \
} else \
ret = strict_strtou##type(cp, base, res); \
\
return ret; \
} \

define_strict_strtoux(l, unsigned long)
define_strict_strtox(l, long)
define_strict_strtoux(ll, unsigned long long)
define_strict_strtox(ll, long long)
int strict_strtoll(const char *cp, unsigned int base, long long *res)
{
int ret;
if (*cp == '-') {
ret = strict_strtoull(cp + 1, base, (unsigned long long *)res);
if (!ret)
*res = -(*res);
} else {
ret = strict_strtoull(cp, base, (unsigned long long *)res);
}

EXPORT_SYMBOL(strict_strtoul);
EXPORT_SYMBOL(strict_strtol);
return ret;
}
EXPORT_SYMBOL(strict_strtoll);
EXPORT_SYMBOL(strict_strtoull);

static int skip_atoi(const char **s)
{
Expand Down

0 comments on commit 0e723cf

Please sign in to comment.