Changeset 424

Show
Ignore:
Timestamp:
06/19/10 20:40:21 (3 months ago)
Author:
solar
Message:

tmpfile() implementation now based on /proc/sys/kernel/random/uuid.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/functions/stdio/fclose.c

    r420 r424  
    4444                _PDCLIB_filelist = stream->next; 
    4545            } 
     46            /* Delete tmpfile() */ 
     47            if ( stream->status & _PDCLIB_DELONCLOSE ) 
     48            { 
     49                remove( stream->filename ); 
     50            } 
    4651            /* Free stream */ 
    4752            free( stream ); 
     53 
    4854            return 0; 
    4955        } 
  • trunk/platform/example/functions/stdio/tmpfile.c

    r420 r424  
    2525 
    2626/* This is an example implementation of tmpfile() fit for use with POSIX 
    27    POSIX kernels. 
     27   kernels. 
    2828*/ 
    2929struct _PDCLIB_file_t * tmpfile( void ) 
     
    3333       appropriate. 
    3434    */ 
    35     FILE * randomsource = fopen( "/dev/urandom", "rb" ); 
     35    FILE * randomsource = fopen( "/proc/sys/kernel/random/uuid", "rb" ); 
    3636    char filename[ L_tmpnam ]; 
    3737    _PDCLIB_fd_t fd; 
     
    4949           generate the filename candidate, which is *also* platform-dependent. 
    5050        */ 
    51         uint32_t random; 
    52         fscanf( randomsource, "%" SCNu32, &random );  
    53         sprintf( filename, "/tmp/%010" PRNu32 ".tmp", random ); 
     51        unsigned int random; 
     52        fscanf( randomsource, "%u", &random );  
     53        sprintf( filename, "/tmp/%u.tmp", random ); 
    5454        /* Check if file of this name exists. Note that fopen() is a very weak 
    5555           check, which does not take e.g. access permissions into account 
     
    7272        return NULL; 
    7373    } 
    74     rc->status = _PDCLIB_filemode( "wb+" ) | _PDCLIB_LIBBUFFER | _IOLBF | _PDCLIB_DELONCLOSE; 
     74    rc->status = _PDCLIB_filemode( "wb+" ) | _IOLBF | _PDCLIB_DELONCLOSE; 
    7575    rc->handle = fd; 
    7676    rc->ungetbuf = (unsigned char *)rc + sizeof( struct _PDCLIB_file_t ); 
  • trunk/platform/example/internals/_PDCLIB_config.h

    r414 r424  
    259259#define _PDCLIB_FILENAME_MAX 128 
    260260 
    261 /* Buffer size for tmpnam(). */ 
    262 #define _PDCLIB_L_tmpnam 100 
     261/* Maximum length of filenames generated by tmpnam(). (See tmpfile.c.) */ 
     262#define _PDCLIB_L_tmpnam 46 
    263263 
    264264/* Number of distinct file names that can be generated by tmpnam(). */ 
  • trunk/platform/example_64/internals/_PDCLIB_config.h

    r415 r424  
    252252#define _PDCLIB_FILENAME_MAX 128 
    253253 
    254 /* Buffer size for tmpnam(). */ 
    255 #define _PDCLIB_L_tmpnam 100 
     254/* Maximum length of filenames generated by tmpnam(). (See tmpfile.c.) */ 
     255#define _PDCLIB_L_tmpnam 46 
    256256 
    257257/* Number of distinct file names that can be generated by tmpnam(). */ 
  • trunk/platform/example_cygwin/internals/_PDCLIB_config.h

    r415 r424  
    259259#define _PDCLIB_FILENAME_MAX 128 
    260260 
    261 /* Buffer size for tmpnam(). */ 
    262 #define _PDCLIB_L_tmpnam 100 
    263  
    264261/* Number of distinct file names that can be generated by tmpnam(). */ 
    265262#define _PDCLIB_TMP_MAX 50