-
- /* Under VMS, fopen(file, "wb") will craete a new version of the
- same file. This is not good, so let's try updating an existing
- one, and create file only if it doesn't already exist. This
- should be completely harmless on system that have no file
- versions. -- Richard Levitte */
- out=fopen(file,"rb+");
- if (out == NULL && errno == ENOENT)
- {
- errno = 0;
- out=fopen(file,"wb");
- }
+
+#if defined(O_CREAT) && !defined(WIN32)
+ /* For some reason Win32 can't write to files created this way */
+
+ /* chmod(..., 0600) is too late to protect the file,
+ * permissions should be restrictive from the start */
+ int fd = open(file, O_CREAT, 0600);
+ if (fd != -1)
+ out = fdopen(fd, "wb");
+#endif
+ if (out == NULL)
+ out = fopen(file,"wb");