Moved inline functions from rsync.h into ifuncs.h.
[rsync/rsync.git] / log.c
diff --git a/log.c b/log.c
index ad0d00b..e916b95 100644 (file)
--- a/log.c
+++ b/log.c
@@ -6,8 +6,9 @@
  * Copyright (C) 2003-2007 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as
- * published by the Free Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,6 +20,7 @@
  */
 
 #include "rsync.h"
+#include "ifuncs.h"
 
 extern int verbose;
 extern int dry_run;
@@ -311,26 +313,25 @@ void rwrite(enum logcode code, const char *buf, int len, int is_utf8)
 
 #ifdef ICONV_CONST
        if (ic != (iconv_t)-1) {
+               xbuf outbuf, inbuf;
                char convbuf[1024];
-               ICONV_CONST char *in_buf = (ICONV_CONST char *)buf;
-               char *out_buf = convbuf;
-               size_t in_cnt = len, out_cnt = sizeof convbuf - 1;
-
-               iconv(ic, NULL, 0, NULL, 0);
-               while (iconv(ic, &in_buf,&in_cnt,
-                            &out_buf,&out_cnt) == (size_t)-1) {
-                       if (out_buf != convbuf) {
-                               filtered_fwrite(f, convbuf, out_buf - convbuf, 0);
-                               out_buf = convbuf;
-                               out_cnt = sizeof convbuf - 1;
+               int ierrno;
+
+               INIT_CONST_XBUF(outbuf, convbuf);
+               INIT_XBUF(inbuf, (char*)buf, len, -1);
+
+               while (inbuf.len) {
+                       iconvbufs(ic, &inbuf, &outbuf, 0);
+                       ierrno = errno;
+                       if (outbuf.len) {
+                               filtered_fwrite(f, convbuf, outbuf.len, 0);
+                               outbuf.len = 0;
                        }
-                       if (errno == E2BIG)
+                       if (!ierrno || ierrno == E2BIG)
                                continue;
-                       fprintf(f, "\\#%03o", *(uchar*)in_buf++);
-                       in_cnt--;
+                       fprintf(f, "\\#%03o", CVAL(inbuf.buf, inbuf.pos++));
+                       inbuf.len--;
                }
-               if (out_buf != convbuf)
-                       filtered_fwrite(f, convbuf, out_buf - convbuf, 0);
        } else
 #endif
                filtered_fwrite(f, buf, len, !allow_8bit_chars);
@@ -791,7 +792,7 @@ void log_exit(int code, const char *file, int line)
                        (double)stats.total_written,
                        (double)stats.total_read,
                        (double)stats.total_size);
-       } else {
+       } else if (am_server != 2) {
                const char *name;
 
                name = rerr_name(code);