diff options
author | Ulrich Drepper <drepper@redhat.com> | 1999-07-06 16:26:03 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1999-07-06 16:26:03 +0000 |
commit | 2e65ca2b226a55e7d25ef687ce33185c0a71bd99 (patch) | |
tree | 0b76ef817b2b4977374fe025016e80fcd2e4f3ff /sysdeps/posix | |
parent | 4708015f24a69bd0a436483c4d1244d1fb1f2e87 (diff) | |
download | glibc-2e65ca2b226a55e7d25ef687ce33185c0a71bd99.tar.gz glibc-2e65ca2b226a55e7d25ef687ce33185c0a71bd99.tar.xz glibc-2e65ca2b226a55e7d25ef687ce33185c0a71bd99.zip |
Update.
1999-07-06 Ulrich Drepper <drepper@cygnus.com> * sysdeps/unix/sysv/linux/alpha/ioperm.c: Update for some more motherboards. Patch by Jay Estabrook. * sysdeps/unix/sysv/linux/configure.in: Don't test for libc4 in ldd for SPARC. * /sysdeps/unix/sysv/linux/sparc/ldd-rewrite.sed: New file. Patch by Cristian Gafton. 1999-07-02 Cristian Gafton <gafton@redhat.com> * sysdeps/unix/sysv/linux/bits/socket.h (__cmsg_nxthdr): "return 0" instead of "return NULL" to make C++ happy. 1999-07-04 Mark Kettenis <kettenis@gnu.org> * libio/iofdopen.c (_IO_new_fdopen): Set EINVAL if MODE is not allowed by the file access mode of the open file. 1999-07-06 Ulrich Drepper <drepper@cygnus.com> * sysdeps/generic/setfpucw.c: Include math.h to get all needed macros defined. 1999-07-03 Jakub Jelinek <jj@ultra.linux.cz> * sysdeps/sparc/sparc64/submul_1.S: Fix carry handling. Optimize. * sysdeps/sparc/sparc64/lshift.S: Make a leaf subroutine. Optimize. * sysdeps/sparc/sparc64/rshift.S: Likewise. * sysdeps/sparc/sparc64/mul_1.S: Optimize. 1999-07-04 Wolfram Gloger <wmglo@dent.med.uni-muenchen.de> * malloc/malloc.c (request2size): Check for overflow and return NULL whenever it is encountered. 1999-07-04 Zack Weinberg <zack@rabi.columbia.edu> * sysdeps/posix/tempname.c (__gen_tempname): Add ability to create directories. Replace OPENIT and LARGEFILE args with a single flags parameter. * sysdeps/generic/tempname.c: Likewise. * include/stdio.h: Adjust prototype of __gen_tempname to match. Define symbolic constants for second argument. * misc/mkdtemp.c: New file, provides new function mkdtemp(). * stdlib/stdlib.h: Prototype it. * misc/Versions: Export it. * misc/Makefile (routines): Add mktemp. * manual/filesys.texi: Document it. * misc/mktemp.c: Adjust call of __gen_tempname to match new convention. * misc/mkstemp.c: Likewise. * stdio-common/tempnam.c: Likewise. * stdio-common/tmpfile.c: Likewise. * stdio-common/tmpfile64.c: Likewise. * stdio-common/tmpnam.c: Likewise. * stdio-common/tmpnam_r.c: Likewise. 1999-07-05 Jakub Jelinek <jj@ultra.linux.cz> * sysdeps/sparc/sparc64/dl-machine.h (elf_machine_rela): Support R_SPARC_OLO10 relocations. * elf/elf.h (R_SPARC_OLO10): Fix comment.
Diffstat (limited to 'sysdeps/posix')
-rw-r--r-- | sysdeps/posix/tempname.c | 65 |
1 files changed, 43 insertions, 22 deletions
diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c index 7689bb01e3..536225e957 100644 --- a/sysdeps/posix/tempname.c +++ b/sysdeps/posix/tempname.c @@ -27,6 +27,7 @@ #include <fcntl.h> #include <unistd.h> #include <sys/time.h> +#include <assert.h> /* Return nonzero if DIR is an existent directory. */ static int @@ -106,20 +107,27 @@ static const char letters[] = /* Generate a temporary file name based on TMPL. TMPL must match the rules for mk[s]temp (i.e. end in "XXXXXX"). The name constructed does not exist at the time of the call to __gen_tempname. TMPL is - overwritten with the result. If OPENIT is nonzero, creates the - file and returns a read-write fd; the file is mode 0600 modulo - umask. If LARGEFILE is nonzero, uses open64() instead of open(). + overwritten with the result. + + KIND may be one of: + __GT_NOCREATE: simply verify that the name does not exist + at the time of the call. + __GT_FILE: create the file using open(O_CREAT|O_EXCL) + and return a read-write fd. The file is mode 0600. + __GT_BIGFILE: same as __GT_FILE but use open64(). + __GT_DIR: create a directory, which will be mode 0700. We use a clever algorithm to get hard-to-predict names. */ int -__gen_tempname (char *tmpl, int openit, int largefile) +__gen_tempname (char *tmpl, int kind) { int len; char *XXXXXX; static uint64_t value; struct timeval tv; - int count, fd; + int count, fd = -1; int save_errno = errno; + struct stat st; len = strlen (tmpl); if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX")) @@ -152,24 +160,25 @@ __gen_tempname (char *tmpl, int openit, int largefile) v /= 62; XXXXXX[5] = letters[v % 62]; - if (openit) - { - fd = (largefile - ? __open (tmpl, O_RDWR | O_CREAT | O_EXCL, 0600) - : __open64 (tmpl, O_RDWR | O_CREAT | O_EXCL, 0600)); - if (fd >= 0) - { - __set_errno (save_errno); - return fd; - } - else if (errno != EEXIST) - /* Any other error will apply also to other names we might - try, and there are 2^32 or so of them, so give up now. */ - return -1; - } - else + switch (kind) { - struct stat st; + case __GT_FILE: + fd = __open (tmpl, O_RDWR | O_CREAT | O_EXCL, 0600); + break; + + case __GT_BIGFILE: + fd = __open64 (tmpl, O_RDWR | O_CREAT | O_EXCL, 0600); + break; + + case __GT_DIR: + fd = __mkdir (tmpl, 0700); + break; + + case __GT_NOCREATE: + /* This case is backward from the other three. __gen_tempname + succeeds if __xstat fails because the name does not exist. + Note the continue to bypass the common logic at the bottom + of the loop. */ if (__xstat (_STAT_VER, tmpl, &st) < 0) { if (errno == ENOENT) @@ -181,7 +190,19 @@ __gen_tempname (char *tmpl, int openit, int largefile) /* Give up now. */ return -1; } + continue; + + default: + assert (! "invalid KIND in __gen_tempname"); + } + + if (fd >= 0) + { + __set_errno (save_errno); + return fd; } + else if (errno != EEXIST) + return -1; } /* We got out of the loop because we ran out of combinations to try. */ |