summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2009-06-03 19:24:24 +0200
committerWerner Koch <wk@gnupg.org>2009-06-03 19:24:24 +0200
commitdac70ca2fda12f4fb01eb3f2f33f3831a26c10a0 (patch)
treed595a46157bf18797f5226b10e1216b9498679de /common
parentFix for bug#1066. (diff)
downloadgnupg2-dac70ca2fda12f4fb01eb3f2f33f3831a26c10a0.tar.xz
gnupg2-dac70ca2fda12f4fb01eb3f2f33f3831a26c10a0.zip
Fixed an fopen problem on Windows Vista.
Diffstat (limited to 'common')
-rw-r--r--common/ChangeLog4
-rw-r--r--common/estream.c84
2 files changed, 37 insertions, 51 deletions
diff --git a/common/ChangeLog b/common/ChangeLog
index 2f5a65a03..50669612e 100644
--- a/common/ChangeLog
+++ b/common/ChangeLog
@@ -1,3 +1,7 @@
+2009-06-03 Werner Koch <wk@g10code.com>
+
+ * estream.c (es_convert_mode): Rewrite and support the "x" flag.
+
2009-05-28 David Shaw <dshaw@jabberwocky.com>
From 1.4:
diff --git a/common/estream.c b/common/estream.c
index ee6c51af8..214c2ff7d 100644
--- a/common/estream.c
+++ b/common/estream.c
@@ -897,67 +897,49 @@ static es_cookie_io_functions_t estream_functions_file =
};
-
-/* Stream primitives. */
-
static int
es_convert_mode (const char *mode, unsigned int *modeflags)
{
+ unsigned int omode, oflags;
- /* FIXME: We need to allow all mode flags permutations. */
- struct
- {
- const char *mode;
- unsigned int flags;
- } mode_flags[] = { { "r",
- O_RDONLY },
- { "rb",
- O_RDONLY | O_BINARY },
- { "w",
- O_WRONLY | O_TRUNC | O_CREAT },
- { "wb",
- O_WRONLY | O_TRUNC | O_CREAT | O_BINARY },
- { "a",
- O_WRONLY | O_APPEND | O_CREAT },
- { "ab",
- O_WRONLY | O_APPEND | O_CREAT | O_BINARY },
- { "r+",
- O_RDWR },
- { "rb+",
- O_RDWR | O_BINARY },
- { "r+b",
- O_RDONLY | O_WRONLY | O_BINARY },
- { "w+",
- O_RDWR | O_TRUNC | O_CREAT },
- { "wb+",
- O_RDWR | O_TRUNC | O_CREAT | O_BINARY },
- { "w+b",
- O_RDWR | O_TRUNC | O_CREAT | O_BINARY },
- { "a+",
- O_RDWR | O_CREAT | O_APPEND },
- { "ab+",
- O_RDWR | O_CREAT | O_APPEND | O_BINARY },
- { "a+b",
- O_RDWR | O_CREAT | O_APPEND | O_BINARY }
- };
- unsigned int i;
- int err;
-
- for (i = 0; i < DIM (mode_flags); i++)
- if (! strcmp (mode_flags[i].mode, mode))
- break;
- if (i == DIM (mode_flags))
+ switch (*mode)
{
+ case 'r':
+ omode = O_RDONLY;
+ oflags = 0;
+ break;
+ case 'w':
+ omode = O_WRONLY;
+ oflags = O_TRUNC | O_CREAT;
+ break;
+ case 'a':
+ omode = O_WRONLY;
+ oflags = O_APPEND | O_CREAT;
+ break;
+ default:
errno = EINVAL;
- err = -1;
+ return -1;
}
- else
+ for (mode++; *mode; mode++)
{
- err = 0;
- *modeflags = mode_flags[i].flags;
+ switch (*mode)
+ {
+ case '+':
+ omode = O_RDWR;
+ break;
+ case 'b':
+ oflags |= O_BINARY;
+ break;
+ case 'x':
+ oflags |= O_EXCL;
+ break;
+ default: /* Ignore unknown flags. */
+ break;
+ }
}
- return err;
+ *modeflags = (omode | oflags);
+ return 0;
}