summaryrefslogtreecommitdiff
path: root/lib/curl_setup.h
diff options
context:
space:
mode:
authorJay Satiro <raysatiro@yahoo.com>2015-06-01 03:20:18 -0400
committerJay Satiro <raysatiro@yahoo.com>2015-06-01 03:21:23 -0400
commite8423f9ce1507c749c559f1ac1847fa433e66c45 (patch)
treee8596020f27127160bfeedd51ecbc6b95da2c4d5 /lib/curl_setup.h
parent9f5dcab83d77b2331ed2716f901e5cb4a0c17529 (diff)
downloadcurl-e8423f9ce1507c749c559f1ac1847fa433e66c45.tar.gz
curl_setup: Add macros for FOPEN_READTEXT, FOPEN_WRITETEXT
- Change fopen calls to use FOPEN_READTEXT instead of "r" or "rt" - Change fopen calls to use FOPEN_WRITETEXT instead of "w" or "wt" This change is to explicitly specify when we need to read/write text. Unfortunately 't' is not part of POSIX fopen so we can't specify it directly. Instead we now have FOPEN_READTEXT, FOPEN_WRITETEXT. Prior to this change we had an issue on Windows if an application that uses libcurl overrides the default file mode to binary. The default file mode in Windows is normally text mode (translation mode) and that's what libcurl expects. Bug: https://github.com/bagder/curl/pull/258#issuecomment-107093055 Reported-by: Orgad Shaneh
Diffstat (limited to 'lib/curl_setup.h')
-rw-r--r--lib/curl_setup.h20
1 files changed, 20 insertions, 0 deletions
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 */