31 #include <sys/types.h>
40 #define FILENAME_MAX MAXPATHLEN
42 #define FILENAME_MAX 1024
47 #define P_tmpdir "/usr/tmp/"
55 return stat (dir, &buf) == 0 && S_ISDIR (buf.st_mode);
65 if (
stat (file, &st) == 0)
74 int exists = errno != ENOENT;
83 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
101 int dir_search,
size_t *lenptr,
104 int saverrno = errno;
105 static const char tmpdir[] =
P_tmpdir;
106 static size_t indices[2];
109 static pid_t oldpid = (pid_t) 0;
110 pid_t pid = getpid ();
111 register size_t len, plen, dlen;
115 register const char *
d = getenv (
"TMPDIR");
118 if (d == NULL && dir != NULL &&
diraccess (dir))
137 while (dlen > 1 && dir[dlen - 1] ==
'/')
140 if (pfx != NULL && *pfx !=
'\0')
149 if (dir != tmpdir && !strcmp (dir, tmpdir))
151 idx = &indices[(plen == 0 && dir == tmpdir) ? 1 : 0];
156 indices[0] = indices[1] = 0;
159 len = dlen + 1 + plen + 5 + 3;
169 if (
sizeof (buf) < len)
172 sprintf (buf,
"%.*s/%.*s%.5d%c%c%c",
173 (
int) dlen, dir, (
int) plen,
176 % (
sizeof (letters) - 1)],
177 letters[(*idx / (
sizeof (letters) - 1))
178 % (
sizeof (letters) - 1)],
179 letters[(*idx / ((
sizeof (letters) - 1) *
180 (
sizeof (letters) - 1)))
181 % (
sizeof (letters) - 1)]
184 if (! buf || strlen (buf) != (
int) len)
187 if (streamptr != NULL)