2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
7 #include <proto/exec.h>
11 #include <exec/types.h>
14 #include <stdio.h> /* FIXME: remove */
16 /*****************************************************************************
27 Make a unique temporary file name.
30 template- Name of the environment variable.
36 Template must end in "XXXXXX" (i.e at least 6 X's).
38 Prior to this paragraph being created, mktemp() sometimes produced filenames
39 with '/' in them. AROS doesn't like that at all. Fortunately, the bug in this
40 function which produced it has been fixed. -- blippy
42 For clarity, define the HEAD of the template to be the part before the tail,
43 and the TAIL to be the succession of X's. So in, T:temp.XXXXXX , the head is
44 T:temp. and the tail is XXXXXX .
49 Cannot create more than 26 filenames for the same process id. This is because
50 the "bumping" is only done to the first tail character - it should be
51 generalised to bump more characters if necessary.
56 Based on libnix mktemp
58 ******************************************************************************/
60 ULONG pid
= (ULONG
)FindTask(0L);
61 char *c
= template + strlen(template);
67 remainder
= (int)(pid
% 10L);
74 c
++; /* ... c now points to the 1st char of the template tail */
76 if (*c
) /* FIXME: why would you get *c == 0 legitimately? */
78 /* Loop over the first position of the tail, bumping it up as necessary */
79 for(*c
= 'A'; *c
<= 'Z'; (*c
)++)
81 if (!(lock
= Lock(template, ACCESS_READ
)))
87 *c
= 0; /* FIXME: looks wrong. Why would you want to chop the tail? */