• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <errno.h>
4 #include <sys/stat.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include <unsupported_api.h>
8 
9 #include "syscall.h"
10 #include "kstat.h"
11 
12 #define MAXTRIES 100
13 
tmpnam(char * buf)14 char *tmpnam(char *buf)
15 {
16 	static char internal[L_tmpnam];
17 	char s[] = "/tmp/tmpnam_XXXXXX";
18 	int try;
19 	int r;
20 	unsupported_api(__FUNCTION__);
21 	for (try=0; try<MAXTRIES; try++) {
22 		__randname(s+12);
23 #ifdef SYS_lstat
24 		r = __syscall(SYS_lstat, s, &(struct kstat){0});
25 #else
26 		r = __syscall(SYS_fstatat, AT_FDCWD, s,
27 			&(struct kstat){0}, AT_SYMLINK_NOFOLLOW);
28 #endif
29 		if (r == -ENOENT) return strcpy(buf ? buf : internal, s);
30 	}
31 	return 0;
32 }
33