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