Added the --8-bit (-8) option.
[rsync/rsync.git] / rsync.c
diff --git a/rsync.c b/rsync.c
index 6d1ee8f..ebccb13 100644 (file)
--- a/rsync.c
+++ b/rsync.c
    process */
 
 #include "rsync.h"
+#if defined HAVE_ICONV_OPEN && defined HAVE_ICONV_H
+#include <iconv.h>
+#endif
+#if defined HAVE_LIBCHARSET_H && defined HAVE_LOCALE_CHARSET
+#include <libcharset.h>
+#elif defined HAVE_LANGINFO_H && defined HAVE_NL_LANGINFO
+#include <langinfo.h>
+#endif
 
 extern int verbose;
 extern int dry_run;
@@ -42,6 +50,46 @@ extern int keep_dirlinks;
 extern int make_backups;
 extern struct stats stats;
 
+#if defined HAVE_ICONV_OPEN && defined HAVE_ICONV_H
+iconv_t ic_chck = (iconv_t)-1;
+
+static const char *default_charset(void)
+{
+#if defined HAVE_LIBCHARSET_H && defined HAVE_LOCALE_CHARSET
+       return locale_charset();
+#elif defined HAVE_LANGINFO_H && defined HAVE_NL_LANGINFO
+       return nl_langinfo(CODESET);
+#else
+       return ""; /* Works with (at the very least) gnu iconv... */
+#endif
+}
+
+void setup_iconv()
+{
+       const char *defset;
+
+       if (!am_server)
+               return;
+
+       defset = default_charset();
+
+       /* It's OK if this fails... */
+       ic_chck = iconv_open(defset, defset);
+
+       if (verbose > 3) {
+               if (ic_chck == (iconv_t)-1) {
+                       rprintf(FINFO,
+                               "note: iconv_open(\"%s\", \"%s\") failed (%d)"
+                               " -- using isprint() instead of iconv().\n",
+                               defset, defset, errno);
+               } else {
+                       rprintf(FINFO,
+                               "note: iconv_open(\"%s\", \"%s\") succeeded.\n",
+                               defset, defset);
+               }
+       }
+}
+#endif
 
 /*
   free a sums struct