aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/cookie.c4
-rw-r--r--lib/curl_setup.h20
-rw-r--r--lib/memdebug.c2
-rw-r--r--lib/netrc.c6
-rw-r--r--lib/vtls/gtls.c2
-rw-r--r--lib/vtls/openssl.c2
6 files changed, 26 insertions, 10 deletions
diff --git a/lib/cookie.c b/lib/cookie.c
index 012792605..fd7ed4168 100644
--- a/lib/cookie.c
+++ b/lib/cookie.c
@@ -914,7 +914,7 @@ struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
fp = NULL;
}
else
- fp = file?fopen(file, "r"):NULL;
+ fp = file?fopen(file, FOPEN_READTEXT):NULL;
c->newsession = newsession; /* new session? */
@@ -1262,7 +1262,7 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere)
use_stdout=TRUE;
}
else {
- out = fopen(dumphere, "w");
+ out = fopen(dumphere, FOPEN_WRITETEXT);
if(!out)
return 1; /* failure */
}
diff --git a/lib/curl_setup.h b/lib/curl_setup.h
index 9c7cc07eb..cbec34f26 100644
--- a/lib/curl_setup.h
+++ b/lib/curl_setup.h
@@ -707,4 +707,24 @@ int netware_init(void);
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
+/* In Windows the default file mode is text but an application can override it.
+Therefore we specify it explicitly. https://github.com/bagder/curl/pull/258
+*/
+#if defined(WIN32)
+#define FOPEN_READTEXT "rt"
+#define FOPEN_WRITETEXT "wt"
+#elif defined(__CYGWIN__)
+/* Cygwin has specific behavior we need to address when WIN32 is not defined.
+https://cygwin.com/cygwin-ug-net/using-textbinary.html
+For write we want our output to have line endings of LF and be compatible with
+other Cygwin utilities. For read we want to handle input that may have line
+endings either CRLF or LF so 't' is appropriate.
+*/
+#define FOPEN_READTEXT "rt"
+#define FOPEN_WRITETEXT "w"
+#else
+#define FOPEN_READTEXT "r"
+#define FOPEN_WRITETEXT "w"
+#endif
+
#endif /* HEADER_CURL_SETUP_H */
diff --git a/lib/memdebug.c b/lib/memdebug.c
index 3b38a7492..dd8889b2d 100644
--- a/lib/memdebug.c
+++ b/lib/memdebug.c
@@ -112,7 +112,7 @@ void curl_memdebug(const char *logname)
{
if(!logfile) {
if(logname && *logname)
- logfile = fopen(logname, "w");
+ logfile = fopen(logname, FOPEN_WRITETEXT);
else
logfile = stderr;
#ifdef MEMDEBUG_LOG_SYNC
diff --git a/lib/netrc.c b/lib/netrc.c
index 97a07b88e..06f8ea15a 100644
--- a/lib/netrc.c
+++ b/lib/netrc.c
@@ -109,11 +109,7 @@ int Curl_parsenetrc(const char *host,
netrc_alloc = TRUE;
}
-#ifdef __CYGWIN__
- file = fopen(netrcfile, "rt");
-#else
- file = fopen(netrcfile, "r");
-#endif
+ file = fopen(netrcfile, FOPEN_READTEXT);
if(netrc_alloc)
free(netrcfile);
if(file) {
diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c
index d6eb6c445..1db31e40c 100644
--- a/lib/vtls/gtls.c
+++ b/lib/vtls/gtls.c
@@ -231,7 +231,7 @@ static gnutls_datum_t load_file (const char *file)
long filelen;
void *ptr;
- if(!(f = fopen(file, "r")))
+ if(!(f = fopen(file, "rb")))
return loaded_file;
if(fseek(f, 0, SEEK_END) != 0
|| (filelen = ftell(f)) < 0
diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c
index 96a7d6e89..eb2cf5bf5 100644
--- a/lib/vtls/openssl.c
+++ b/lib/vtls/openssl.c
@@ -2725,7 +2725,7 @@ static CURLcode servercert(struct connectdata *conn,
/* e.g. match issuer name with provided issuer certificate */
if(data->set.str[STRING_SSL_ISSUERCERT]) {
- fp = fopen(data->set.str[STRING_SSL_ISSUERCERT], "r");
+ fp = fopen(data->set.str[STRING_SSL_ISSUERCERT], FOPEN_READTEXT);
if(!fp) {
if(strict)
failf(data, "SSL: Unable to open issuer cert (%s)",