diff options
Diffstat (limited to 'stdio-common/tmpfile.c')
-rw-r--r-- | stdio-common/tmpfile.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/stdio-common/tmpfile.c b/stdio-common/tmpfile.c index e6030be0af..c5cbb688f4 100644 --- a/stdio-common/tmpfile.c +++ b/stdio-common/tmpfile.c @@ -34,23 +34,31 @@ FILE * tmpfile (void) { - char buf[FILENAME_MAX]; int fd; FILE *f; - - if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0)) - return NULL; int flags = 0; #ifdef FLAGS flags = FLAGS; #endif - fd = __gen_tempname (buf, 0, flags, __GT_FILE); + + /* First try a system specific method. */ + fd = __gen_tempfd (flags); + if (fd < 0) - return NULL; + { + char buf[FILENAME_MAX]; + + if (__path_search (buf, sizeof buf, NULL, "tmpf", 0)) + return NULL; + + fd = __gen_tempname (buf, 0, flags, __GT_FILE); + if (fd < 0) + return NULL; - /* Note that this relies on the Unix semantics that - a file is not really removed until it is closed. */ - (void) __unlink (buf); + /* Note that this relies on the Unix semantics that + a file is not really removed until it is closed. */ + (void) __unlink (buf); + } if ((f = __fdopen (fd, "w+b")) == NULL) __close (fd); |