{
_PDCLIB_filelist = stream->next;
}
{
_PDCLIB_filelist = stream->next;
}
+ /* Delete tmpfile() */
+ if ( stream->status & _PDCLIB_DELONCLOSE )
+ {
+ remove( stream->filename );
+ }
/* Free stream */
free( stream );
/* Free stream */
free( stream );
return 0;
}
previous = current;
return 0;
}
previous = current;
extern struct _PDCLIB_file_t * _PDCLIB_filelist;
/* This is an example implementation of tmpfile() fit for use with POSIX
extern struct _PDCLIB_file_t * _PDCLIB_filelist;
/* This is an example implementation of tmpfile() fit for use with POSIX
*/
struct _PDCLIB_file_t * tmpfile( void )
{
*/
struct _PDCLIB_file_t * tmpfile( void )
{
/* This is the chosen way to get high-quality randomness. Replace as
appropriate.
*/
/* 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 )
char filename[ L_tmpnam ];
_PDCLIB_fd_t fd;
if ( randomsource == NULL )
use high-quality randomness instead of a pseudo-random sequence to
generate the filename candidate, which is *also* platform-dependent.
*/
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
/* 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
close( fd );
return NULL;
}
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;
rc->handle = fd;
rc->ungetbuf = (unsigned char *)rc + sizeof( struct _PDCLIB_file_t );
rc->filename = (char *)rc->ungetbuf + _PDCLIB_UNGETCBUFSIZE;
/* Length of the longest filename the implementation guarantees to support. */
#define _PDCLIB_FILENAME_MAX 128
/* 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
/* Number of distinct file names that can be generated by tmpnam(). */
#define _PDCLIB_TMP_MAX 50
/* Length of the longest filename the implementation guarantees to support. */
#define _PDCLIB_FILENAME_MAX 128
/* 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
/* Number of distinct file names that can be generated by tmpnam(). */
#define _PDCLIB_TMP_MAX 50
/* Length of the longest filename the implementation guarantees to support. */
#define _PDCLIB_FILENAME_MAX 128
/* 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
/* Number of distinct file names that can be generated by tmpnam(). */
#define _PDCLIB_TMP_MAX 50