2 Copyright © 1995-2003, 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 ******************************************************************************/
61 ULONG pid
= (ULONG
)FindTask(0L);
62 char *c
= template + strlen(template);
68 remainder
= (int)(pid
% 10L);
75 c
++; /* ... c now points to the 1st char of the template tail */
77 if (*c
) /* FIXME: why would you get *c == 0 legitimately? */
79 /* Loop over the first position of the tail, bumping it up as necessary */
80 for(*c
= 'A'; *c
<= 'Z'; (*c
)++)
82 if (!(lock
= Lock(template, ACCESS_READ
)))
88 *c
= 0; /* FIXME: looks wrong. Why would you want to chop the tail? */