blob: bd68c4c0a043dad17e4f12f8998498a200b2f070 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/* tmpnam.c : return a temporary file name */
/* written by Eric R. Smith and placed in the public domain */
/**
* - modified for gawk needs - pattern /$$XXXXXX from the original
* code creates names which are hard to remove when somethig
* goes wrong
* - retuned name can be passed outside via system(); other programs
* may not dig '/' as a path separator
* - somehow more frugal in a memory use
* (mj - October 1990)
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern char * getenv(const char *);
extern char * mktemp(char *);
extern char * strcpy(char *, const char *);
extern char * strcat(char *, const char *);
extern size_t strlen(const char *s);
static char pattern[] = "\\gwkXXXXX";
char *tmpnam(buf)
char *buf;
{
char *tmpdir;
if (!(tmpdir = getenv("TEMP")) && !(tmpdir = getenv("TMPDIR")))
tmpdir = ".";
if (!buf) {
size_t blen;
blen = strlen (tmpdir) + sizeof(pattern);
if (NULL == (buf = malloc(blen)))
return NULL;
}
(void) strcat(strcpy(buf, tmpdir), pattern);
return(mktemp(buf));
}
/* used by gawk_popen() */
char *tempnam(path, base)
const char *path, *base; /* ignored */
{
return tmpnam(NULL);
}
|