diff options
author | Mike Frysinger <vapier@gentoo.org> | 2012-11-14 00:30:54 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2012-11-14 00:31:15 -0500 |
commit | 42d1b23fc0f3748b8bf474e456d6c44aa7e563fd (patch) | |
tree | 2e159926ea9cbe018bf2ddaade8e7c0eff90d3c8 /libc/stdlib | |
parent | dbaa240832c159e395e8b3104ecdb551c8f96b5d (diff) |
libc/stdlib: add mkostemp helpers
Some projects (like udev) are starting to use this.
Imported from glibc.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libc/stdlib')
-rw-r--r-- | libc/stdlib/Makefile.in | 4 | ||||
-rw-r--r-- | libc/stdlib/mkostemp.c | 32 | ||||
-rw-r--r-- | libc/stdlib/mkostemp64.c | 33 |
3 files changed, 67 insertions, 2 deletions
diff --git a/libc/stdlib/Makefile.in b/libc/stdlib/Makefile.in index 3166b8e62..b92f7ceeb 100644 --- a/libc/stdlib/Makefile.in +++ b/libc/stdlib/Makefile.in @@ -12,7 +12,7 @@ include $(top_srcdir)libc/stdlib/malloc-simple/Makefile.in include $(top_srcdir)libc/stdlib/malloc-standard/Makefile.in CSRC-y := \ - abort.c getenv.c mkdtemp.c realpath.c canonicalize.c mkstemp.c \ + 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 \ jrand48_r.c lcong48.c lrand48.c lrand48_r.c mrand48.c mrand48_r.c nrand48.c \ @@ -21,7 +21,7 @@ CSRC-y := \ 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 +CSRC-$(UCLIBC_HAS_LFS) += mkstemp64.c mkostemp64.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/mkostemp.c b/libc/stdlib/mkostemp.c new file mode 100644 index 000000000..93b50fc40 --- /dev/null +++ b/libc/stdlib/mkostemp.c @@ -0,0 +1,32 @@ +/* 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 "../misc/internals/tempname.h" + +/* Generate a unique temporary file name from TEMPLATE. + The last six characters 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 +mkostemp (template, flags) + char *template; + int flags; +{ + return __gen_tempname (template, __GT_FILE, flags); +} diff --git a/libc/stdlib/mkostemp64.c b/libc/stdlib/mkostemp64.c new file mode 100644 index 000000000..5509d8c1b --- /dev/null +++ b/libc/stdlib/mkostemp64.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2000-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 <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include "../misc/internals/tempname.h" + +/* Generate a unique temporary file name from TEMPLATE. + The last six characters 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 +mkostemp64 (template, flags) + char *template; + int flags; +{ + return __gen_tempname (template, __GT_BIGFILE, flags | O_LARGEFILE); +} |