X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ftmpfile.c;h=f01de3a419fae42d75f92fa62add17fbde4836fd;hb=5f1cfee9e825db39e75bc2388856fb274d395e20;hp=e8c4418cd288ede86268bb48a6e83e2a9314117c;hpb=8c0f3c676c064ef15324eecd9c9892f1d07134db;p=gnulib.git diff --git a/lib/tmpfile.c b/lib/tmpfile.c index e8c4418cd..f01de3a41 100644 --- a/lib/tmpfile.c +++ b/lib/tmpfile.c @@ -1,10 +1,10 @@ /* Create a temporary file. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -12,8 +12,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ /* Written by Ben Pfaff. */ @@ -53,9 +52,9 @@ supports_delete_on_close () OSVERSIONINFO v; if (GetVersionEx (&v)) - known = (v.dwPlatformId == VER_PLATFORM_WIN32_NT ? 1 : -1); + known = (v.dwPlatformId == VER_PLATFORM_WIN32_NT ? 1 : -1); else - known = -1; + known = -1; } return (known > 0); } @@ -76,49 +75,49 @@ tmpfile (void) char xtemplate[PATH_MAX]; if (path_search (xtemplate, PATH_MAX, dir, NULL, true) >= 0) - { - size_t len = strlen (xtemplate); - int o_temporary = (supports_delete_on_close () ? _O_TEMPORARY : 0); - int fd; - - do - { - memcpy (&xtemplate[len - 6], "XXXXXX", 6); - if (gen_tempname (xtemplate, GT_NOCREATE) < 0) - { - fd = -1; - break; - } - - fd = _open (xtemplate, - _O_CREAT | _O_EXCL | o_temporary - | _O_RDWR | _O_BINARY, - _S_IREAD | _S_IWRITE); - } - while (fd < 0 && errno == EEXIST); - - if (fd >= 0) - { - FILE *fp = _fdopen (fd, "w+b"); - - if (fp != NULL) - return fp; - else - { - int saved_errno = errno; - _close (fd); - errno = saved_errno; - } - } - } + { + size_t len = strlen (xtemplate); + int o_temporary = (supports_delete_on_close () ? _O_TEMPORARY : 0); + int fd; + + do + { + memcpy (&xtemplate[len - 6], "XXXXXX", 6); + if (gen_tempname (xtemplate, 0, 0, GT_NOCREATE) < 0) + { + fd = -1; + break; + } + + fd = _open (xtemplate, + _O_CREAT | _O_EXCL | o_temporary + | _O_RDWR | _O_BINARY, + _S_IREAD | _S_IWRITE); + } + while (fd < 0 && errno == EEXIST); + + if (fd >= 0) + { + FILE *fp = _fdopen (fd, "w+b"); + + if (fp != NULL) + return fp; + else + { + int saved_errno = errno; + _close (fd); + errno = saved_errno; + } + } + } } else { if (retval > 0) - errno = ENAMETOOLONG; + errno = ENAMETOOLONG; else - /* Ideally this should translate GetLastError () to an errno value. */ - errno = ENOENT; + /* Ideally this should translate GetLastError () to an errno value. */ + errno = ENOENT; } return NULL;