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.
This commit is contained in:
David Dykstra
2003-01-26 03:46:54 +00:00
parent 7508b795bf
commit 536b84680b
7 changed files with 26 additions and 8 deletions

4
NEWS
View File

@@ -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)

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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",

14
rsync.h
View File

@@ -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);

View File

@@ -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++;