Open config files in text mode when O_TEXT is defined. This helps on
authorDavid Dykstra <dwd@samba.org>
Sun, 26 Jan 2003 03:46:54 +0000 (03:46 +0000)
committerDavid Dykstra <dwd@samba.org>
Sun, 26 Jan 2003 03:46:54 +0000 (03:46 +0000)
Cygwin when the config files are on a filesystem that is mounted in
binary mode.  Patch from Ville Herva.

NEWS
authenticate.c
clientserver.c
exclude.c
params.c
rsync.h
syscall.c

diff --git a/NEWS b/NEWS
index 63ebd58..2e6404d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,10 @@ rsync changes since last release
     * Set the default value of --modify-window to 1 on Cygwin.  (Lapo
       Luchini)
 
     * Set the default value of --modify-window to 1 on Cygwin.  (Lapo
       Luchini)
 
+    * Open config files in text mode when O_TEXT is defined.  This helps
+      on Cygwin when the config files are on a filesystem that are mounted
+      in binary mode.  (Ville Herva)
+
     * Ignore errors from chmod when -p/-a/--preserve-perms is not set.
       (Dave Dykstra)
 
     * Ignore errors from chmod when -p/-a/--preserve-perms is not set.
       (Dave Dykstra)
 
index 7d44da6..a1c3575 100644 (file)
@@ -82,7 +82,7 @@ static int get_secret(int module, char *user, char *secret, int len)
 
        if (!fname || !*fname) return 0;
 
 
        if (!fname || !*fname) return 0;
 
-       fd = open(fname,O_RDONLY);
+       fd = open(fname,O_RDONLY | O_TEXT);
        if (fd == -1) return 0;
 
        if (do_stat(fname, &st) == -1) {
        if (fd == -1) return 0;
 
        if (do_stat(fname, &st) == -1) {
@@ -144,7 +144,7 @@ static char *getpassf(char *filename)
 
        if (!filename) return NULL;
 
 
        if (!filename) return NULL;
 
-       if ( (fd=open(filename,O_RDONLY)) == -1) {
+       if ( (fd=open(filename,O_RDONLY | O_TEXT)) == -1) {
                rsyserr(FERROR, errno, "could not open password file \"%s\"",filename);
                if (envpw) rprintf(FERROR,"falling back to RSYNC_PASSWORD environment variable.\n");    
                return NULL;
                rsyserr(FERROR, errno, "could not open password file \"%s\"",filename);
                if (envpw) rprintf(FERROR,"falling back to RSYNC_PASSWORD environment variable.\n");    
                return NULL;
index d158a2f..709057f 100644 (file)
@@ -514,7 +514,7 @@ int start_daemon(int f_in, int f_out)
 
        motd = lp_motd_file();
        if (motd && *motd) {
 
        motd = lp_motd_file();
        if (motd && *motd) {
-               FILE *f = fopen(motd,"r");
+               FILE *f = fopen(motd,"r" O_TEXT_STR);
                while (f && !feof(f)) {
                        int len = fread(line, 1, sizeof(line)-1, f);
                        if (len > 0) {
                while (f && !feof(f)) {
                        int len = fread(line, 1, sizeof(line)-1, f);
                        if (len > 0) {
index 693babb..848d561 100644 (file)
--- a/exclude.c
+++ b/exclude.c
@@ -224,9 +224,9 @@ struct exclude_struct **make_exclude_list(const char *fname,
        char line[MAXPATHLEN];
 
        if (strcmp(fname, "-")) {
        char line[MAXPATHLEN];
 
        if (strcmp(fname, "-")) {
-               f = fopen(fname,"r");
+               f = fopen(fname,"r" O_TEXT_STR);
        } else {
        } else {
-               f = fdopen(0, "r");
+               f = fdopen(0, "r" O_TEXT_STR);
        }
        if (!f) {
                if (fatal) {
        }
        if (!f) {
                if (fatal) {
index 8163811..b224ec9 100644 (file)
--- a/params.c
+++ b/params.c
@@ -488,7 +488,7 @@ static FILE *OpenConfFile( char *FileName )
     return( NULL );
     }
 
     return( NULL );
     }
 
-  OpenedFile = fopen( FileName, "r" );
+  OpenedFile = fopen( FileName, "r" O_TEXT_STR );
   if( NULL == OpenedFile )
     {
     rprintf(FERROR,"rsync: unable to open configuration file \"%s\": %s\n",
   if( NULL == OpenedFile )
     {
     rprintf(FERROR,"rsync: unable to open configuration file \"%s\": %s\n",
diff --git a/rsync.h b/rsync.h
index 8592984..0477a4c 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -595,6 +595,20 @@ void rsyserr(enum logcode, int, const char *, ...)
 #define inet_ntoa rep_inet_ntoa
 #endif
 
 #define inet_ntoa rep_inet_ntoa
 #endif
 
+/* Compatibility defines so that platforms that don't distinguish between
+ * text and binary files (like Cygwin does) can use the same code. */
+#ifndef O_TEXT
+#define O_TEXT 0
+#define O_TEXT_STR ""
+#else
+#define O_TEXT_STR "t"
+#endif
+#ifndef O_BINARY
+#define O_BINARY 0
+#define O_BINARY_STR ""
+#else
+#define O_BINARY_STR "b"
+#endif
 
 #ifndef HAVE_STRLCPY
 size_t strlcpy(char *d, const char *s, size_t bufsize);
 
 #ifndef HAVE_STRLCPY
 size_t strlcpy(char *d, const char *s, size_t bufsize);
index 58f1f67..c620f60 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -85,10 +85,10 @@ int do_open(char *pathname, int flags, mode_t mode)
            if (dry_run) return -1;
            CHECK_RO
        }
            if (dry_run) return -1;
            CHECK_RO
        }
-#ifdef O_BINARY
+
        /* for Windows */
        flags |= O_BINARY;
        /* for Windows */
        flags |= O_BINARY;
-#endif
+
        /* some systems can't handle a double / */
        if (pathname[0] == '/' && pathname[1] == '/') pathname++;
 
        /* some systems can't handle a double / */
        if (pathname[0] == '/' && pathname[1] == '/') pathname++;