Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: fusl/src/stdio/tempnam.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/src/stdio/swscanf.c ('k') | fusl/src/stdio/tmpfile.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <errno.h>
4 #include <sys/stat.h>
5 #include <limits.h>
6 #include <string.h>
7 #include "syscall.h"
8
9 #define MAXTRIES 100
10
11 char *__randname(char *);
12
13 char *tempnam(const char *dir, const char *pfx)
14 {
15 char s[PATH_MAX];
16 size_t l, dl, pl;
17 int try;
18 int r;
19
20 if (!dir) dir = P_tmpdir;
21 if (!pfx) pfx = "temp";
22
23 dl = strlen(dir);
24 pl = strlen(pfx);
25 l = dl + 1 + pl + 1 + 6;
26
27 if (l >= PATH_MAX) {
28 errno = ENAMETOOLONG;
29 return 0;
30 }
31
32 memcpy(s, dir, dl);
33 s[dl] = '/';
34 memcpy(s+dl+1, pfx, pl);
35 s[dl+1+pl] = '_';
36 s[l] = 0;
37
38 for (try=0; try<MAXTRIES; try++) {
39 __randname(s+l-6);
40 #ifdef SYS_lstat
41 r = __syscall(SYS_lstat, s, &(struct stat){0});
42 #else
43 r = __syscall(SYS_fstatat, AT_FDCWD, s,
44 &(struct stat){0}, AT_SYMLINK_NOFOLLOW);
45 #endif
46 if (r == -ENOENT) return strdup(s);
47 }
48 return 0;
49 }
OLDNEW
« no previous file with comments | « fusl/src/stdio/swscanf.c ('k') | fusl/src/stdio/tmpfile.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698