]> pd.if.org Git - pdclib/commitdiff
tmpfile() implementation now based on /proc/sys/kernel/random/uuid.
authorsolar <unknown>
Sat, 19 Jun 2010 18:40:21 +0000 (18:40 +0000)
committersolar <unknown>
Sat, 19 Jun 2010 18:40:21 +0000 (18:40 +0000)
functions/stdio/fclose.c
platform/example/functions/stdio/tmpfile.c
platform/example/internals/_PDCLIB_config.h
platform/example_64/internals/_PDCLIB_config.h
platform/example_cygwin/internals/_PDCLIB_config.h

index dc27fe2eb1555a5e36bd7ceb513390d675baf415..0e822eb95ad58af5518497af060b032a22a63d7e 100644 (file)
@@ -43,8 +43,14 @@ int fclose( struct _PDCLIB_file_t * stream )
             {
                 _PDCLIB_filelist = stream->next;
             }
+            /* Delete tmpfile() */
+            if ( stream->status & _PDCLIB_DELONCLOSE )
+            {
+                remove( stream->filename );
+            }
             /* Free stream */
             free( stream );
+
             return 0;
         }
         previous = current;
index 4c55e5d3542a4c4db4f16f14fcd7d8425b6050ec..44b975d36b13a96f2bf8d63717cd680ec230201f 100644 (file)
@@ -24,7 +24,7 @@
 extern struct _PDCLIB_file_t * _PDCLIB_filelist;
 
 /* This is an example implementation of tmpfile() fit for use with POSIX
-   POSIX kernels.
+   kernels.
 */
 struct _PDCLIB_file_t * tmpfile( void )
 {
@@ -32,7 +32,7 @@ struct _PDCLIB_file_t * tmpfile( void )
     /* This is the chosen way to get high-quality randomness. Replace as
        appropriate.
     */
-    FILE * randomsource = fopen( "/dev/urandom", "rb" );
+    FILE * randomsource = fopen( "/proc/sys/kernel/random/uuid", "rb" );
     char filename[ L_tmpnam ];
     _PDCLIB_fd_t fd;
     if ( randomsource == NULL )
@@ -48,9 +48,9 @@ struct _PDCLIB_file_t * tmpfile( void )
            use high-quality randomness instead of a pseudo-random sequence to
            generate the filename candidate, which is *also* platform-dependent.
         */
-        uint32_t random;
-        fscanf( randomsource, "%" SCNu32, &random ); 
-        sprintf( filename, "/tmp/%010" PRNu32 ".tmp", random );
+        unsigned int random;
+        fscanf( randomsource, "%u", &random ); 
+        sprintf( filename, "/tmp/%u.tmp", random );
         /* Check if file of this name exists. Note that fopen() is a very weak
            check, which does not take e.g. access permissions into account
            (file might exist but not readable). Replace with something more
@@ -71,7 +71,7 @@ struct _PDCLIB_file_t * tmpfile( void )
         close( fd );
         return NULL;
     }
-    rc->status = _PDCLIB_filemode( "wb+" ) | _PDCLIB_LIBBUFFER | _IOLBF | _PDCLIB_DELONCLOSE;
+    rc->status = _PDCLIB_filemode( "wb+" ) | _IOLBF | _PDCLIB_DELONCLOSE;
     rc->handle = fd;
     rc->ungetbuf = (unsigned char *)rc + sizeof( struct _PDCLIB_file_t );
     rc->filename = (char *)rc->ungetbuf + _PDCLIB_UNGETCBUFSIZE;
index 4251522bc4ec88d0b787c2878f5d16cdafe7b3c8..89028b50fa471130cbd006d1a9bf68f811f07bd7 100644 (file)
@@ -258,8 +258,8 @@ typedef int _PDCLIB_fd_t;
 /* Length of the longest filename the implementation guarantees to support. */
 #define _PDCLIB_FILENAME_MAX 128
 
-/* Buffer size for tmpnam(). */
-#define _PDCLIB_L_tmpnam 100
+/* Maximum length of filenames generated by tmpnam(). (See tmpfile.c.) */
+#define _PDCLIB_L_tmpnam 46
 
 /* Number of distinct file names that can be generated by tmpnam(). */
 #define _PDCLIB_TMP_MAX 50
index 65abc89ea192d1618d50fb4186a47bacfe259e6e..30d51b1f701987ef5a64bd707dde1eafd0bfd636 100644 (file)
@@ -251,8 +251,8 @@ typedef int _PDCLIB_fd_t;
 /* Length of the longest filename the implementation guarantees to support. */
 #define _PDCLIB_FILENAME_MAX 128
 
-/* Buffer size for tmpnam(). */
-#define _PDCLIB_L_tmpnam 100
+/* Maximum length of filenames generated by tmpnam(). (See tmpfile.c.) */
+#define _PDCLIB_L_tmpnam 46
 
 /* Number of distinct file names that can be generated by tmpnam(). */
 #define _PDCLIB_TMP_MAX 50
index 78397be438e54a3439334f8d94904ba4bf00aa29..32e0906ffece99c83977fd82890c1806c5ba347a 100644 (file)
@@ -258,9 +258,6 @@ typedef int _PDCLIB_fd_t;
 /* Length of the longest filename the implementation guarantees to support. */
 #define _PDCLIB_FILENAME_MAX 128
 
-/* Buffer size for tmpnam(). */
-#define _PDCLIB_L_tmpnam 100
-
 /* Number of distinct file names that can be generated by tmpnam(). */
 #define _PDCLIB_TMP_MAX 50