Added "const" to appropriate char pointers.
authorWayne Davison <wayned@samba.org>
Sun, 19 Nov 2006 00:23:21 +0000 (00:23 +0000)
committerWayne Davison <wayned@samba.org>
Sun, 19 Nov 2006 00:23:21 +0000 (00:23 +0000)
14 files changed:
authenticate.c
checksum.c
clientserver.c
flist.c
generator.c
hlink.c
io.c
lib/pool_alloc.c
lib/pool_alloc.h
log.c
pipe.c
rsync.h
syscall.c
util.c

index 5370cb7..c3dabd0 100644 (file)
@@ -27,11 +27,11 @@ extern char *password_file;
 encode a buffer using base64 - simple and slow algorithm. null terminates
 the result.
   ***************************************************************************/
 encode a buffer using base64 - simple and slow algorithm. null terminates
 the result.
   ***************************************************************************/
-void base64_encode(char *buf, int len, char *out, int pad)
+void base64_encode(const char *buf, int len, char *out, int pad)
 {
        char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
        int bit_offset, byte_offset, idx, i;
 {
        char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
        int bit_offset, byte_offset, idx, i;
-       unsigned char *d = (unsigned char *)buf;
+       const uchar *d = (const uchar *)buf;
        int bytes = (len*8 + 5)/6;
 
        for (i = 0; i < bytes; i++) {
        int bytes = (len*8 + 5)/6;
 
        for (i = 0; i < bytes; i++) {
@@ -55,7 +55,7 @@ void base64_encode(char *buf, int len, char *out, int pad)
 }
 
 /* Generate a challenge buffer and return it base64-encoded. */
 }
 
 /* Generate a challenge buffer and return it base64-encoded. */
-static void gen_challenge(char *addr, char *challenge)
+static void gen_challenge(const char *addr, char *challenge)
 {
        char input[32];
        char md4_out[MD4_SUM_LENGTH];
 {
        char input[32];
        char md4_out[MD4_SUM_LENGTH];
@@ -63,7 +63,7 @@ static void gen_challenge(char *addr, char *challenge)
 
        memset(input, 0, sizeof input);
 
 
        memset(input, 0, sizeof input);
 
-       strlcpy((char *)input, addr, 17);
+       strlcpy(input, addr, 17);
        sys_gettimeofday(&tv);
        SIVAL(input, 16, tv.tv_sec);
        SIVAL(input, 20, tv.tv_usec);
        sys_gettimeofday(&tv);
        SIVAL(input, 16, tv.tv_sec);
        SIVAL(input, 20, tv.tv_usec);
@@ -79,12 +79,13 @@ static void gen_challenge(char *addr, char *challenge)
 
 /* Return the secret for a user from the secret file, null terminated.
  * Maximum length is len (not counting the null). */
 
 /* Return the secret for a user from the secret file, null terminated.
  * Maximum length is len (not counting the null). */
-static int get_secret(int module, char *user, char *secret, int len)
+static int get_secret(int module, const char *user, char *secret, int len)
 {
 {
-       char *fname = lp_secrets_file(module);
+       const char *fname = lp_secrets_file(module);
        STRUCT_STAT st;
        int fd, ok = 1;
        STRUCT_STAT st;
        int fd, ok = 1;
-       char ch, *p;
+       const char *p;
+       char ch, *s;
 
        if (!fname || !*fname)
                return 0;
 
        if (!fname || !*fname)
                return 0;
@@ -136,27 +137,27 @@ static int get_secret(int module, char *user, char *secret, int len)
        }
 
        /* Slurp the secret into the "secret" buffer. */
        }
 
        /* Slurp the secret into the "secret" buffer. */
-       p = secret;
+       s = secret;
        while (len > 0) {
        while (len > 0) {
-               if (read(fd, p, 1) != 1 || *p == '\n')
+               if (read(fd, s, 1) != 1 || *s == '\n')
                        break;
                        break;
-               if (*p == '\r')
+               if (*s == '\r')
                        continue;
                        continue;
-               p++;
+               s++;
                len--;
        }
                len--;
        }
-       *p = '\0';
+       *s = '\0';
        close(fd);
 
        return 1;
 }
 
        close(fd);
 
        return 1;
 }
 
-static char *getpassf(char *filename)
+static const char *getpassf(const char *filename)
 {
        STRUCT_STAT st;
        char buffer[512], *p;
        int fd, n, ok = 1;
 {
        STRUCT_STAT st;
        char buffer[512], *p;
        int fd, n, ok = 1;
-       char *envpw = getenv("RSYNC_PASSWORD");
+       const char *envpw = getenv("RSYNC_PASSWORD");
 
        if (!filename)
                return NULL;
 
        if (!filename)
                return NULL;
@@ -203,7 +204,7 @@ static char *getpassf(char *filename)
 
 /* Generate an MD4 hash created from the combination of the password
  * and the challenge string and return it base64-encoded. */
 
 /* Generate an MD4 hash created from the combination of the password
  * and the challenge string and return it base64-encoded. */
-static void generate_hash(char *in, char *challenge, char *out)
+static void generate_hash(const char *in, const char *challenge, char *out)
 {
        char buf[MD4_SUM_LENGTH];
 
 {
        char buf[MD4_SUM_LENGTH];
 
@@ -221,8 +222,8 @@ static void generate_hash(char *in, char *challenge, char *out)
  * Return NULL if authentication failed.  Return "" if anonymous access.
  * Otherwise return username.
  */
  * Return NULL if authentication failed.  Return "" if anonymous access.
  * Otherwise return username.
  */
-char *auth_server(int f_in, int f_out, int module, char *host, char *addr,
-                 char *leader)
+char *auth_server(int f_in, int f_out, int module, const char *host,
+                 const char *addr, const char *leader)
 {
        char *users = lp_auth_users(module);
        char challenge[MD4_SUM_LENGTH*2];
 {
        char *users = lp_auth_users(module);
        char challenge[MD4_SUM_LENGTH*2];
@@ -286,10 +287,9 @@ char *auth_server(int f_in, int f_out, int module, char *host, char *addr,
        return strdup(line);
 }
 
        return strdup(line);
 }
 
-
-void auth_client(int fd, char *user, char *challenge)
+void auth_client(int fd, const char *user, const char *challenge)
 {
 {
-       char *pass;
+       const char *pass;
        char pass2[MD4_SUM_LENGTH*2];
 
        if (!user || !*user)
        char pass2[MD4_SUM_LENGTH*2];
 
        if (!user || !*user)
index e3ced51..c8b6cdf 100644 (file)
@@ -151,7 +151,7 @@ void sum_init(int seed)
  * @todo Perhaps get rid of md and just pass in the address each time.
  * Very slightly clearer and slower.
  **/
  * @todo Perhaps get rid of md and just pass in the address each time.
  * Very slightly clearer and slower.
  **/
-void sum_update(char *p, int32 len)
+void sum_update(const char *p, int32 len)
 {
        if (len + sumresidue < CSUM_CHUNK) {
                memcpy(sumrbuf + sumresidue, p, len);
 {
        if (len + sumresidue < CSUM_CHUNK) {
                memcpy(sumrbuf + sumresidue, p, len);
index eba203b..d27ced3 100644 (file)
@@ -110,7 +110,7 @@ int start_socket_client(char *host, char *path, int argc, char *argv[])
        return ret ? ret : client_run(fd, fd, -1, argc, argv);
 }
 
        return ret ? ret : client_run(fd, fd, -1, argc, argv);
 }
 
-int start_inband_exchange(char *user, char *path, int f_in, int f_out,
+int start_inband_exchange(const char *user, char *path, int f_in, int f_out,
                          int argc)
 {
        int i;
                          int argc)
 {
        int i;
diff --git a/flist.c b/flist.c
index 8e543a6..8b24b0a 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -467,7 +467,7 @@ static void send_file_entry(struct file_struct *file, int f)
 #endif
 
        if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) {
 #endif
 
        if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) {
-               char *sum;
+               const char *sum;
                if (S_ISREG(mode))
                        sum = file->u.sum;
                else {
                if (S_ISREG(mode))
                        sum = file->u.sum;
                else {
@@ -1505,8 +1505,7 @@ struct file_list *flist_new(int with_hlink, char *msg)
 
        memset(flist, 0, sizeof (struct file_list));
 
 
        memset(flist, 0, sizeof (struct file_list));
 
-       if (!(flist->file_pool = pool_create(FILE_EXTENT, 0,
-           out_of_memory, POOL_INTERN)))
+       if (!(flist->file_pool = pool_create(FILE_EXTENT, 0, out_of_memory, POOL_INTERN)))
                out_of_memory(msg);
 
 #ifdef SUPPORT_HARD_LINKS
                out_of_memory(msg);
 
 #ifdef SUPPORT_HARD_LINKS
index edc2e74..453cff5 100644 (file)
@@ -395,7 +395,7 @@ int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st)
 }
 
 void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
 }
 
 void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st,
-            int32 iflags, uchar fnamecmp_type, char *xname)
+            int32 iflags, uchar fnamecmp_type, const char *xname)
 {
        if (statret >= 0) { /* A from-dest-dir statret can == 1! */
                int keep_time = !preserve_times ? 0
 {
        if (statret >= 0) { /* A from-dest-dir statret can == 1! */
                int keep_time = !preserve_times ? 0
@@ -919,7 +919,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                           enum logcode code, int f_out)
 {
        static int missing_below = -1, excluded_below = -1;
                           enum logcode code, int f_out)
 {
        static int missing_below = -1, excluded_below = -1;
-       static char *parent_dirname = "";
+       static const char *parent_dirname = "";
        static struct file_list *fuzzy_dirlist = NULL;
        static int need_fuzzy_dirlist = 0;
        struct file_struct *fuzzy_file = NULL;
        static struct file_list *fuzzy_dirlist = NULL;
        static int need_fuzzy_dirlist = 0;
        struct file_struct *fuzzy_file = NULL;
@@ -984,7 +984,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                statret = -1;
                stat_errno = ENOENT;
        } else {
                statret = -1;
                stat_errno = ENOENT;
        } else {
-               char *dn = file->dirname ? file->dirname : ".";
+               const char *dn = file->dirname ? file->dirname : ".";
                if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
                        if (relative_paths && !implied_dirs
                         && do_stat(dn, &st) < 0
                if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
                        if (relative_paths && !implied_dirs
                         && do_stat(dn, &st) < 0
@@ -1003,7 +1003,8 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
                parent_dirname = dn;
 
                if (need_fuzzy_dirlist && S_ISREG(file->mode)) {
                parent_dirname = dn;
 
                if (need_fuzzy_dirlist && S_ISREG(file->mode)) {
-                       fuzzy_dirlist = get_dirlist(dn, -1, 1);
+                       strlcpy(fnamecmpbuf, dn, sizeof fnamecmpbuf);
+                       fuzzy_dirlist = get_dirlist(fnamecmpbuf, -1, 1);
                        need_fuzzy_dirlist = 0;
                }
 
                        need_fuzzy_dirlist = 0;
                }
 
diff --git a/hlink.c b/hlink.c
index 2ef998c..e0a5265 100644 (file)
--- a/hlink.c
+++ b/hlink.c
@@ -67,8 +67,7 @@ static void link_idev_data(void)
        alloc_pool_t hlink_pool;
        alloc_pool_t idev_pool = the_file_list->hlink_pool;
 
        alloc_pool_t hlink_pool;
        alloc_pool_t idev_pool = the_file_list->hlink_pool;
 
-       hlink_pool = pool_create(128 * 1024, sizeof (struct hlink),
-           out_of_memory, POOL_INTERN);
+       hlink_pool = pool_create(128 * 1024, sizeof (struct hlink), out_of_memory, POOL_INTERN);
 
        for (from = to = 0; from < hlink_count; from++) {
                start = from;
 
        for (from = to = 0; from < hlink_count; from++) {
                start = from;
diff --git a/io.c b/io.c
index 55aac4a..0251176 100644 (file)
--- a/io.c
+++ b/io.c
@@ -204,7 +204,7 @@ void set_msg_fd_out(int fd)
 }
 
 /* Add a message to the pending MSG_* list. */
 }
 
 /* Add a message to the pending MSG_* list. */
-static void msg_list_add(struct msg_list *lst, int code, char *buf, int len)
+static void msg_list_add(struct msg_list *lst, int code, const char *buf, int len)
 {
        struct msg_list_item *m;
        int sz = len + 4 + sizeof m[0] - 1;
 {
        struct msg_list_item *m;
        int sz = len + 4 + sizeof m[0] - 1;
@@ -371,7 +371,7 @@ static int msg2genr_flush(int flush_it_all)
        return 1;
 }
 
        return 1;
 }
 
-int send_msg(enum msgcode code, char *buf, int len)
+int send_msg(enum msgcode code, const char *buf, int len)
 {
        if (msg_fd_out < 0) {
                if (!defer_forwarding_messages)
 {
        if (msg_fd_out < 0) {
                if (!defer_forwarding_messages)
@@ -894,12 +894,12 @@ int64 read_longint(int f)
        return num;
 }
 
        return num;
 }
 
-void read_buf(int f,char *buf,size_t len)
+void read_buf(int f, char *buf, size_t len)
 {
        readfd(f,buf,len);
 }
 
 {
        readfd(f,buf,len);
 }
 
-void read_sbuf(int f,char *buf,size_t len)
+void read_sbuf(int f, char *buf, size_t len)
 {
        readfd(f, buf, len);
        buf[len] = '\0';
 {
        readfd(f, buf, len);
        buf[len] = '\0';
@@ -1039,7 +1039,7 @@ static void sleep_for_bwlimit(int bytes_written)
  *
  * This function underlies the multiplexing system.  The body of the
  * application never calls this function directly. */
  *
  * This function underlies the multiplexing system.  The body of the
  * application never calls this function directly. */
-static void writefd_unbuffered(int fd,char *buf,size_t len)
+static void writefd_unbuffered(int fd, const char *buf, size_t len)
 {
        size_t n, total = 0;
        fd_set w_fds, r_fds, e_fds;
 {
        size_t n, total = 0;
        fd_set w_fds, r_fds, e_fds;
@@ -1157,7 +1157,7 @@ static void msg2sndr_flush(void)
  * Write an message to a multiplexed stream. If this fails then rsync
  * exits.
  **/
  * Write an message to a multiplexed stream. If this fails then rsync
  * exits.
  **/
-static void mplex_write(enum msgcode code, char *buf, size_t len)
+static void mplex_write(enum msgcode code, const char *buf, size_t len)
 {
        char buffer[1024];
        size_t n = len;
 {
        char buffer[1024];
        size_t n = len;
@@ -1197,7 +1197,7 @@ void io_flush(int flush_it_all)
        iobuf_out_cnt = 0;
 }
 
        iobuf_out_cnt = 0;
 }
 
-static void writefd(int fd,char *buf,size_t len)
+static void writefd(int fd, const char *buf, size_t len)
 {
        if (fd == msg_fd_out) {
                rprintf(FERROR, "Internal error: wrong write used in receiver.\n");
 {
        if (fd == msg_fd_out) {
                rprintf(FERROR, "Internal error: wrong write used in receiver.\n");
@@ -1271,13 +1271,13 @@ void write_longint(int f, int64 x)
 #endif
 }
 
 #endif
 }
 
-void write_buf(int f,char *buf,size_t len)
+void write_buf(int f, const char *buf, size_t len)
 {
        writefd(f,buf,len);
 }
 
 /** Write a string to the connection */
 {
        writefd(f,buf,len);
 }
 
 /** Write a string to the connection */
-void write_sbuf(int f, char *buf)
+void write_sbuf(int f, const char *buf)
 {
        writefd(f, buf, strlen(buf));
 }
 {
        writefd(f, buf, strlen(buf));
 }
@@ -1287,7 +1287,7 @@ void write_byte(int f, uchar c)
        writefd(f, (char *)&c, 1);
 }
 
        writefd(f, (char *)&c, 1);
 }
 
-void write_vstring(int f, char *str, int len)
+void write_vstring(int f, const char *str, int len)
 {
        uchar lenbuf[3], *lb = lenbuf;
 
 {
        uchar lenbuf[3], *lb = lenbuf;
 
@@ -1370,7 +1370,7 @@ void io_start_multiplex_in(void)
 }
 
 /** Write an message to the multiplexed data stream. */
 }
 
 /** Write an message to the multiplexed data stream. */
-int io_multiplex_write(enum msgcode code, char *buf, size_t len)
+int io_multiplex_write(enum msgcode code, const char *buf, size_t len)
 {
        if (!io_multiplexing_out)
                return 0;
 {
        if (!io_multiplexing_out)
                return 0;
index 1ec381d..b0164e7 100644 (file)
@@ -44,8 +44,7 @@ struct align_test {
 #define PTR_ADD(b,o)   ( (void*) ((char*)(b) + (o)) )
 
 alloc_pool_t
 #define PTR_ADD(b,o)   ( (void*) ((char*)(b) + (o)) )
 
 alloc_pool_t
-pool_create(size_t size, size_t quantum,
-    void (*bomb)(char *), int flags)
+pool_create(size_t size, size_t quantum, void (*bomb)(const char *), int flags)
 {
        struct alloc_pool       *pool;
 
 {
        struct alloc_pool       *pool;
 
@@ -92,7 +91,7 @@ pool_destroy(alloc_pool_t p)
 }
 
 void *
 }
 
 void *
-pool_alloc(alloc_pool_t p, size_t len, char *bomb)
+pool_alloc(alloc_pool_t p, size_t len, const char *bomb)
 {
        struct alloc_pool *pool = (struct alloc_pool *) p;
        if (!pool)
 {
        struct alloc_pool *pool = (struct alloc_pool *) p;
        if (!pool)
index a4ab761..3d09563 100644 (file)
@@ -7,9 +7,9 @@
 
 typedef void *alloc_pool_t;
 
 
 typedef void *alloc_pool_t;
 
-alloc_pool_t pool_create(size_t size, size_t quantum, void (*bomb)(char *), int flags);
+alloc_pool_t pool_create(size_t size, size_t quantum, void (*bomb)(const char *), int flags);
 void pool_destroy(alloc_pool_t pool);
 void pool_destroy(alloc_pool_t pool);
-void *pool_alloc(alloc_pool_t pool, size_t size, char *bomb);
+void *pool_alloc(alloc_pool_t pool, size_t size, const char *bomb);
 void pool_free(alloc_pool_t pool, size_t size, void *addr);
 
 #define pool_talloc(pool, type, count, bomb) \
 void pool_free(alloc_pool_t pool, size_t size, void *addr);
 
 #define pool_talloc(pool, type, count, bomb) \
diff --git a/log.c b/log.c
index 3da7b9f..c69482d 100644 (file)
--- a/log.c
+++ b/log.c
@@ -103,7 +103,7 @@ static char const *rerr_name(int code)
        return NULL;
 }
 
        return NULL;
 }
 
-static void logit(int priority, char *buf)
+static void logit(int priority, const char *buf)
 {
        if (logfile_was_closed)
                logfile_reopen();
 {
        if (logfile_was_closed)
                logfile_reopen();
@@ -233,7 +233,7 @@ static void filtered_fwrite(FILE *f, const char *buf, int len, int use_isprint)
 /* this is the underlying (unformatted) rsync debugging function. Call
  * it with FINFO, FERROR or FLOG.  Note: recursion can happen with
  * certain fatal conditions. */
 /* this is the underlying (unformatted) rsync debugging function. Call
  * it with FINFO, FERROR or FLOG.  Note: recursion can happen with
  * certain fatal conditions. */
-void rwrite(enum logcode code, char *buf, int len)
+void rwrite(enum logcode code, const char *buf, int len)
 {
        int trailing_CR_or_NL;
        FILE *f = NULL;
 {
        int trailing_CR_or_NL;
        FILE *f = NULL;
@@ -302,7 +302,8 @@ void rwrite(enum logcode code, char *buf, int len)
 #if defined HAVE_ICONV_OPEN && defined HAVE_ICONV_H
        if (ic_chck != (iconv_t)-1) {
                char convbuf[1024];
 #if defined HAVE_ICONV_OPEN && defined HAVE_ICONV_H
        if (ic_chck != (iconv_t)-1) {
                char convbuf[1024];
-               char *in_buf = buf, *out_buf = convbuf;
+               const char *in_buf = buf;
+               char *out_buf = convbuf;
                size_t in_cnt = len, out_cnt = sizeof convbuf - 1;
 
                iconv(ic_chck, NULL, 0, NULL, 0);
                size_t in_cnt = len, out_cnt = sizeof convbuf - 1;
 
                iconv(ic_chck, NULL, 0, NULL, 0);
@@ -418,12 +419,13 @@ void rflush(enum logcode code)
 }
 
 /* A generic logging routine for send/recv, with parameter substitiution. */
 }
 
 /* A generic logging routine for send/recv, with parameter substitiution. */
-static void log_formatted(enum logcode code, char *format, char *op,
+static void log_formatted(enum logcode code, const char *format, const char *op,
                          struct file_struct *file, struct stats *initial_stats,
                          struct file_struct *file, struct stats *initial_stats,
-                         int iflags, char *hlink)
+                         int iflags, const char *hlink)
 {
        char buf[MAXPATHLEN+1024], buf2[MAXPATHLEN], fmt[32];
 {
        char buf[MAXPATHLEN+1024], buf2[MAXPATHLEN], fmt[32];
-       char *p, *s, *n;
+       char *p, *s, *c;
+       const char *n;
        size_t len, total;
        int64 b;
 
        size_t len, total;
        int64 b;
 
@@ -442,14 +444,14 @@ static void log_formatted(enum logcode code, char *format, char *op,
 
        for (p = buf; (p = strchr(p, '%')) != NULL; ) {
                s = p++;
 
        for (p = buf; (p = strchr(p, '%')) != NULL; ) {
                s = p++;
-               n = fmt + 1;
+               c = fmt + 1;
                if (*p == '-')
                if (*p == '-')
-                       *n++ = *p++;
-               while (isDigit(p) && n - fmt < (int)(sizeof fmt) - 8)
-                       *n++ = *p++;
+                       *c++ = *p++;
+               while (isDigit(p) && c - fmt < (int)(sizeof fmt) - 8)
+                       *c++ = *p++;
                if (!*p)
                        break;
                if (!*p)
                        break;
-               *n = '\0';
+               *c = '\0';
                n = NULL;
 
                switch (*p) {
                n = NULL;
 
                switch (*p) {
@@ -490,47 +492,50 @@ static void log_formatted(enum logcode code, char *format, char *op,
                        n = buf2;
                        break;
                case 'M':
                        n = buf2;
                        break;
                case 'M':
-                       n = timestring(file->modtime);
-                       {
-                               char *cp = n;
-                               while ((cp = strchr(cp, ' ')) != NULL)
-                                       *cp = '-';
-                       }
+                       n = c = timestring(file->modtime);
+                       while ((c = strchr(p, ' ')) != NULL)
+                               *c = '-';
                        break;
                case 'B':
                        break;
                case 'B':
-                       n = buf2 + MAXPATHLEN - PERMSTRING_SIZE;
-                       permstring(n - 1, file->mode); /* skip the type char */
+                       c = buf2 + MAXPATHLEN - PERMSTRING_SIZE - 1;
+                       permstring(c, file->mode);
+                       n = c + 1; /* skip the type char */
                        break;
                case 'o':
                        n = op;
                        break;
                case 'f':
                        break;
                case 'o':
                        n = op;
                        break;
                case 'f':
-                       n = f_name(file, NULL);
+                       c = f_name(file, NULL);
                        if (am_sender && file->dir.root) {
                                pathjoin(buf2, sizeof buf2,
                        if (am_sender && file->dir.root) {
                                pathjoin(buf2, sizeof buf2,
-                                        file->dir.root, n);
+                                        file->dir.root, c);
                                clean_fname(buf2, 0);
                                clean_fname(buf2, 0);
-                               if (fmt[1])
-                                       strlcpy(n, buf2, MAXPATHLEN);
-                               else
+                               if (fmt[1]) {
+                                       strlcpy(c, buf2, MAXPATHLEN);
+                                       n = c;
+                               } else
                                        n = buf2;
                                        n = buf2;
-                       } else if (*n != '/') {
+                       } else if (*c != '/') {
                                pathjoin(buf2, sizeof buf2,
                                pathjoin(buf2, sizeof buf2,
-                                        curr_dir + module_dirlen, n);
+                                        curr_dir + module_dirlen, c);
                                clean_fname(buf2, 0);
                                clean_fname(buf2, 0);
-                               if (fmt[1])
-                                       strlcpy(n, buf2, MAXPATHLEN);
-                               else
+                               if (fmt[1]) {
+                                       strlcpy(c, buf2, MAXPATHLEN);
+                                       n = c;
+                               } else
                                        n = buf2;
                                        n = buf2;
-                       } else
-                               clean_fname(n, 0);
+                       } else {
+                               clean_fname(c, 0);
+                               n = c;
+                       }
                        if (*n == '/')
                                n++;
                        break;
                case 'n':
                        if (*n == '/')
                                n++;
                        break;
                case 'n':
-                       n = f_name(file, NULL);
+                       c = f_name(file, NULL);
                        if (S_ISDIR(file->mode))
                        if (S_ISDIR(file->mode))
-                               strlcat(n, "/", MAXPATHLEN);
+                               strlcat(c, "/", MAXPATHLEN);
+                       n = c;
                        break;
                case 'L':
                        if (hlink && *hlink) {
                        break;
                case 'L':
                        if (hlink && *hlink) {
@@ -590,39 +595,39 @@ static void log_formatted(enum logcode code, char *format, char *op,
                                n = "*deleting";
                                break;
                        }
                                n = "*deleting";
                                break;
                        }
-                       n = buf2 + MAXPATHLEN - 32;
-                       n[0] = iflags & ITEM_LOCAL_CHANGE
+                       n  = c = buf2 + MAXPATHLEN - 32;
+                       c[0] = iflags & ITEM_LOCAL_CHANGE
                              ? iflags & ITEM_XNAME_FOLLOWS ? 'h' : 'c'
                             : !(iflags & ITEM_TRANSFER) ? '.'
                             : !local_server && *op == 's' ? '<' : '>';
                              ? iflags & ITEM_XNAME_FOLLOWS ? 'h' : 'c'
                             : !(iflags & ITEM_TRANSFER) ? '.'
                             : !local_server && *op == 's' ? '<' : '>';
-                       n[1] = S_ISDIR(file->mode) ? 'd'
+                       c[1] = S_ISDIR(file->mode) ? 'd'
                             : IS_SPECIAL(file->mode) ? 'S'
                             : IS_DEVICE(file->mode) ? 'D'
                             : S_ISLNK(file->mode) ? 'L' : 'f';
                             : IS_SPECIAL(file->mode) ? 'S'
                             : IS_DEVICE(file->mode) ? 'D'
                             : S_ISLNK(file->mode) ? 'L' : 'f';
-                       n[2] = !(iflags & ITEM_REPORT_CHECKSUM) ? '.' : 'c';
-                       n[3] = !(iflags & ITEM_REPORT_SIZE) ? '.' : 's';
-                       n[4] = !(iflags & ITEM_REPORT_TIME) ? '.'
+                       c[2] = !(iflags & ITEM_REPORT_CHECKSUM) ? '.' : 'c';
+                       c[3] = !(iflags & ITEM_REPORT_SIZE) ? '.' : 's';
+                       c[4] = !(iflags & ITEM_REPORT_TIME) ? '.'
                             : !preserve_times || S_ISLNK(file->mode) ? 'T' : 't';
                             : !preserve_times || S_ISLNK(file->mode) ? 'T' : 't';
-                       n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
-                       n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
-                       n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
-                       n[8] = '.';
-                       n[9] = '\0';
+                       c[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
+                       c[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
+                       c[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
+                       c[8] = '.';
+                       c[9] = '\0';
 
                        if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
                                char ch = iflags & ITEM_IS_NEW ? '+' : '?';
                                int i;
 
                        if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
                                char ch = iflags & ITEM_IS_NEW ? '+' : '?';
                                int i;
-                               for (i = 2; n[i]; i++)
-                                       n[i] = ch;
-                       } else if (n[0] == '.' || n[0] == 'h' || n[0] == 'c') {
+                               for (i = 2; c[i]; i++)
+                                       c[i] = ch;
+                       } else if (c[0] == '.' || c[0] == 'h' || c[0] == 'c') {
                                int i;
                                int i;
-                               for (i = 2; n[i]; i++) {
-                                       if (n[i] != '.')
+                               for (i = 2; c[i]; i++) {
+                                       if (c[i] != '.')
                                                break;
                                }
                                                break;
                                }
-                               if (!n[i]) {
-                                       for (i = 2; n[i]; i++)
-                                               n[i] = ' ';
+                               if (!c[i]) {
+                                       for (i = 2; c[i]; i++)
+                                               c[i] = ' ';
                                }
                        }
                        break;
                                }
                        }
                        break;
@@ -690,9 +695,9 @@ int log_format_has(const char *format, char esc)
  * to stdout.  If it is FLOG, it just goes to the log file.  Otherwise we
  * output to both. */
 void log_item(enum logcode code, struct file_struct *file,
  * to stdout.  If it is FLOG, it just goes to the log file.  Otherwise we
  * output to both. */
 void log_item(enum logcode code, struct file_struct *file,
-             struct stats *initial_stats, int iflags, char *hlink)
+             struct stats *initial_stats, int iflags, const char *hlink)
 {
 {
-       char *s_or_r = am_sender ? "send" : "recv";
+       const char *s_or_r = am_sender ? "send" : "recv";
 
        if (code != FLOG && stdout_format && !am_server) {
                log_formatted(FCLIENT, stdout_format, s_or_r,
 
        if (code != FLOG && stdout_format && !am_server) {
                log_formatted(FCLIENT, stdout_format, s_or_r,
@@ -705,7 +710,7 @@ void log_item(enum logcode code, struct file_struct *file,
 }
 
 void maybe_log_item(struct file_struct *file, int iflags, int itemizing,
 }
 
 void maybe_log_item(struct file_struct *file, int iflags, int itemizing,
-                   char *buf)
+                   const char *buf)
 {
        int significant_flags = iflags & SIGNIFICANT_ITEM_FLAGS;
        int see_item = itemizing && (significant_flags || *buf
 {
        int significant_flags = iflags & SIGNIFICANT_ITEM_FLAGS;
        int see_item = itemizing && (significant_flags || *buf
@@ -722,11 +727,11 @@ void maybe_log_item(struct file_struct *file, int iflags, int itemizing,
        }
 }
 
        }
 }
 
-void log_delete(char *fname, int mode)
+void log_delete(const char *fname, int mode)
 {
        static struct file_struct file;
        int len = strlen(fname);
 {
        static struct file_struct file;
        int len = strlen(fname);
-       char *fmt;
+       const char *fmt;
 
        file.mode = mode;
        file.basename = fname;
 
        file.mode = mode;
        file.basename = fname;
diff --git a/pipe.c b/pipe.c
index d47a3e9..0e27020 100644 (file)
--- a/pipe.c
+++ b/pipe.c
@@ -50,9 +50,8 @@ pid_t piped_child(char **command, int *f_in, int *f_out)
        int to_child_pipe[2];
        int from_child_pipe[2];
 
        int to_child_pipe[2];
        int from_child_pipe[2];
 
-       if (verbose >= 2) {
+       if (verbose >= 2)
                print_child_argv(command);
                print_child_argv(command);
-       }
 
        if (fd_pair(to_child_pipe) < 0 || fd_pair(from_child_pipe) < 0) {
                rsyserr(FERROR, errno, "pipe");
 
        if (fd_pair(to_child_pipe) < 0 || fd_pair(from_child_pipe) < 0) {
                rsyserr(FERROR, errno, "pipe");
diff --git a/rsync.h b/rsync.h
index 269631d..25cb560 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -513,12 +513,12 @@ struct hlink {
 struct file_struct {
        union {
                dev_t rdev;     /* The device number, if this is a device */
 struct file_struct {
        union {
                dev_t rdev;     /* The device number, if this is a device */
-               char *sum;      /* Only a normal file can have a checksum */
-               char *link;     /* Points to symlink string, if a symlink */
+               const char *sum;/* Only a normal file can have a checksum */
+               const char *link;/* Points to symlink string, if a symlink */
        } u;
        OFF_T length;
        } u;
        OFF_T length;
-       char *basename;         /* The current item's name (AKA filename) */
-       char *dirname;          /* The directory info inside the transfer */
+       const char *basename;   /* The current item's name (AKA filename) */
+       const char *dirname;    /* The directory info inside the transfer */
        union {
                const char *root;/* Sender-side dir info outside transfer */
                int depth;      /* Receiver-side directory depth info */
        union {
                const char *root;/* Sender-side dir info outside transfer */
                int depth;      /* Receiver-side directory depth info */
index 868e00d..aaf5962 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -75,7 +75,7 @@ int do_lchown(const char *path, uid_t owner, gid_t group)
        return lchown(path, owner, group);
 }
 
        return lchown(path, owner, group);
 }
 
-int do_mknod(char *pathname, mode_t mode, dev_t dev)
+int do_mknod(const char *pathname, mode_t mode, dev_t dev)
 {
        if (dry_run) return 0;
        RETURN_ERROR_IF_RO_OR_LO;
 {
        if (dry_run) return 0;
        RETURN_ERROR_IF_RO_OR_LO;
diff --git a/util.c b/util.c
index 32dd591..40f00d2 100644 (file)
--- a/util.c
+++ b/util.c
@@ -109,19 +109,19 @@ void print_child_argv(char **cmd)
        rprintf(FCLIENT, "\n");
 }
 
        rprintf(FCLIENT, "\n");
 }
 
-NORETURN void out_of_memory(char *str)
+NORETURN void out_of_memory(const char *str)
 {
        rprintf(FERROR, "ERROR: out of memory in %s [%s]\n", str, who_am_i());
        exit_cleanup(RERR_MALLOC);
 }
 
 {
        rprintf(FERROR, "ERROR: out of memory in %s [%s]\n", str, who_am_i());
        exit_cleanup(RERR_MALLOC);
 }
 
-NORETURN void overflow_exit(char *str)
+NORETURN void overflow_exit(const char *str)
 {
        rprintf(FERROR, "ERROR: buffer overflow in %s [%s]\n", str, who_am_i());
        exit_cleanup(RERR_MALLOC);
 }
 
 {
        rprintf(FERROR, "ERROR: buffer overflow in %s [%s]\n", str, who_am_i());
        exit_cleanup(RERR_MALLOC);
 }
 
-int set_modtime(char *fname, time_t modtime, mode_t mode)
+int set_modtime(const char *fname, time_t modtime, mode_t mode)
 {
 #if !defined HAVE_LUTIMES || !defined HAVE_UTIMES
        if (S_ISLNK(mode))
 {
 #if !defined HAVE_LUTIMES || !defined HAVE_UTIMES
        if (S_ISLNK(mode))
@@ -216,7 +216,7 @@ int create_directory_path(char *fname)
  *
  * Derived from GNU C's cccp.c.
  */
  *
  * Derived from GNU C's cccp.c.
  */
-int full_write(int desc, char *ptr, size_t len)
+int full_write(int desc, const char *ptr, size_t len)
 {
        int total_written;
 
 {
        int total_written;
 
@@ -384,7 +384,7 @@ int robust_unlink(const char *fname)
  * across filesystems, -2 if copy_file() failed, and -1 on other errors.
  * If partialptr is not NULL and we need to do a copy, copy the file into
  * the active partial-dir instead of over the destination file. */
  * across filesystems, -2 if copy_file() failed, and -1 on other errors.
  * If partialptr is not NULL and we need to do a copy, copy the file into
  * the active partial-dir instead of over the destination file. */
-int robust_rename(char *from, char *to, char *partialptr,
+int robust_rename(const char *from, const char *to, const char *partialptr,
                  int mode)
 {
        int tries = 4;
                  int mode)
 {
        int tries = 4;
@@ -461,7 +461,7 @@ void kill_all(int sig)
 }
 
 /** Turn a user name into a uid */
 }
 
 /** Turn a user name into a uid */
-int name_to_uid(char *name, uid_t *uid)
+int name_to_uid(const char *name, uid_t *uid)
 {
        struct passwd *pass;
        if (!name || !*name)
 {
        struct passwd *pass;
        if (!name || !*name)
@@ -475,7 +475,7 @@ int name_to_uid(char *name, uid_t *uid)
 }
 
 /** Turn a group name into a gid */
 }
 
 /** Turn a group name into a gid */
-int name_to_gid(char *name, gid_t *gid)
+int name_to_gid(const char *name, gid_t *gid)
 {
        struct group *grp;
        if (!name || !*name)
 {
        struct group *grp;
        if (!name || !*name)
@@ -1149,9 +1149,7 @@ char *human_dnum(double dnum, int decimal_digits)
        return buf;
 }
 
        return buf;
 }
 
-/**
- * Return the date and time as a string
- **/
+/* Return the date and time as a string.  Some callers tweak returned buf. */
 char *timestring(time_t t)
 {
        static char TimeBuf[200];
 char *timestring(time_t t)
 {
        static char TimeBuf[200];