2 This file has been released into the Public Domain.
5 POSIX function tmpfile().
13 #include <proto/dos.h>
16 /*****************************************************************************
27 The tmpfile() function returns a pointer to a stream
28 associated with a file descriptor returned by the routine
29 mkstemp(3). The created file is unlinked before tmpfile()
30 returns, causing the file to be automatically deleted when the
31 last reference to it is closed. The file is opened with the
32 access value `w+'. The file is created in the T: directory,
33 which is the standard AROS temp directory.
40 The tmpfile() function returns a pointer to an open file stream on
41 success. On error, a NULL pointer is returned and errno is set
45 The tmpfile() function may fail and set the global variable
46 errno for any of the errors specified for the library functions
47 fdopen() or mkstemp().
63 perror(strerror(errno));
67 fprintf(fp, "do a bit of writing to the temp file");
71 BUG1: The temporary file is neither closed nor deleted. Ideally,
72 unlink() could be used to mark the temp file for removal (see
73 BUG1 in the source code) - but I suspect a bug in unlink() itself,
74 whereby it tries to remove the file straight away, rather than
75 waiting for all references to it to be closed. The bug is not too
76 serious, because all temp files are written to the T: directory,
77 which get zapped when AROS is closed down. However, problems may
78 exist when you start creating over 26 temp files with the same PID.
86 ******************************************************************************/
88 #define TEMPLATE "T:temp.XXXXXX"
92 filename
= (char *)malloc(MAXPATHLEN
);
93 if (!filename
) { puts("FIXME: mktemp() malloc failed"); return NULL
;}
94 strcpy(filename
, TEMPLATE
);
97 fp
= fopen(filename
, "w+");
98 /* unlink(filename); -- see BUG1 in BUGS section */