2 This file has been released into the Public Domain.
5 POSIX.1-2008 function tmpfile().
13 #include <proto/dos.h>
17 #include <aros/debug.h>
19 /*****************************************************************************
30 The tmpfile() function returns a pointer to a stream
31 associated with a file descriptor returned by the routine
32 mkstemp(3). The created file is unlinked before tmpfile()
33 returns, causing the file to be automatically deleted when the
34 last reference to it is closed. The file is opened with the
35 access value `w+'. The file is created in the T: directory,
36 which is the standard AROS temp directory.
43 The tmpfile() function returns a pointer to an open file stream on
44 success. On error, a NULL pointer is returned and errno is set
48 The tmpfile() function may fail and set the global variable
49 errno for any of the errors specified for the library functions
50 fdopen() or mkstemp().
66 perror(strerror(errno));
70 fprintf(fp, "do a bit of writing to the temp file");
74 BUG1: The temporary file is neither closed nor deleted. Ideally,
75 unlink() could be used to mark the temp file for removal (see
76 BUG1 in the source code) - but I suspect a bug in unlink() itself,
77 whereby it tries to remove the file straight away, rather than
78 waiting for all references to it to be closed. The bug is not too
79 serious, because all temp files are written to the T: directory,
80 which get zapped when AROS is closed down. However, problems may
81 exist when you start creating over 26 temp files with the same PID.
89 ******************************************************************************/
91 #define TEMPLATE "T:temp.XXXXXX"
95 filename
= (char *)malloc(MAXPATHLEN
);
96 if (!filename
) { puts("FIXME: mktemp() malloc failed"); return NULL
;}
97 strcpy(filename
, TEMPLATE
);
100 D(bug("[posixc/tmpfile()] filename: %s\n", filename
));
101 fp
= fopen(filename
, "w+");
102 /* unlink(filename); -- see BUG1 in BUGS section */