/* * Undef these macros so that the functions that we provide * here will have the correct names regardless of how string.h * may have chosen to #define them.
*/ #undef memcpy #undef memset #undef memcmp
/** * simple_strtoull - convert a string to an unsigned long long * @cp: The start of the string * @endp: A pointer to the end of the parsed string will be placed here * @base: The number base to use
*/ unsignedlonglong simple_strtoull(constchar *cp, char **endp, unsignedint base)
{ unsignedlonglong result = 0;
/** * strstr - Find the first substring in a %NUL terminated string * @s1: The string to be searched * @s2: The string to search for
*/ char *strstr(constchar *s1, constchar *s2)
{
size_t l1, l2;
l2 = strlen(s2); if (!l2) return (char *)s1;
l1 = strlen(s1); while (l1 >= l2) {
l1--; if (!memcmp(s1, s2, l2)) return (char *)s1;
s1++;
} return NULL;
}
/** * strchr - Find the first occurrence of the character c in the string s. * @s: the string to be searched * @c: the character to search for
*/ char *strchr(constchar *s, int c)
{ while (*s != (char)c) if (*s++ == '\0') return NULL; return (char *)s;
}
/* * Convert non-negative integer string representation in explicitly given radix * to an integer. * Return number of characters consumed maybe or-ed with overflow bit. * If overflow occurs, result integer (incorrect) is still returned. * * Don't you dare use this function.
*/ staticunsignedint _parse_integer(constchar *s, unsignedint base, unsignedlonglong *p)
{ unsignedlonglong res; unsignedint rv;
res = 0;
rv = 0; while (1) { unsignedint c = *s; unsignedint lc = c | 0x20; /* don't tolower() this line */ unsignedint val;
if ('0' <= c && c <= '9')
val = c - '0'; elseif ('a' <= lc && lc <= 'f')
val = lc - 'a' + 10; else break;
if (val >= base) break; /* * Check for overflow only if we are within range of * it in the max base we support (16)
*/ if (unlikely(res & (~0ull << 60))) { if (res > __div_u64(ULLONG_MAX - val, base))
rv |= KSTRTOX_OVERFLOW;
}
res = res * base + val;
rv++;
s++;
}
*p = res; return rv;
}
s = _parse_integer_fixup_radix(s, &base);
rv = _parse_integer(s, base, &_res); if (rv & KSTRTOX_OVERFLOW) return -ERANGE; if (rv == 0) return -EINVAL;
s += rv; if (*s == '\n')
s++; if (*s) return -EINVAL;
*res = _res; return 0;
}
/** * kstrtoull - convert a string to an unsigned long long * @s: The start of the string. The string must be null-terminated, and may also * include a single newline before its terminating null. The first character * may also be a plus sign, but not a minus sign. * @base: The number base to use. The maximum supported base is 16. If base is * given as 0, then the base of the string is automatically detected with the * conventional semantics - If it begins with 0x the number will be parsed as a * hexadecimal (case insensitive), if it otherwise begins with 0, it will be * parsed as an octal number. Otherwise it will be parsed as a decimal. * @res: Where to write the result of the conversion on success. * * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. * Used as a replacement for the obsolete simple_strtoull. Return code must * be checked.
*/ int kstrtoull(constchar *s, unsignedint base, unsignedlonglong *res)
{ if (s[0] == '+')
s++; return _kstrtoull(s, base, res);
}
/** * boot_kstrtoul - convert a string to an unsigned long * @s: The start of the string. The string must be null-terminated, and may also * include a single newline before its terminating null. The first character * may also be a plus sign, but not a minus sign. * @base: The number base to use. The maximum supported base is 16. If base is * given as 0, then the base of the string is automatically detected with the * conventional semantics - If it begins with 0x the number will be parsed as a * hexadecimal (case insensitive), if it otherwise begins with 0, it will be * parsed as an octal number. Otherwise it will be parsed as a decimal. * @res: Where to write the result of the conversion on success. * * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. * Used as a replacement for the simple_strtoull.
*/ int boot_kstrtoul(constchar *s, unsignedint base, unsignedlong *res)
{ /* * We want to shortcut function call, but * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0.
*/ if (sizeof(unsignedlong) == sizeof(unsignedlonglong) &&
__alignof__(unsignedlong) == __alignof__(unsignedlonglong)) return kstrtoull(s, base, (unsignedlonglong *)res); else return _kstrtoul(s, base, res);
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.