summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-03-03 09:58:49 +0100
committerStef Walter <stefw@gnome.org>2013-03-03 10:07:14 +0100
commit61e0cb5dddb89ddab1d68791eb28d892c114622f (patch)
tree56d6c5d62ad4a9cd4f25693d9412283c5cb2b229
parentd9076a99c59bb0132b25277a2340f428c9b6c98e (diff)
downloadp11-kit-61e0cb5dddb89ddab1d68791eb28d892c114622f.tar.gz
Open files in binary mode on windows
So that the Windows' C library doesn't munge line endings
-rw-r--r--common/compat.h4
-rw-r--r--p11-kit/conf.c2
-rw-r--r--p11-kit/pin.c2
-rw-r--r--tools/tests/test.c11
4 files changed, 11 insertions, 8 deletions
diff --git a/common/compat.h b/common/compat.h
index 7eb42a5..d4858f0 100644
--- a/common/compat.h
+++ b/common/compat.h
@@ -64,6 +64,10 @@
#endif
#endif
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
#ifndef HAVE_GETPROGNAME
const char * getprogname (void);
#endif
diff --git a/p11-kit/conf.c b/p11-kit/conf.c
index 28008aa..778ea00 100644
--- a/p11-kit/conf.c
+++ b/p11-kit/conf.c
@@ -125,7 +125,7 @@ read_config_file (const char* filename, int flags)
assert (filename);
- f = fopen (filename, "r");
+ f = fopen (filename, "rb");
if (f == NULL) {
error = errno;
if ((flags & CONF_IGNORE_MISSING) &&
diff --git a/p11-kit/pin.c b/p11-kit/pin.c
index afcb8ca..dac635c 100644
--- a/p11-kit/pin.c
+++ b/p11-kit/pin.c
@@ -465,7 +465,7 @@ p11_kit_pin_file_callback (const char *pin_source,
if (pin_flags & P11_KIT_PIN_FLAGS_RETRY)
return NULL;
- fd = open (pin_source, O_RDONLY);
+ fd = open (pin_source, O_BINARY | O_RDONLY);
if (fd == -1)
return NULL;
diff --git a/tools/tests/test.c b/tools/tests/test.c
index c445099..61fda83 100644
--- a/tools/tests/test.c
+++ b/tools/tests/test.c
@@ -54,20 +54,19 @@ read_file (CuTest *tc,
const char *filename,
long *len)
{
+ struct stat sb;
FILE *f = NULL;
char *data;
- f = fopen (filename, "r");
+ f = fopen (filename, "rb");
if (f == NULL)
CuFail_Line (tc, file, line, "Couldn't open file", filename);
/* Figure out size */
- if (fseek (f, 0, SEEK_END) == -1 ||
- (*len = ftell (f)) == -1 ||
- fseek (f, 0, SEEK_SET) == -1) {
- CuFail_Line (tc, file, line, "Couldn't get file length", filename);
- }
+ if (stat (filename, &sb) < 0)
+ CuFail_Line (tc, file, line, "Couldn't stat file", filename);
+ *len = sb.st_size;
data = malloc (*len ? *len : 1);
assert (data != NULL);