diff options
author | Romain Naour <romain.naour@openwide.fr> | 2015-08-01 18:31:06 +0200 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2015-08-14 23:29:22 +0200 |
commit | 6cf35f84045f38f067365623886fecff16ca92f9 (patch) | |
tree | 5c7788b303ed40482562d4e00d12363999500614 /libc/stdlib | |
parent | 8cde3a9bf2856dcb9a759dec7ecb04a68e712254 (diff) |
add mkstemps, mkstemps64 and mkostemps, mkostemps64 functions
Change __gen_tempname() prototype in order to pass the additional
suffix lenght. In __gen_tempname() add a new check for suffixlen.
Update some comments in the code.
Signed-off-by: Romain Naour <romain.naour@openwide.fr>
Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
Diffstat (limited to 'libc/stdlib')
-rw-r--r-- | libc/stdlib/Makefile.in | 6 | ||||
-rw-r--r-- | libc/stdlib/mkdtemp.c | 2 | ||||
-rw-r--r-- | libc/stdlib/mkostemp.c | 2 | ||||
-rw-r--r-- | libc/stdlib/mkostemp64.c | 3 | ||||
-rw-r--r-- | libc/stdlib/mkostemps.c | 36 | ||||
-rw-r--r-- | libc/stdlib/mkostemps64.c | 34 | ||||
-rw-r--r-- | libc/stdlib/mkstemp.c | 2 | ||||
-rw-r--r-- | libc/stdlib/mkstemp64.c | 2 | ||||
-rw-r--r-- | libc/stdlib/mkstemps.c | 33 | ||||
-rw-r--r-- | libc/stdlib/mkstemps64.c | 33 | ||||
-rw-r--r-- | libc/stdlib/mktemp.c | 2 |
11 files changed, 146 insertions, 9 deletions
diff --git a/libc/stdlib/Makefile.in b/libc/stdlib/Makefile.in index 071f91119..ae74995bb 100644 --- a/libc/stdlib/Makefile.in +++ b/libc/stdlib/Makefile.in @@ -13,8 +13,8 @@ include $(top_srcdir)libc/stdlib/malloc-standard/Makefile.in CSRC-y := \ abort.c getenv.c mkdtemp.c realpath.c canonicalize.c mkstemp.c mkostemp.c \ - rand.c random.c random_r.c setenv.c div.c ldiv.c lldiv.c \ - getpt.c drand48-iter.c jrand48.c \ + mkstemps.c mkostemps.c rand.c random.c random_r.c setenv.c div.c ldiv.c \ + lldiv.c getpt.c drand48-iter.c jrand48.c \ jrand48_r.c lcong48.c lrand48.c lrand48_r.c mrand48.c mrand48_r.c nrand48.c \ nrand48_r.c rand_r.c srand48.c srand48_r.c seed48.c seed48_r.c \ a64l.c l64a.c __uc_malloc.c @@ -22,7 +22,7 @@ CSRC-$(UCLIBC_SUSV2_LEGACY) += valloc.c CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_memalign.c CSRC-$(UCLIBC_HAS_PTY) += grantpt.c unlockpt.c ptsname.c CSRC-$(UCLIBC_HAS_ARC4RANDOM) += arc4random.c -CSRC-$(UCLIBC_HAS_LFS) += mkstemp64.c mkostemp64.c +CSRC-$(UCLIBC_HAS_LFS) += mkstemp64.c mkostemp64.c mkstemps64.c mkostemps64.c CSRC-$(UCLIBC_HAS_FLOATS) += drand48.c drand48_r.c erand48.c erand48_r.c CSRC-$(if $(findstring yy,$(UCLIBC_HAS_FLOATS)$(UCLIBC_SUSV3_LEGACY)),y) += \ gcvt.c diff --git a/libc/stdlib/mkdtemp.c b/libc/stdlib/mkdtemp.c index e6d4a364c..185e206a3 100644 --- a/libc/stdlib/mkdtemp.c +++ b/libc/stdlib/mkdtemp.c @@ -29,7 +29,7 @@ (This function comes from OpenBSD.) */ char * mkdtemp (char *template) { - if (__gen_tempname (template, __GT_DIR, 0, S_IRUSR | S_IWUSR | S_IXUSR)) + if (__gen_tempname (template, __GT_DIR, 0, 0, S_IRUSR | S_IWUSR | S_IXUSR)) return NULL; else return template; diff --git a/libc/stdlib/mkostemp.c b/libc/stdlib/mkostemp.c index 912be30a6..4eab0797a 100644 --- a/libc/stdlib/mkostemp.c +++ b/libc/stdlib/mkostemp.c @@ -28,5 +28,5 @@ int mkostemp (char *template, int flags) { flags -= flags & O_ACCMODE; /* Remove O_RDONLY, O_WRONLY, and O_RDWR. */ - return __gen_tempname (template, __GT_FILE, flags, S_IRUSR | S_IWUSR); + return __gen_tempname (template, __GT_FILE, flags, 0, S_IRUSR | S_IWUSR); } diff --git a/libc/stdlib/mkostemp64.c b/libc/stdlib/mkostemp64.c index c6d6d849d..25595ad96 100644 --- a/libc/stdlib/mkostemp64.c +++ b/libc/stdlib/mkostemp64.c @@ -27,5 +27,6 @@ int mkostemp64 (char *template, int flags) { - return __gen_tempname (template, __GT_BIGFILE, flags | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IXUSR); + return __gen_tempname (template, __GT_BIGFILE, flags | O_LARGEFILE, 0, + S_IRUSR | S_IWUSR | S_IXUSR); } diff --git a/libc/stdlib/mkostemps.c b/libc/stdlib/mkostemps.c new file mode 100644 index 000000000..13a517185 --- /dev/null +++ b/libc/stdlib/mkostemps.c @@ -0,0 +1,36 @@ +/* Copyright (C) 1998-2012 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, see + <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include "../misc/internals/tempname.h" + +/* Generate a unique temporary file name from TEMPLATE. + The TEMPLATE is of the form "XXXXXXsuffix" where six characters + after the TEMPLATE must be "XXXXXX" followed by the suffix. + The suffix length must be specified with suffixlen. + "XXXXXX" are replaced with a string that makes the filename unique. + Then open the file and return a fd. */ +int mkostemps (char *template, int suffixlen, int flags) +{ + flags -= flags & O_ACCMODE; /* Remove O_RDONLY, O_WRONLY, and O_RDWR. */ + return __gen_tempname (template, __GT_FILE, flags, suffixlen, + S_IRUSR | S_IWUSR); +} + + diff --git a/libc/stdlib/mkostemps64.c b/libc/stdlib/mkostemps64.c new file mode 100644 index 000000000..0436fcf81 --- /dev/null +++ b/libc/stdlib/mkostemps64.c @@ -0,0 +1,34 @@ +/* Copyright (C) 1998-2012 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, see + <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include "../misc/internals/tempname.h" + +/* Generate a unique temporary file name from TEMPLATE. + The TEMPLATE is of the form "XXXXXXsuffix" where six characters + after the TEMPLATE must be "XXXXXX" followed by the suffix. + The suffix length must be specified with suffixlen. + "XXXXXX" are replaced with a string that makes the filename unique. + Then open the file and return a fd. */ +int mkostemps64 (char *template, int suffixlen, int flags) +{ + flags -= flags & O_ACCMODE; /* Remove O_RDONLY, O_WRONLY, and O_RDWR. */ + return __gen_tempname (template, __GT_FILE, flags, suffixlen, + S_IRUSR | S_IWUSR); +} diff --git a/libc/stdlib/mkstemp.c b/libc/stdlib/mkstemp.c index a3a159590..abcc93e62 100644 --- a/libc/stdlib/mkstemp.c +++ b/libc/stdlib/mkstemp.c @@ -26,5 +26,5 @@ Then open the file and return a fd. */ int mkstemp (char *template) { - return __gen_tempname (template, __GT_FILE, 0, S_IRUSR | S_IWUSR); + return __gen_tempname (template, __GT_FILE, 0, 0, S_IRUSR | S_IWUSR); } diff --git a/libc/stdlib/mkstemp64.c b/libc/stdlib/mkstemp64.c index 6f2ee3e83..82c6da531 100644 --- a/libc/stdlib/mkstemp64.c +++ b/libc/stdlib/mkstemp64.c @@ -26,5 +26,5 @@ Then open the file and return a fd. */ int mkstemp64 (char *template) { - return __gen_tempname (template, __GT_BIGFILE, 0, S_IRUSR | S_IWUSR); + return __gen_tempname (template, __GT_BIGFILE, 0, 0, S_IRUSR | S_IWUSR); } diff --git a/libc/stdlib/mkstemps.c b/libc/stdlib/mkstemps.c new file mode 100644 index 000000000..22aebf4ba --- /dev/null +++ b/libc/stdlib/mkstemps.c @@ -0,0 +1,33 @@ +/* Copyright (C) 1998-2012 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, see + <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> +#include "../misc/internals/tempname.h" + +/* Generate a unique temporary file name from TEMPLATE. + The TEMPLATE is of the form "XXXXXXsuffix" where six characters + after the TEMPLATE must be "XXXXXX" followed by the suffix. + The suffix length must be specified with suffixlen. + "XXXXXX" are replaced with a string that makes the filename unique. + Then open the file and return a fd. */ +int mkstemps (char *template, int suffixlen) +{ + return __gen_tempname (template, __GT_FILE, 0, suffixlen, + S_IRUSR | S_IWUSR); +} diff --git a/libc/stdlib/mkstemps64.c b/libc/stdlib/mkstemps64.c new file mode 100644 index 000000000..19fb4c861 --- /dev/null +++ b/libc/stdlib/mkstemps64.c @@ -0,0 +1,33 @@ +/* Copyright (C) 1998-2012 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, see + <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> +#include "../misc/internals/tempname.h" + +/* Generate a unique temporary file name from TEMPLATE. + The TEMPLATE is of the form "XXXXXXsuffix" where six characters + after the TEMPLATE must be "XXXXXX" followed by the suffix. + The suffix length must be specified with suffixlen. + "XXXXXX" are replaced with a string that makes the filename unique. + Then open the file and return a fd. */ +int mkstemps64 (char *template, int suffixlen) +{ + return __gen_tempname (template, __GT_BIGFILE, 0, suffixlen, + S_IRUSR | S_IWUSR); +} diff --git a/libc/stdlib/mktemp.c b/libc/stdlib/mktemp.c index 403596645..be8815358 100644 --- a/libc/stdlib/mktemp.c +++ b/libc/stdlib/mktemp.c @@ -24,7 +24,7 @@ * they are replaced with a string that makes the filename unique. */ char *mktemp(char *template) { - if (__gen_tempname (template, __GT_NOCREATE, 0, 0) < 0) + if (__gen_tempname (template, __GT_NOCREATE, 0,0, 0) < 0) /* We return the null string if we can't find a unique file name. */ template[0] = '\0'; |