* uip/.cvsignore: added "new".
[mmh] / sbr / m_scratch.c
1
2 /*
3  * m_scratch.c -- construct a scratch file
4  *
5  * $Id$
6  *
7  * This code is Copyright (c) 2002, by the authors of nmh.  See the
8  * COPYRIGHT file in the root directory of the nmh distribution for
9  * complete copyright information.
10  */
11
12 #include <h/mh.h>
13
14 /***************************************************************************
15  * DO NOT USE THIS FUNCTION!  IT WILL BE REMOVED IN THE FUTURE.
16  * THIS FUNCTION IS INSECURE.  USE THE FUNCTIONS DEFINED IN m_mktemp.c.
17  ***************************************************************************/
18 char *
19 m_scratch (char *file, char *template)
20 {
21     char *cp;
22     static char buffer[BUFSIZ], tmpfil[BUFSIZ];
23
24     snprintf (tmpfil, sizeof(tmpfil), "%sXXXXXX", template);
25 /*
26   Mkstemp work postponed until later -Doug
27 #ifdef HAVE_MKSTEMP
28     mkstemp (tmpfil);
29 #else
30 */
31     mktemp (tmpfil);
32 /*
33 #endif
34 */
35     /* nasty - this really means: if there is no '/' in the path */
36     if ((cp = r1bindex (file, '/')) == file)
37         strncpy (buffer, tmpfil, sizeof(buffer));
38     else
39         snprintf (buffer, sizeof(buffer), "%.*s%s", (int)(cp - file), file, tmpfil);
40     unlink (buffer);
41
42     return buffer;
43 }