1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
9 * ----------------------------------------------------------------------- */
12 * Very basic string functions
18 * This file gets included in compressed/string.c which might pull in
19 * string_32.h and which in turn maps memcmp to __builtin_memcmp(). Undo
23 int memcmp(const void *s1, const void *s2, size_t len)
26 asm("repe; cmpsb; setnz %0"
27 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
31 int strcmp(const char *str1, const char *str2)
33 const unsigned char *s1 = (const unsigned char *)str1;
34 const unsigned char *s2 = (const unsigned char *)str2;
47 int strncmp(const char *cs, const char *ct, size_t count)
55 return c1 < c2 ? -1 : 1;
63 size_t strnlen(const char *s, size_t maxlen)
66 while (*es && maxlen) {
74 unsigned int atou(const char *s)
78 i = i * 10 + (*s++ - '0');
82 /* Works only for digits and letters, but small and fast */
83 #define TOLOWER(x) ((x) | 0x20)
85 static unsigned int simple_guess_base(const char *cp)
88 if (TOLOWER(cp[1]) == 'x' && isxdigit(cp[2]))
98 * simple_strtoull - convert a string to an unsigned long long
99 * @cp: The start of the string
100 * @endp: A pointer to the end of the parsed string will be placed here
101 * @base: The number base to use
104 unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
106 unsigned long long result = 0;
109 base = simple_guess_base(cp);
111 if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x')
114 while (isxdigit(*cp)) {
117 value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10;
120 result = result * base + value;
130 * strlen - Find the length of a string
131 * @s: The string to be sized
133 size_t strlen(const char *s)
137 for (sc = s; *sc != '\0'; ++sc)
143 * strstr - Find the first substring in a %NUL terminated string
144 * @s1: The string to be searched
145 * @s2: The string to search for
147 char *strstr(const char *s1, const char *s2)
157 if (!memcmp(s1, s2, l2))