Skip to contentSkip to conversation

string lib redundancy and whitespace clarity fixes

PATCH In review Jonathan Ho 2 participants 2 messages Feb 10, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 string lib redundancy and whitespace clarity fixes

Fixed some weird whitespace, solved redundancies (applies to v2.6.10).

string.c Wed Feb 09 16:21:28 2005 renamed from string.c Fri Dec 24 13:35:25 2004 +2 -2
@@ -38,7 +38,7 @@ int strnicmp(const char *s1, const char
    /* Yes, Virginia, it had better be unsigned */
    unsigned char c1, c2;
 
-    c1 = 0;    c2 = 0;
+    c1 = c2 = 0;
    if (len) {
        do {
            c1 = *s1; c2 = *s2;
@@ -253,12 +253,12 @@ EXPORT_SYMBOL(strncmp);
 * @s: The string to be searched
 * @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')
            return NULL;

- return (char *) s;
+ return (char *)s;
}
EXPORT_SYMBOL(strchr);
#endif
@@ -390,14 +390,14 @@ EXPORT_SYMBOL(strcspn);
* @cs: The string to be searched
* @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( sc2 = ct; *sc2 != '\0'; ++sc2) {
+ for(sc1 = cs; *sc1 != '\0'; sc1++) {

+        for(sc2 = ct; *sc2 != '\0'; sc2++) {
            if (*sc1 == *sc2)
-                return (char *) sc1;
+                return (char *)sc1;
        }
    }
    return NULL;

@@ -417,7 +417,7 @@ EXPORT_SYMBOL(strpbrk);
* of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
* Same semantics, slimmer shape. ;)
*/
-char * strsep(char **s, const char *ct)
+char *strsep(char **s, const char *ct)

{
    char *sbegin = *s, *end;

@@ -444,9 +444,9 @@ EXPORT_SYMBOL(strsep);
*
* 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--)
        *xs++ = c;

@@ -469,7 +469,7 @@ EXPORT_SYMBOL(memset);
* You should not use this function to access IO space, use memcpy_toio()
* or memcpy_fromio() instead.
*/
-void bcopy(const void * srcp, void * destp, size_t count) +void bcopy(const void *srcp, void *destp, size_t count)

{
    const char *src = srcp;
    char *dest = destp;

@@ -490,7 +490,7 @@ EXPORT_SYMBOL(bcopy);
* You should not use this function to access IO space, use memcpy_toio()
* 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;

@@ -563,17 +563,17 @@ EXPORT_SYMBOL(memcmp);
* returns the address of the first occurrence of @c, or 1 byte past
* 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) {
        if (*p == c)
-            return (void *) p;
+            return (void *)p;
        p++;
        size--;
    }

- return (void *) p;
+ return (void *)p;
}
EXPORT_SYMBOL(memscan);
#endif
@@ -584,18 +584,18 @@ EXPORT_SYMBOL(memscan);
* @s1: The string to be searched
* @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;

    l2 = strlen(s2);
    if (!l2)
-        return (char *) s1;
+        return (char *)s1;
    l1 = strlen(s1);
    while (l1 >= l2) {
        l1--;
-        if (!memcmp(s1,s2,l2))
-            return (char *) s1;
+        if (!memcmp(s1, s2, l2))
+            return (char *)s1;
        s1++;
    }
    return NULL;
@@ -618,7 +618,7 @@ void *memchr(const void *s, int c, size_
    const unsigned char *p = s;
    while (n-- != 0) {
            if ((unsigned char)c == *p++) {
-            return (void *)(p-1);
+            return (void *)(p - 1);
        }
    }
    return NULL;
#1 lore raw

string.c Wed Feb 09

Quoted 6 lines · * Jonathan Ho ([email protected]) wrote:

Fixed some weird whitespace, solved redundancies (applies to v2.6.10).

string.c Wed Feb 09 renamed from string.c Fri Dec 24 13:35:25 2004 +0 -0

This won't apply nicely with -p1. Nor will it apply against current -bk (which no longer has bcopy in it, for example).

Quoted 13 lines

16:21:28 2005

string.c Wed Feb 09 renamed from string.c Fri Dec 24 13:35:25 2004 +1 -1
@@ -38,7 +38,7 @@ int strnicmp(const char *s1, const char
     /* Yes, Virginia, it had better be unsigned */
     unsigned char c1, c2;
 
-    c1 = 0;    c2 = 0;
+    c1 = c2 = 0;
     if (len) {
         do {
             c1 = *s1; c2 = *s2;
@@ -253,12 +253,12 @@ EXPORT_SYMBOL(strncmp);
  * @s: The string to be searched
  * @c: The character to search for

string.c Wed Feb 09 EXPORT_SYMBOL(strncmp); · line 261

Quoted 10 lines
string.c Wed Feb 09 renamed from string.c Fri Dec 24 13:35:25 2004 +3 -3
  */
-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')
             return NULL;
-    return (char *) s;
+    return (char *)s;

For this kind of CodingStyle cleanup, I think it's probably not worth it. Unless you have other changes and fixes planned in the area.

Quoted 7 lines
string.c Wed Feb 09 renamed from string.c Fri Dec 24 13:35:25 2004 +0 -0
 }
 EXPORT_SYMBOL(strchr);
 #endif
@@ -390,14 +390,14 @@ EXPORT_SYMBOL(strcspn);
  * @cs: The string to be searched
  * @ct: The characters to search for
  */

string.c Wed Feb 09 EXPORT_SYMBOL(strcspn); · line 398

Quoted 10 lines
string.c Wed Feb 09 renamed from string.c Fri Dec 24 13:35:25 2004 +4 -4
-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( sc2 = ct; *sc2 != '\0'; ++sc2) {
+    for(sc1 = cs; *sc1 != '\0'; sc1++) {
+        for(sc2 = ct; *sc2 != '\0'; sc2++) {

Neither of these is CodingStyle compliant ;-) Take a look at what Lindent does (not perfect, but good rule of thumb).

thanks,
-chris

Signature · 1 line
Linux Security Modules     http://lsm.immunix.org     http://lsm.bkbits.net