Commit 51a0f0f6 authored by Jesper Juhl's avatar Jesper Juhl Committed by Linus Torvalds

[PATCH] lib/string.c cleanup: whitespace and CodingStyle cleanups

Removes some blank lines, removes some trailing whitespace, adds spaces
after commas and a few similar changes.
Signed-off-by: default avatarJesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent d97b3214
...@@ -39,8 +39,10 @@ int strnicmp(const char *s1, const char *s2, size_t len) ...@@ -39,8 +39,10 @@ int strnicmp(const char *s1, const char *s2, size_t len)
c1 = 0; c2 = 0; c1 = 0; c2 = 0;
if (len) { if (len) {
do { do {
c1 = *s1; c2 = *s2; c1 = *s1;
s1++; s2++; c2 = *s2;
s1++;
s2++;
if (!c1) if (!c1)
break; break;
if (!c2) if (!c2)
...@@ -55,7 +57,6 @@ int strnicmp(const char *s1, const char *s2, size_t len) ...@@ -55,7 +57,6 @@ int strnicmp(const char *s1, const char *s2, size_t len)
} }
return (int)c1 - (int)c2; return (int)c1 - (int)c2;
} }
EXPORT_SYMBOL(strnicmp); EXPORT_SYMBOL(strnicmp);
#endif #endif
...@@ -66,7 +67,7 @@ EXPORT_SYMBOL(strnicmp); ...@@ -66,7 +67,7 @@ EXPORT_SYMBOL(strnicmp);
* @src: Where to copy the string from * @src: Where to copy the string from
*/ */
#undef strcpy #undef strcpy
char * strcpy(char * dest,const char *src) char *strcpy(char *dest, const char *src)
{ {
char *tmp = dest; char *tmp = dest;
...@@ -91,12 +92,13 @@ EXPORT_SYMBOL(strcpy); ...@@ -91,12 +92,13 @@ EXPORT_SYMBOL(strcpy);
* count, the remainder of @dest will be padded with %NUL. * count, the remainder of @dest will be padded with %NUL.
* *
*/ */
char * strncpy(char * dest,const char *src,size_t count) char *strncpy(char *dest, const char *src, size_t count)
{ {
char *tmp = dest; char *tmp = dest;
while (count) { while (count) {
if ((*tmp = *src) != 0) src++; if ((*tmp = *src) != 0)
src++;
tmp++; tmp++;
count--; count--;
} }
...@@ -122,7 +124,7 @@ size_t strlcpy(char *dest, const char *src, size_t size) ...@@ -122,7 +124,7 @@ size_t strlcpy(char *dest, const char *src, size_t size)
size_t ret = strlen(src); size_t ret = strlen(src);
if (size) { if (size) {
size_t len = (ret >= size) ? size-1 : ret; size_t len = (ret >= size) ? size - 1 : ret;
memcpy(dest, src, len); memcpy(dest, src, len);
dest[len] = '\0'; dest[len] = '\0';
} }
...@@ -138,7 +140,7 @@ EXPORT_SYMBOL(strlcpy); ...@@ -138,7 +140,7 @@ EXPORT_SYMBOL(strlcpy);
* @src: The string to append to it * @src: The string to append to it
*/ */
#undef strcat #undef strcat
char * strcat(char * dest, const char * src) char *strcat(char *dest, const char *src)
{ {
char *tmp = dest; char *tmp = dest;
...@@ -162,7 +164,7 @@ EXPORT_SYMBOL(strcat); ...@@ -162,7 +164,7 @@ EXPORT_SYMBOL(strcat);
* Note that in contrast to strncpy, strncat ensures the result is * Note that in contrast to strncpy, strncat ensures the result is
* terminated. * terminated.
*/ */
char * strncat(char *dest, const char *src, size_t count) char *strncat(char *dest, const char *src, size_t count)
{ {
char *tmp = dest; char *tmp = dest;
...@@ -176,7 +178,6 @@ char * strncat(char *dest, const char *src, size_t count) ...@@ -176,7 +178,6 @@ char * strncat(char *dest, const char *src, size_t count)
} }
} }
} }
return tmp; return tmp;
} }
EXPORT_SYMBOL(strncat); EXPORT_SYMBOL(strncat);
...@@ -216,7 +217,7 @@ EXPORT_SYMBOL(strlcat); ...@@ -216,7 +217,7 @@ EXPORT_SYMBOL(strlcat);
* @ct: Another string * @ct: Another string
*/ */
#undef strcmp #undef strcmp
int strcmp(const char * cs,const char * ct) int strcmp(const char *cs, const char *ct)
{ {
register signed char __res; register signed char __res;
...@@ -224,7 +225,6 @@ int strcmp(const char * cs,const char * ct) ...@@ -224,7 +225,6 @@ int strcmp(const char * cs,const char * ct)
if ((__res = *cs - *ct++) != 0 || !*cs++) if ((__res = *cs - *ct++) != 0 || !*cs++)
break; break;
} }
return __res; return __res;
} }
EXPORT_SYMBOL(strcmp); EXPORT_SYMBOL(strcmp);
...@@ -237,7 +237,7 @@ EXPORT_SYMBOL(strcmp); ...@@ -237,7 +237,7 @@ EXPORT_SYMBOL(strcmp);
* @ct: Another string * @ct: Another string
* @count: The maximum number of bytes to compare * @count: The maximum number of bytes to compare
*/ */
int strncmp(const char * cs,const char * ct,size_t count) int strncmp(const char *cs, const char *ct, size_t count)
{ {
register signed char __res = 0; register signed char __res = 0;
...@@ -246,7 +246,6 @@ int strncmp(const char * cs,const char * ct,size_t count) ...@@ -246,7 +246,6 @@ int strncmp(const char * cs,const char * ct,size_t count)
break; break;
count--; count--;
} }
return __res; return __res;
} }
EXPORT_SYMBOL(strncmp); EXPORT_SYMBOL(strncmp);
...@@ -258,12 +257,12 @@ EXPORT_SYMBOL(strncmp); ...@@ -258,12 +257,12 @@ EXPORT_SYMBOL(strncmp);
* @s: The string to be searched * @s: The string to be searched
* @c: The character to search for * @c: The character to search for
*/ */
char * strchr(const char * s, int c) char *strchr(const char *s, int c)
{ {
for(; *s != (char) c; ++s) for (; *s != (char)c; ++s)
if (*s == '\0') if (*s == '\0')
return NULL; return NULL;
return (char *) s; return (char *)s;
} }
EXPORT_SYMBOL(strchr); EXPORT_SYMBOL(strchr);
#endif #endif
...@@ -274,7 +273,7 @@ EXPORT_SYMBOL(strchr); ...@@ -274,7 +273,7 @@ EXPORT_SYMBOL(strchr);
* @s: The string to be searched * @s: The string to be searched
* @c: The character to search for * @c: The character to search for
*/ */
char * strrchr(const char * s, int c) char *strrchr(const char *s, int c)
{ {
const char *p = s + strlen(s); const char *p = s + strlen(s);
do { do {
...@@ -296,8 +295,8 @@ EXPORT_SYMBOL(strrchr); ...@@ -296,8 +295,8 @@ EXPORT_SYMBOL(strrchr);
char *strnchr(const char *s, size_t count, int c) char *strnchr(const char *s, size_t count, int c)
{ {
for (; count-- && *s != '\0'; ++s) for (; count-- && *s != '\0'; ++s)
if (*s == (char) c) if (*s == (char)c)
return (char *) s; return (char *)s;
return NULL; return NULL;
} }
EXPORT_SYMBOL(strnchr); EXPORT_SYMBOL(strnchr);
...@@ -308,7 +307,7 @@ EXPORT_SYMBOL(strnchr); ...@@ -308,7 +307,7 @@ EXPORT_SYMBOL(strnchr);
* strlen - Find the length of a string * strlen - Find the length of a string
* @s: The string to be sized * @s: The string to be sized
*/ */
size_t strlen(const char * s) size_t strlen(const char *s)
{ {
const char *sc; const char *sc;
...@@ -325,7 +324,7 @@ EXPORT_SYMBOL(strlen); ...@@ -325,7 +324,7 @@ EXPORT_SYMBOL(strlen);
* @s: The string to be sized * @s: The string to be sized
* @count: The maximum number of bytes to search * @count: The maximum number of bytes to search
*/ */
size_t strnlen(const char * s, size_t count) size_t strnlen(const char *s, size_t count)
{ {
const char *sc; const char *sc;
...@@ -358,7 +357,6 @@ size_t strspn(const char *s, const char *accept) ...@@ -358,7 +357,6 @@ size_t strspn(const char *s, const char *accept)
return count; return count;
++count; ++count;
} }
return count; return count;
} }
...@@ -384,7 +382,6 @@ size_t strcspn(const char *s, const char *reject) ...@@ -384,7 +382,6 @@ size_t strcspn(const char *s, const char *reject)
} }
++count; ++count;
} }
return count; return count;
} }
EXPORT_SYMBOL(strcspn); EXPORT_SYMBOL(strcspn);
...@@ -395,14 +392,14 @@ EXPORT_SYMBOL(strcspn); ...@@ -395,14 +392,14 @@ EXPORT_SYMBOL(strcspn);
* @cs: The string to be searched * @cs: The string to be searched
* @ct: The characters to search for * @ct: The characters to search for
*/ */
char * strpbrk(const char * cs,const char * ct) char *strpbrk(const char *cs, const char *ct)
{ {
const char *sc1,*sc2; const char *sc1, *sc2;
for( sc1 = cs; *sc1 != '\0'; ++sc1) { for (sc1 = cs; *sc1 != '\0'; ++sc1) {
for( sc2 = ct; *sc2 != '\0'; ++sc2) { for (sc2 = ct; *sc2 != '\0'; ++sc2) {
if (*sc1 == *sc2) if (*sc1 == *sc2)
return (char *) sc1; return (char *)sc1;
} }
} }
return NULL; return NULL;
...@@ -422,9 +419,10 @@ EXPORT_SYMBOL(strpbrk); ...@@ -422,9 +419,10 @@ EXPORT_SYMBOL(strpbrk);
* of that name. In fact, it was stolen from glibc2 and de-fancy-fied. * of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
* Same semantics, slimmer shape. ;) * Same semantics, slimmer shape. ;)
*/ */
char * strsep(char **s, const char *ct) char *strsep(char **s, const char *ct)
{ {
char *sbegin = *s, *end; char *sbegin = *s;
char *end;
if (sbegin == NULL) if (sbegin == NULL)
return NULL; return NULL;
...@@ -433,10 +431,8 @@ char * strsep(char **s, const char *ct) ...@@ -433,10 +431,8 @@ char * strsep(char **s, const char *ct)
if (end) if (end)
*end++ = '\0'; *end++ = '\0';
*s = end; *s = end;
return sbegin; return sbegin;
} }
EXPORT_SYMBOL(strsep); EXPORT_SYMBOL(strsep);
#endif #endif
...@@ -449,13 +445,12 @@ EXPORT_SYMBOL(strsep); ...@@ -449,13 +445,12 @@ EXPORT_SYMBOL(strsep);
* *
* Do not use memset() to access IO space, use memset_io() instead. * Do not use memset() to access IO space, use memset_io() instead.
*/ */
void * memset(void * s,int c,size_t count) void *memset(void *s, int c, size_t count)
{ {
char *xs = (char *) s; char *xs = (char *)s;
while (count--) while (count--)
*xs++ = c; *xs++ = c;
return s; return s;
} }
EXPORT_SYMBOL(memset); EXPORT_SYMBOL(memset);
...@@ -471,13 +466,13 @@ EXPORT_SYMBOL(memset); ...@@ -471,13 +466,13 @@ EXPORT_SYMBOL(memset);
* You should not use this function to access IO space, use memcpy_toio() * You should not use this function to access IO space, use memcpy_toio()
* or memcpy_fromio() instead. * or memcpy_fromio() instead.
*/ */
void * memcpy(void * dest,const void *src,size_t count) void *memcpy(void *dest, const void *src, size_t count)
{ {
char *tmp = (char *) dest, *s = (char *) src; char *tmp = (char *)dest;
char *s = (char *)src;
while (count--) while (count--)
*tmp++ = *s++; *tmp++ = *s++;
return dest; return dest;
} }
EXPORT_SYMBOL(memcpy); EXPORT_SYMBOL(memcpy);
...@@ -492,23 +487,21 @@ EXPORT_SYMBOL(memcpy); ...@@ -492,23 +487,21 @@ EXPORT_SYMBOL(memcpy);
* *
* Unlike memcpy(), memmove() copes with overlapping areas. * Unlike memcpy(), memmove() copes with overlapping areas.
*/ */
void * memmove(void * dest,const void *src,size_t count) void *memmove(void *dest, const void *src, size_t count)
{ {
char *tmp, *s; char *tmp, *s;
if (dest <= src) { if (dest <= src) {
tmp = (char *) dest; tmp = (char *)dest;
s = (char *) src; s = (char *)src;
while (count--) while (count--)
*tmp++ = *s++; *tmp++ = *s++;
} } else {
else { tmp = (char *)dest + count;
tmp = (char *) dest + count; s = (char *)src + count;
s = (char *) src + count;
while (count--) while (count--)
*--tmp = *--s; *--tmp = *--s;
} }
return dest; return dest;
} }
EXPORT_SYMBOL(memmove); EXPORT_SYMBOL(memmove);
...@@ -522,12 +515,12 @@ EXPORT_SYMBOL(memmove); ...@@ -522,12 +515,12 @@ EXPORT_SYMBOL(memmove);
* @count: The size of the area. * @count: The size of the area.
*/ */
#undef memcmp #undef memcmp
int memcmp(const void * cs,const void * ct,size_t count) int memcmp(const void *cs, const void *ct, size_t count)
{ {
const unsigned char *su1, *su2; const unsigned char *su1, *su2;
int res = 0; int res = 0;
for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
if ((res = *su1 - *su2) != 0) if ((res = *su1 - *su2) != 0)
break; break;
return res; return res;
...@@ -545,17 +538,17 @@ EXPORT_SYMBOL(memcmp); ...@@ -545,17 +538,17 @@ EXPORT_SYMBOL(memcmp);
* returns the address of the first occurrence of @c, or 1 byte past * returns the address of the first occurrence of @c, or 1 byte past
* the area if @c is not found * the area if @c is not found
*/ */
void * memscan(void * addr, int c, size_t size) void *memscan(void *addr, int c, size_t size)
{ {
unsigned char * p = (unsigned char *) addr; unsigned char *p = (unsigned char *)addr;
while (size) { while (size) {
if (*p == c) if (*p == c)
return (void *) p; return (void *)p;
p++; p++;
size--; size--;
} }
return (void *) p; return (void *)p;
} }
EXPORT_SYMBOL(memscan); EXPORT_SYMBOL(memscan);
#endif #endif
...@@ -566,18 +559,18 @@ EXPORT_SYMBOL(memscan); ...@@ -566,18 +559,18 @@ EXPORT_SYMBOL(memscan);
* @s1: The string to be searched * @s1: The string to be searched
* @s2: The string to search for * @s2: The string to search for
*/ */
char * strstr(const char * s1,const char * s2) char *strstr(const char *s1, const char *s2)
{ {
int l1, l2; int l1, l2;
l2 = strlen(s2); l2 = strlen(s2);
if (!l2) if (!l2)
return (char *) s1; return (char *)s1;
l1 = strlen(s1); l1 = strlen(s1);
while (l1 >= l2) { while (l1 >= l2) {
l1--; l1--;
if (!memcmp(s1,s2,l2)) if (!memcmp(s1, s2, l2))
return (char *) s1; return (char *)s1;
s1++; s1++;
} }
return NULL; return NULL;
...@@ -600,7 +593,7 @@ void *memchr(const void *s, int c, size_t n) ...@@ -600,7 +593,7 @@ void *memchr(const void *s, int c, size_t n)
const unsigned char *p = s; const unsigned char *p = s;
while (n-- != 0) { while (n-- != 0) {
if ((unsigned char)c == *p++) { if ((unsigned char)c == *p++) {
return (void *)(p-1); return (void *)(p - 1);
} }
} }
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment