]> pd.if.org Git - pdclib/blobdiff - platform/posix/functions/stdio/tmpfile.c
PDCLib includes with quotes, not <>.
[pdclib] / platform / posix / functions / stdio / tmpfile.c
index deb992ccbc80e2133e6eb1a102823ba838c06784..07b18ceec9bd769f751ea48eed38a7f194b79ad4 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /* tmpfile( void )
 
    This file is part of the Public Domain C Library (PDCLib).
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
-
-#include <_PDCLIB_glue.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+#include "_PDCLIB_glue.h"
 #include <unistd.h>
+#ifdef __linux__
+/* get O_CLOEXEC without sys/types.h being awful */
+#include <asm/fcntl.h>
+int open(const char *fname, int flags, ...);
+#else
+#include <fcntl.h>
+#endif
 
 extern const _PDCLIB_fileops_t _PDCLIB_fileops;
 
@@ -52,7 +52,7 @@ FILE* _PDCLIB_nothrow tmpfile( void )
            (file might exist but not readable). Replace with something more
            appropriate.
         */
-        fd = open( filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR );
+        fd = open( filename, O_CREAT | O_EXCL | O_RDWR, 0600 );
         if ( fd != -1 )
         {
             break;
@@ -61,9 +61,9 @@ FILE* _PDCLIB_nothrow tmpfile( void )
     close( urandom );
 
     FILE* rc = _PDCLIB_fvopen(((_PDCLIB_fd_t){ .sval = fd}), &_PDCLIB_fileops,
-                                _PDCLIB_FWRITE | _PDCLIB_FRW | 
+                                _PDCLIB_FWRITE | _PDCLIB_FRW |
                                 _PDCLIB_DELONCLOSE, filename);
-    if( rc == NULL ) 
+    if( rc == NULL )
     {
         close( fd );
         return NULL;
@@ -75,7 +75,7 @@ FILE* _PDCLIB_nothrow tmpfile( void )
 #endif
 
 #ifdef TEST
-#include <_PDCLIB_test.h>
+#include "_PDCLIB_test.h"
 #include <string.h>
 
 int main( void )