x11gfx.hidd: support 32 bit modes
[AROS.git] / compiler / stdc / tmpfile.c
blobe2799c97e01f07f88c00868325ef040936bcd6b5
1 /*
2 Copyright © 2010-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function tmpfile().
6 This function is based on the public domain libnix code
7 */
8 #include "__stdio.h"
10 /*****************************************************************************
12 NAME */
13 #include <stdio.h>
15 FILE * tmpfile(
17 /* SYNOPSIS */
18 void)
20 /* FUNCTION
21 The tmpfile() function creates a temporary file that is different from
22 any other existing file and that will automatically be removed when
23 it is closed or at program termination. The file is opened for update
24 with "wb+" mode.
26 INPUTS
29 RESULT
30 Pointer to the stream that was created. On error NULL is returned.
32 NOTES
33 This function uses tmpnam(NULL) to get the file name.
35 EXAMPLE
36 #include <errno.h>
37 #include <stdio.h>
38 #include <string.h>
40 main()
42 FILE * fp;
44 fp = tmpfile();
45 if ( fp == NULL)
47 perror(strerror(errno));
48 return;
51 fprintf(fp, "do a bit of writing to the temp file");
54 BUGS
56 SEE ALSO
57 fopen(), tmpnam()
59 INTERNALS
61 ******************************************************************************/
63 char *s;
64 FILE *f = NULL;
66 do {
67 s = tmpnam(NULL);
69 if (s == NULL)
70 return NULL;
72 f = fopen(s, "wb+");
73 } while (f == NULL);
75 f->flags |= __STDCIO_STDIO_TMP;
77 return f;
78 } /* tmpfile() */