configure, configure.in stamp-h.in, and uip/Makefile.in modified to fix
[mmh] / sbr / m_scratch.c
1
2 /*
3  * m_scratch.c -- construct a scratch file
4  *
5  * $Id$
6  */
7
8 #include <h/mh.h>
9
10
11 char *
12 m_scratch (char *file, char *template)
13 {
14     char *cp;
15     static char buffer[BUFSIZ], tmpfil[BUFSIZ];
16
17     snprintf (tmpfil, sizeof(tmpfil), "%sXXXXXX", template);
18 /*
19   Mkstemp work postponed until later -Doug
20 #ifdef HAVE_MKSTEMP
21     mkstemp (tmpfil);
22 #else
23 */
24     mktemp (tmpfil);
25 /*
26 #endif
27 */
28 /* nasty - this really means: if there is no '/' in the path */
29     if ((cp = r1bindex (file, '/')) == file)
30         strncpy (buffer, tmpfil, sizeof(buffer));
31     else
32         snprintf (buffer, sizeof(buffer), "%.*s%s", cp - file, file, tmpfil);
33     unlink (buffer);
34
35     return buffer;
36 }