mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 20:40:05 +00:00
Implement mkstemps and mkstemps64.
This commit is contained in:
parent
471d4931f8
commit
7f3146e789
24
ChangeLog
24
ChangeLog
@ -1,3 +1,27 @@
|
||||
2009-10-30 Ulrich Drepper <drepper@redhat.com>
|
||||
|
||||
[BZ #10349]
|
||||
* sysdeps/posix/tempname.c (__gen_tempname): Take new second
|
||||
parameter, specifying length of prefix.
|
||||
* stdio-common/tempname.c: Likewise.
|
||||
* include/stdio.h: Adjust prototypes.
|
||||
* libio/oldtmpfile.c: Adjust caller.
|
||||
* misc/mkdtemp.c: Likewise.
|
||||
* misc/mkostemp.c: Likewise.
|
||||
* misc/mkostemp64.c: Likewise.
|
||||
* misc/mkstemp.c: Likewise.
|
||||
* misc/mkstemp64.c: Likewise.
|
||||
* misc/mktemp.c: Likewise.
|
||||
* stdio-common/tempnam.c: Likewise.
|
||||
* stdio-common/tmpfile.c: Likewise.
|
||||
* stdio-common/tmpnam.c: Likewise.
|
||||
* stdio-common/tmpnam_r.c: Likewise.
|
||||
* misc/mkstemps.c: New file.
|
||||
* misc/mkstemps64.c: New file.
|
||||
* stdlib/stdlib.h: Add prototypes.
|
||||
* misc/Makefile (routines): Add mkstemps and mkstemps64.
|
||||
* misc/Versions: Export mkstemps and mkstemps64 for GLIBC_2.11.
|
||||
|
||||
2009-10-29 Ulrich Drepper <drepper@redhat.com>
|
||||
|
||||
* locale/iso-639.def: Add sml entry.
|
||||
|
6
NEWS
6
NEWS
@ -1,4 +1,4 @@
|
||||
GNU C Library NEWS -- history of user-visible changes. 2009-10-15
|
||||
GNU C Library NEWS -- history of user-visible changes. 2009-10-29
|
||||
Copyright (C) 1992-2008, 2009 Free Software Foundation, Inc.
|
||||
See the end for copying conditions.
|
||||
|
||||
@ -7,7 +7,7 @@ using `glibc' in the "product" field.
|
||||
|
||||
Version 2.11
|
||||
|
||||
* New interfaces: execvpe, pthread_sigqueue
|
||||
* New interfaces: execvpe, pthread_sigqueue, mkstemps, mkstemps64
|
||||
Implemented by Ulrich Drepper.
|
||||
|
||||
* Checking version of longjmp added that fails if an uninitialized stack
|
||||
@ -18,7 +18,7 @@ Version 2.11
|
||||
|
||||
* New optimized string functions for x86-64: strstr, strcasestr, memcmp,
|
||||
strcspn, strpbrk, strspn, strcpy, stpcpy, strncpy, strcmp (SSE2, SSE4.2),
|
||||
strncmp (SSE2, SSE4.2).
|
||||
strncmp (SSE2, SSE4.2), strchr (SSE4.2), strrchr (SSE4.2).
|
||||
Contributed by H.J. Lu.
|
||||
|
||||
strlen, rawmemchr, strcmp (SSSE3), strncmp (SSSE3).
|
||||
|
@ -80,7 +80,8 @@ extern int __path_search (char *__tmpl, size_t __tmpl_len,
|
||||
__const char *__dir, __const char *__pfx,
|
||||
int __try_tempdir);
|
||||
|
||||
extern int __gen_tempname (char *__tmpl, int __flags, int __kind);
|
||||
extern int __gen_tempname (char *__tmpl, int __suffixlen, int __flags,
|
||||
int __kind);
|
||||
/* The __kind argument to __gen_tempname may be one of: */
|
||||
# define __GT_FILE 0 /* create a file */
|
||||
# define __GT_DIR 1 /* create a directory */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1991,1993,1996-2000,2003,2004,2007
|
||||
/* Copyright (C) 1991,1993,1996-2000,2003,2004,2007,2009
|
||||
Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
@ -39,7 +39,7 @@ __old_tmpfile (void)
|
||||
|
||||
if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
|
||||
return NULL;
|
||||
fd = __gen_tempname (buf, 0, __GT_FILE);
|
||||
fd = __gen_tempname (buf, 0, 0, __GT_FILE);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
|
@ -45,7 +45,7 @@ routines := brk sbrk sstk ioctl \
|
||||
gethostid sethostid \
|
||||
revoke vhangup \
|
||||
swapon swapoff mktemp mkstemp mkstemp64 mkdtemp \
|
||||
mkostemp mkostemp64 \
|
||||
mkostemp mkostemp64 mkstemps mkstemps64 \
|
||||
ualarm usleep \
|
||||
gtty stty \
|
||||
ptrace \
|
||||
|
@ -140,4 +140,7 @@ libc {
|
||||
GLIBC_2.10 {
|
||||
preadv; preadv64; pwritev; pwritev64;
|
||||
}
|
||||
GLIBC_2.11 {
|
||||
mkstemps; mkstemps64;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1999, 2007 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1999, 2007, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -28,7 +28,7 @@ char *
|
||||
mkdtemp (template)
|
||||
char *template;
|
||||
{
|
||||
if (__gen_tempname (template, 0, __GT_DIR))
|
||||
if (__gen_tempname (template, 0, 0, __GT_DIR))
|
||||
return NULL;
|
||||
else
|
||||
return template;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1998, 1999, 2001, 2007 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1998, 1999, 2001, 2007, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -32,5 +32,5 @@ mkostemp (template, flags)
|
||||
char *template;
|
||||
int flags;
|
||||
{
|
||||
return __gen_tempname (template, flags, __GT_FILE);
|
||||
return __gen_tempname (template, 0, flags, __GT_FILE);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2000, 2007 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2000, 2007, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -29,5 +29,5 @@ mkostemp64 (template, flags)
|
||||
char *template;
|
||||
int flags;
|
||||
{
|
||||
return __gen_tempname (template, flags | O_LARGEFILE, __GT_FILE);
|
||||
return __gen_tempname (template, 0, flags | O_LARGEFILE, __GT_FILE);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1998, 1999, 2001, 2007 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1998, 1999, 2001, 2007, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -31,5 +31,5 @@ int
|
||||
mkstemp (template)
|
||||
char *template;
|
||||
{
|
||||
return __gen_tempname (template, 0, __GT_FILE);
|
||||
return __gen_tempname (template, 0, 0, __GT_FILE);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2000, 2007 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 2000, 2007, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -28,5 +28,5 @@ int
|
||||
mkstemp64 (template)
|
||||
char *template;
|
||||
{
|
||||
return __gen_tempname (template, O_LARGEFILE, __GT_FILE);
|
||||
return __gen_tempname (template, 0, O_LARGEFILE, __GT_FILE);
|
||||
}
|
||||
|
43
misc/mkstemps.c
Normal file
43
misc/mkstemps.c
Normal file
@ -0,0 +1,43 @@
|
||||
/* Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef __GT_FILE
|
||||
# define __GT_FILE 0
|
||||
#endif
|
||||
|
||||
/* Generate a unique temporary file name from TEMPLATE. The last six
|
||||
characters before a suffix of length SUFFIXLEN of TEMPLATE must be
|
||||
"XXXXXX"; they are replaced with a string that makes the filename
|
||||
unique. Then open the file and return a fd. */
|
||||
int
|
||||
mkstemps (template, suffixlen)
|
||||
char *template;
|
||||
int suffixlen;
|
||||
{
|
||||
if (suffixlen < 0)
|
||||
{
|
||||
__set_errno (EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return __gen_tempname (template, suffixlen, 0, __GT_FILE);
|
||||
}
|
40
misc/mkstemps64.c
Normal file
40
misc/mkstemps64.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* Copyright (C) 2000, 2007, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Generate a unique temporary file name from TEMPLATE. The last six
|
||||
characters before a suffix of length SUFFIXLEN of TEMPLATE must be
|
||||
"XXXXXX"; they are replaced with a string that makes the filename
|
||||
unique. Then open the file and return a fd. */
|
||||
int
|
||||
mkstemps64 (template, suffixlen)
|
||||
char *template;
|
||||
int suffixlen;
|
||||
{
|
||||
if (suffixlen < 0)
|
||||
{
|
||||
__set_errno (EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return __gen_tempname (template, suffixlen, O_LARGEFILE, __GT_FILE);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1998, 1999, 2000, 2007 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1998, 1999, 2000, 2007, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -26,7 +26,7 @@ char *
|
||||
mktemp (template)
|
||||
char *template;
|
||||
{
|
||||
if (__gen_tempname (template, 0, __GT_NOCREATE) < 0)
|
||||
if (__gen_tempname (template, 0, 0, __GT_NOCREATE) < 0)
|
||||
/* We return the null string if we can't find a unique file name. */
|
||||
template[0] = '\0';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1991,1993,1996-2000,2007 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991,1993,1996-2000,2007,2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -34,7 +34,7 @@ tempnam (const char *dir, const char *pfx)
|
||||
if (__path_search (buf, FILENAME_MAX, dir, pfx, 1))
|
||||
return NULL;
|
||||
|
||||
if (__gen_tempname (buf, 0, __GT_NOCREATE))
|
||||
if (__gen_tempname (buf, 0, 0, __GT_NOCREATE))
|
||||
return NULL;
|
||||
|
||||
return __strdup (buf);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1991, 92, 93, 95-98, 99, 2007 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991, 92, 93, 95-99, 2007, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -47,8 +47,9 @@ stub_warning (__path_search)
|
||||
*/
|
||||
|
||||
int
|
||||
__gen_tempname (tmpl, flags, kind)
|
||||
__gen_tempname (tmpl, suffixlen, flags, kind)
|
||||
char *tmpl;
|
||||
int suffixlen;
|
||||
int flags;
|
||||
int kind;
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Open a stdio stream on an anonymous temporary file. Generic/POSIX version.
|
||||
Copyright (C) 1991,1993,1996-2000,2002,2003,2007
|
||||
Copyright (C) 1991,1993,1996-2000,2002,2003,2007,2009
|
||||
Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
@ -48,7 +48,7 @@ tmpfile (void)
|
||||
#ifdef FLAGS
|
||||
flags = FLAGS;
|
||||
#endif
|
||||
fd = __gen_tempname (buf, flags, __GT_FILE);
|
||||
fd = __gen_tempname (buf, 0, flags, __GT_FILE);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1991,1993,1996-1999,2000,2007 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991,1993,1996-2000,2007,2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -39,7 +39,7 @@ tmpnam (char *s)
|
||||
0))
|
||||
return NULL;
|
||||
|
||||
if (__builtin_expect (__gen_tempname (tmpbuf, 0, __GT_NOCREATE), 0))
|
||||
if (__builtin_expect (__gen_tempname (tmpbuf, 0, 0, __GT_NOCREATE), 0))
|
||||
return NULL;
|
||||
|
||||
if (s == NULL)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1991,1993,1996-1999,2000,2007 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991,1993,1996-2000,2007,2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -28,7 +28,7 @@ tmpnam_r (char *s)
|
||||
|
||||
if (__path_search (s, L_tmpnam, NULL, NULL, 0))
|
||||
return NULL;
|
||||
if (__gen_tempname (s, 0, __GT_NOCREATE))
|
||||
if (__gen_tempname (s, 0, 0, __GT_NOCREATE))
|
||||
return NULL;
|
||||
|
||||
return s;
|
||||
|
@ -609,7 +609,7 @@ extern char *mktemp (char *__template) __THROW __nonnull ((1)) __wur;
|
||||
Returns a file descriptor open on the file for reading and writing,
|
||||
or -1 if it cannot create a uniquely-named file.
|
||||
|
||||
This function is a possible cancellation points and therefore not
|
||||
This function is a possible cancellation point and therefore not
|
||||
marked with __THROW. */
|
||||
# ifndef __USE_FILE_OFFSET64
|
||||
extern int mkstemp (char *__template) __nonnull ((1)) __wur;
|
||||
@ -626,6 +626,29 @@ extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __USE_MISC
|
||||
/* Similar to mkstemp, but the template can have a suffix after the
|
||||
XXXXXX. The length of the suffix is specified in the second
|
||||
parameter.
|
||||
|
||||
This function is a possible cancellation point and therefore not
|
||||
marked with __THROW. */
|
||||
# ifndef __USE_FILE_OFFSET64
|
||||
extern int mkstemps (char *__template, int __suffixlen) __nonnull ((1)) __wur;
|
||||
# else
|
||||
# ifdef __REDIRECT
|
||||
extern int __REDIRECT (mkstemps, (char *__template, int __suffixlen),
|
||||
mkstemps64) __nonnull ((1)) __wur;
|
||||
# else
|
||||
# define mkstemps mkstemps64
|
||||
# endif
|
||||
# endif
|
||||
# ifdef __USE_LARGEFILE64
|
||||
extern int mkstemps64 (char *__template, int __suffixlen)
|
||||
__nonnull ((1)) __wur;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined __USE_BSD || defined __USE_XOPEN2K8
|
||||
/* Create a unique temporary directory from TEMPLATE.
|
||||
The last six characters of TEMPLATE must be "XXXXXX";
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1991-2001, 2006, 2007 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991-2001, 2006, 2007, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -210,9 +210,9 @@ static const char letters[] =
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
|
||||
/* 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.
|
||||
rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
|
||||
The name constructed does not exist at the time of the call to
|
||||
__gen_tempname. TMPL is overwritten with the result.
|
||||
|
||||
KIND may be one of:
|
||||
__GT_NOCREATE: simply verify that the name does not exist
|
||||
@ -223,7 +223,7 @@ static const char letters[] =
|
||||
|
||||
We use a clever algorithm to get hard-to-predict names. */
|
||||
int
|
||||
__gen_tempname (char *tmpl, int flags, int kind)
|
||||
__gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
|
||||
{
|
||||
int len;
|
||||
char *XXXXXX;
|
||||
@ -251,14 +251,14 @@ __gen_tempname (char *tmpl, int flags, int kind)
|
||||
#endif
|
||||
|
||||
len = strlen (tmpl);
|
||||
if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
|
||||
if (len < 6 + suffixlen || memcmp (&tmpl[len - 6 - suffixlen], "XXXXXX", 6))
|
||||
{
|
||||
__set_errno (EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* This is where the Xs start. */
|
||||
XXXXXX = &tmpl[len - 6];
|
||||
XXXXXX = &tmpl[len - 6 - suffixlen];
|
||||
|
||||
/* Get some more or less random data. */
|
||||
#ifdef RANDOM_BITS
|
||||
|
Loading…
Reference in New Issue
Block a user