make armeb specific header (set AROS_BIG_ENDIAN to one)
[AROS.git] / compiler / stdc / tmpnam.c
blobe9c19c28ae0314c863b4f2ce4627b1351be69637
1 /*
2 Copyright © 2010-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function tmpnam().
6 This function is based on the public domain libnix code
7 */
9 #include <stdlib.h>
10 #include <dos/dos.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include <aros/libcall.h>
15 #include "__stdcio_intbase.h"
17 /*****************************************************************************
19 NAME */
20 #include <stdio.h>
22 char *tmpnam(
24 /* SYNOPSIS */
25 char *s)
27 /* FUNCTION
28 The tmpnam function generates a string that is a valid file name and
29 that is not the same as the name of an existing file. The function
30 is potentially capable of generating TMP_MAX different strings, but
31 any or all of them may already be in use by existing files and thus
32 not be suitable return values.
34 INPUTS
35 Pointer to a string of at least L_tmpnam characters.
37 RESULT
38 The resulting file name is returned in the input string pointer
39 or a pointer to an internal buffer if NULL was passed to the function.
40 If file name generation failed a NULL is returned.
42 NOTES
44 EXAMPLE
46 BUGS
48 SEE ALSO
49 tmpfile()
51 INTERNALS
53 ******************************************************************************/
55 struct StdCIOIntBase *StdCIOBase =
56 (struct StdCIOIntBase *)__aros_getbase_StdCIOBase();
57 BPTR filelock;
58 if (s == NULL)
59 s = StdCIOBase->tmpnambuffer;
61 do /* generate a filename that doesn't exist */
63 sprintf(s,"T:tempfile_stdc_%p_%lu",FindTask(NULL),StdCIOBase->filecount++);
64 filelock = Lock(s,ACCESS_WRITE);
65 if(filelock != 0)
66 UnLock(filelock);
67 } while(filelock!=0 || IoErr()==ERROR_OBJECT_IN_USE);
69 return s;