Got rid of type-casting into isFOO() and toFOO() functions by
authorWayne Davison <wayned@samba.org>
Thu, 9 Nov 2006 02:39:29 +0000 (02:39 +0000)
committerWayne Davison <wayned@samba.org>
Thu, 9 Nov 2006 02:39:29 +0000 (02:39 +0000)
using static inline functions that take a signed char pointer.

clientserver.c
loadparm.c
log.c
options.c
params.c
rsync.h
socket.c
token.c
util.c

index 1cb6a09..eba203b 100644 (file)
@@ -340,7 +340,7 @@ static int rsync_module(int f_in, int f_out, int i, char *addr, char *host)
        if (am_root) {
                p = lp_uid(i);
                if (!name_to_uid(p, &uid)) {
-                       if (!isdigit(*(unsigned char *)p)) {
+                       if (!isDigit(p)) {
                                rprintf(FLOG, "Invalid uid %s\n", p);
                                io_printf(f_out, "@ERROR: invalid uid %s\n", p);
                                return -1;
@@ -350,7 +350,7 @@ static int rsync_module(int f_in, int f_out, int i, char *addr, char *host)
 
                p = lp_gid(i);
                if (!name_to_gid(p, &gid)) {
-                       if (!isdigit(*(unsigned char *)p)) {
+                       if (!isDigit(p)) {
                                rprintf(FLOG, "Invalid gid %s\n", p);
                                io_printf(f_out, "@ERROR: invalid gid %s\n", p);
                                return -1;
index cdfff5f..4c13267 100644 (file)
@@ -524,12 +524,11 @@ static int strwicmp(char *psz1, char *psz2)
    /* sync the strings on first non-whitespace */
    while (1)
    {
-      while (isspace(* (unsigned char *) psz1))
+      while (isSpace(psz1))
          psz1++;
-      while (isspace(* (unsigned char *) psz2))
+      while (isSpace(psz2))
          psz2++;
-      if (toupper(* (unsigned char *) psz1) != toupper(* (unsigned char *) psz2)
-         || *psz1 == '\0' || *psz2 == '\0')
+      if (toUpper(psz1) != toUpper(psz2) || *psz1 == '\0' || *psz2 == '\0')
          break;
       psz1++;
       psz2++;
diff --git a/log.c b/log.c
index 9824de7..f7ccc00 100644 (file)
--- a/log.c
+++ b/log.c
@@ -214,11 +214,11 @@ static void filtered_fwrite(FILE *f, const char *buf, int len, int use_isprint)
        for (s = buf; s < end; s++) {
                if ((s < end - 4
                  && *s == '\\' && s[1] == '#'
-                 && isdigit(*(uchar*)(s+2))
-                 && isdigit(*(uchar*)(s+3))
-                 && isdigit(*(uchar*)(s+4)))
+                 && isDigit(s + 2)
+                 && isDigit(s + 3)
+                 && isDigit(s + 4))
                 || (*s != '\t'
-                 && ((use_isprint && !isprint(*(uchar*)s))
+                 && ((use_isprint && !isPrint(s))
                   || *(uchar*)s < ' '))) {
                        if (s != buf && fwrite(buf, s - buf, 1, f) != 1)
                                exit_cleanup(RERR_MESSAGEIO);
@@ -445,7 +445,7 @@ static void log_formatted(enum logcode code, char *format, char *op,
                n = fmt + 1;
                if (*p == '-')
                        *n++ = *p++;
-               while (isdigit(*(uchar*)p) && n - fmt < (int)(sizeof fmt) - 8)
+               while (isDigit(p) && n - fmt < (int)(sizeof fmt) - 8)
                        *n++ = *p++;
                if (!*p)
                        break;
@@ -677,7 +677,7 @@ int log_format_has(const char *format, char esc)
        for (p = format; (p = strchr(p, '%')) != NULL; ) {
                if (*++p == '-')
                        p++;
-               while (isdigit(*(uchar*)p))
+               while (isDigit(p))
                        p++;
                if (!*p)
                        break;
index 1976071..5fd2993 100644 (file)
--- a/options.c
+++ b/options.c
@@ -715,9 +715,9 @@ static OFF_T parse_size_arg(char **size_arg, char def_suf)
        const char *arg;
        OFF_T size = 1;
 
-       for (arg = *size_arg; isdigit(*(uchar*)arg); arg++) {}
+       for (arg = *size_arg; isDigit(arg); arg++) {}
        if (*arg == '.')
-               for (arg++; isdigit(*(uchar*)arg); arg++) {}
+               for (arg++; isDigit(arg); arg++) {}
        switch (*arg && *arg != '+' && *arg != '-' ? *arg++ : def_suf) {
        case 'b': case 'B':
                reps = 0;
index 0421687..e543cd7 100644 (file)
--- a/params.c
+++ b/params.c
@@ -165,7 +165,7 @@ static int Continuation( char *line, int pos )
    */
   {
   pos--;
-  while( (pos >= 0) && isspace(((unsigned char *)line)[pos]) )
+  while( pos >= 0 && isSpace(line + pos) )
      pos--;
 
   return( ((pos >= 0) && ('\\' == line[pos])) ? pos : -1 );
@@ -387,7 +387,7 @@ static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(char *, char *), int c )
           c = 0;
         else
           {
-          for( end = i; (end >= 0) && isspace(((unsigned char *) bufr)[end]); end-- )
+          for( end = i; end >= 0 && isSpace(bufr + end); end-- )
             ;
           c = getc( InFile );
           }
diff --git a/rsync.h b/rsync.h
index a70c241..7e9fccf 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -885,3 +885,45 @@ int inet_pton(int af, const char *src, void *dst);
 #ifdef MAINTAINER_MODE
 const char *get_panic_action(void);
 #endif
+
+static inline int
+isDigit(const char *ptr)
+{
+       return isdigit(*(unsigned char *)ptr);
+}
+
+static inline int
+isPrint(const char *ptr)
+{
+       return isprint(*(unsigned char *)ptr);
+}
+
+static inline int
+isSpace(const char *ptr)
+{
+       return isspace(*(unsigned char *)ptr);
+}
+
+static inline int
+isLower(const char *ptr)
+{
+       return islower(*(unsigned char *)ptr);
+}
+
+static inline int
+isUpper(const char *ptr)
+{
+       return isupper(*(unsigned char *)ptr);
+}
+
+static inline int
+toLower(const char *ptr)
+{
+       return tolower(*(unsigned char *)ptr);
+}
+
+static inline int
+toUpper(const char *ptr)
+{
+       return toupper(*(unsigned char *)ptr);
+}
index dd7428e..fd8b1b2 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -95,7 +95,7 @@ static int establish_proxy_connection(int fd, char *host, int port,
                        buffer);
                return -1;
        }
-       for (cp = &buffer[5]; isdigit(*(uchar*)cp) || *cp == '.'; cp++) {}
+       for (cp = &buffer[5]; isDigit(cp) || *cp == '.'; cp++) {}
        while (*cp == ' ')
                cp++;
        if (*cp != '2') {
diff --git a/token.c b/token.c
index d3cee04..1ccacbe 100644 (file)
--- a/token.c
+++ b/token.c
@@ -49,8 +49,8 @@ void set_compression(char *fname)
                                continue;
                        }
                        do {
-                               if (isupper(*(unsigned char *)f))
-                                       *t++ = tolower(*(unsigned char *)f);
+                               if (isUpper(f))
+                                       *t++ = toLower(f);
                                else
                                        *t++ = *f;
                        } while (*++f != ' ' && *f);
diff --git a/util.c b/util.c
index 632a242..540fdf5 100644 (file)
--- a/util.c
+++ b/util.c
@@ -612,8 +612,8 @@ void glob_expand(char *base1, char ***argv_ptr, int *argc_ptr, int *maxargs_ptr)
 void strlower(char *s)
 {
        while (*s) {
-               if (isupper(*(unsigned char *)s))
-                       *s = tolower(*(unsigned char *)s);
+               if (isUpper(s))
+                       *s = toLower(s);
                s++;
        }
 }
@@ -1139,7 +1139,7 @@ char *human_dnum(double dnum, int decimal_digits)
 {
        char *buf = human_num(dnum);
        int len = strlen(buf);
-       if (isdigit(*(uchar*)(buf+len-1))) {
+       if (isDigit(buf + len - 1)) {
                /* There's extra room in buf prior to the start of the num. */
                buf -= decimal_digits + 1;
                snprintf(buf, len + decimal_digits + 2, "%.*f", decimal_digits, dnum);
@@ -1307,7 +1307,7 @@ const char *find_filename_suffix(const char *fn, int fn_len, int *len_ptr)
                        if (strcmp(s+1, "orig") == 0)
                                continue;
                } else if (s_len > 2 && had_tilde
-                   && s[1] == '~' && isdigit(*(uchar*)(s+2)))
+                   && s[1] == '~' && isDigit(s + 2))
                        continue;
                *len_ptr = s_len;
                suf = s;
@@ -1315,7 +1315,7 @@ const char *find_filename_suffix(const char *fn, int fn_len, int *len_ptr)
                        break;
                /* Determine if the suffix is all digits. */
                for (s++, s_len--; s_len > 0; s++, s_len--) {
-                       if (!isdigit(*(uchar*)s))
+                       if (!isDigit(s))
                                return suf;
                }
                /* An all-digit suffix may not be that signficant. */