30601f14698461805981cb066fcba38820895041
[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 char *
16 m_scratch (char *file, char *template)
17 {
18     char *cp;
19     static char buffer[BUFSIZ], tmpfil[BUFSIZ];
20
21     snprintf (tmpfil, sizeof(tmpfil), "%sXXXXXX", template);
22 /*
23   Mkstemp work postponed until later -Doug
24 #ifdef HAVE_MKSTEMP
25     mkstemp (tmpfil);
26 #else
27 */
28     mktemp (tmpfil);
29 /*
30 #endif
31 */
32     /* nasty - this really means: if there is no '/' in the path */
33     if ((cp = r1bindex (file, '/')) == file)
34         strncpy (buffer, tmpfil, sizeof(buffer));
35     else
36         snprintf (buffer, sizeof(buffer), "%.*s%s", cp - file, file, tmpfil);
37     unlink (buffer);
38
39     return buffer;
40 }