From 536b84680b4ab1f29fa456b4fa7b5b16eff4af8f Mon Sep 17 00:00:00 2001 From: David Dykstra Date: Sun, 26 Jan 2003 03:46:54 +0000 Subject: [PATCH] Open config files in text mode when O_TEXT is defined. This helps on Cygwin when the config files are on a filesystem that is mounted in binary mode. Patch from Ville Herva. --- NEWS | 4 ++++ authenticate.c | 4 ++-- clientserver.c | 2 +- exclude.c | 4 ++-- params.c | 2 +- rsync.h | 14 ++++++++++++++ syscall.c | 4 ++-- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 63ebd58c..2e6404d8 100644 --- 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) + * 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) diff --git a/authenticate.c b/authenticate.c index 7d44da6e..a1c35755 100644 --- a/authenticate.c +++ b/authenticate.c @@ -82,7 +82,7 @@ static int get_secret(int module, char *user, char *secret, int len) 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) { @@ -144,7 +144,7 @@ static char *getpassf(char *filename) 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; diff --git a/clientserver.c b/clientserver.c index d158a2ff..709057f6 100644 --- a/clientserver.c +++ b/clientserver.c @@ -514,7 +514,7 @@ int start_daemon(int f_in, int f_out) 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) { diff --git a/exclude.c b/exclude.c index 693babb6..848d5613 100644 --- 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, "-")) { - f = fopen(fname,"r"); + f = fopen(fname,"r" O_TEXT_STR); } else { - f = fdopen(0, "r"); + f = fdopen(0, "r" O_TEXT_STR); } if (!f) { if (fatal) { diff --git a/params.c b/params.c index 81638118..b224ec9d 100644 --- a/params.c +++ b/params.c @@ -488,7 +488,7 @@ static FILE *OpenConfFile( char *FileName ) 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", diff --git a/rsync.h b/rsync.h index 8592984b..0477a4c4 100644 --- a/rsync.h +++ b/rsync.h @@ -595,6 +595,20 @@ void rsyserr(enum logcode, int, const char *, ...) #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); diff --git a/syscall.c b/syscall.c index 58f1f677..c620f607 100644 --- 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 } -#ifdef O_BINARY + /* for Windows */ flags |= O_BINARY; -#endif + /* some systems can't handle a double / */ if (pathname[0] == '/' && pathname[1] == '/') pathname++; -- 2.34.1