2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
7 #include <proto/exec.h>
11 #include <exec/types.h>
15 #include <aros/debug.h>
17 /*****************************************************************************
28 Make a unique temporary file name.
31 template - template to change into unique filename
37 Template must end in "XXXXXX" (i.e at least 6 X's).
39 Prior to this paragraph being created, mktemp() sometimes produced filenames
40 with '/' in them. AROS doesn't like that at all. Fortunately, the bug in this
41 function which produced it has been fixed. -- blippy
43 For clarity, define the HEAD of the template to be the part before the tail,
44 and the TAIL to be the succession of X's. So in, T:temp.XXXXXX , the head is
45 T:temp. and the tail is XXXXXX .
50 Cannot create more than 26 filenames for the same process id. This is because
51 the "bumping" is only done to the first tail character - it should be
52 generalised to bump more characters if necessary.
57 Based on libnix mktemp
59 ******************************************************************************/
61 IPTR pid
= (IPTR
)FindTask(0L);
62 char *c
= template + strlen(template);
69 assert(remainder
>=0 && remainder
<10);
74 c
++; /* ... c now points to the 1st char of the template tail */
76 /* If template errornously does not end in X c will point to '\0';
81 /* Loop over the first position of the tail, bumping it up as necessary */
82 for(*c
= 'A'; *c
<= 'Z'; (*c
)++)
84 if (!(lock
= Lock(template, SHARED_LOCK
)))
86 if (IoErr() != ERROR_OBJECT_IN_USE
)
88 D(bug("No lock (IoErr: %d); returning '%s'\n", IoErr(), template));
96 D(bug("26 tries exhausted; Returning '%s'\n", template));