1 From 42d1b23fc0f3748b8bf474e456d6c44aa7e563fd Mon Sep 17 00:00:00 2001
2 From: Mike Frysinger <vapier@gentoo.org>
3 Date: Wed, 14 Nov 2012 00:30:54 -0500
4 Subject: [PATCH] libc/stdlib: add mkostemp helpers
6 Some projects (like udev) are starting to use this.
10 Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 include/stdlib.h | 23 +++++++++++++++++++++++
13 libc/stdlib/Makefile.in | 4 ++--
14 libc/stdlib/mkostemp.c | 32 ++++++++++++++++++++++++++++++++
15 libc/stdlib/mkostemp64.c | 33 +++++++++++++++++++++++++++++++++
16 4 files changed, 90 insertions(+), 2 deletions(-)
17 create mode 100644 libc/stdlib/mkostemp.c
18 create mode 100644 libc/stdlib/mkostemp64.c
20 diff --git a/include/stdlib.h b/include/stdlib.h
21 index 354fc66..79ccc55 100644
22 --- a/include/stdlib.h
23 +++ b/include/stdlib.h
24 @@ -652,6 +652,29 @@ extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
25 extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
29 +/* Generate a unique temporary file name from TEMPLATE similar to
30 + mkstemp. But allow the caller to pass additional flags which are
31 + used in the open call to create the file..
33 + This function is a possible cancellation point and therefore not
34 + marked with __THROW. */
35 +# ifndef __USE_FILE_OFFSET64
36 +extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur;
39 +extern int __REDIRECT (mkostemp, (char *__template, int __flags), mkostemp64)
40 + __nonnull ((1)) __wur;
42 +# define mkostemp mkostemp64
45 +# ifdef __USE_LARGEFILE64
46 +extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur;
53 /* Execute the given line as a shell command.
54 diff --git a/libc/stdlib/Makefile.in b/libc/stdlib/Makefile.in
55 index 3166b8e..b92f7ce 100644
56 --- a/libc/stdlib/Makefile.in
57 +++ b/libc/stdlib/Makefile.in
58 @@ -12,7 +12,7 @@ include $(top_srcdir)libc/stdlib/malloc-simple/Makefile.in
59 include $(top_srcdir)libc/stdlib/malloc-standard/Makefile.in
62 - abort.c getenv.c mkdtemp.c realpath.c canonicalize.c mkstemp.c \
63 + abort.c getenv.c mkdtemp.c realpath.c canonicalize.c mkstemp.c mkostemp.c \
64 rand.c random.c random_r.c setenv.c div.c ldiv.c lldiv.c \
65 getpt.c drand48-iter.c jrand48.c \
66 jrand48_r.c lcong48.c lrand48.c lrand48_r.c mrand48.c mrand48_r.c nrand48.c \
67 @@ -21,7 +21,7 @@ CSRC-y := \
68 CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_memalign.c
69 CSRC-$(UCLIBC_HAS_PTY) += grantpt.c unlockpt.c ptsname.c
70 CSRC-$(UCLIBC_HAS_ARC4RANDOM) += arc4random.c
71 -CSRC-$(UCLIBC_HAS_LFS) += mkstemp64.c
72 +CSRC-$(UCLIBC_HAS_LFS) += mkstemp64.c mkostemp64.c
73 CSRC-$(UCLIBC_HAS_FLOATS) += drand48.c drand48_r.c erand48.c erand48_r.c
74 CSRC-$(if $(findstring yy,$(UCLIBC_HAS_FLOATS)$(UCLIBC_SUSV3_LEGACY)),y) += \
76 diff --git a/libc/stdlib/mkostemp.c b/libc/stdlib/mkostemp.c
78 index 0000000..93b50fc
80 +++ b/libc/stdlib/mkostemp.c
82 +/* Copyright (C) 1998-2012 Free Software Foundation, Inc.
83 + This file is part of the GNU C Library.
85 + The GNU C Library is free software; you can redistribute it and/or
86 + modify it under the terms of the GNU Lesser General Public
87 + License as published by the Free Software Foundation; either
88 + version 2.1 of the License, or (at your option) any later version.
90 + The GNU C Library is distributed in the hope that it will be useful,
91 + but WITHOUT ANY WARRANTY; without even the implied warranty of
92 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93 + Lesser General Public License for more details.
95 + You should have received a copy of the GNU Lesser General Public
96 + License along with the GNU C Library; if not, see
97 + <http://www.gnu.org/licenses/>. */
101 +#include "../misc/internals/tempname.h"
103 +/* Generate a unique temporary file name from TEMPLATE.
104 + The last six characters of TEMPLATE must be "XXXXXX";
105 + they are replaced with a string that makes the filename unique.
106 + Then open the file and return a fd. */
108 +mkostemp (template, flags)
112 + return __gen_tempname (template, __GT_FILE, flags);
114 diff --git a/libc/stdlib/mkostemp64.c b/libc/stdlib/mkostemp64.c
116 index 0000000..5509d8c
118 +++ b/libc/stdlib/mkostemp64.c
120 +/* Copyright (C) 2000-2012 Free Software Foundation, Inc.
121 + This file is part of the GNU C Library.
123 + The GNU C Library is free software; you can redistribute it and/or
124 + modify it under the terms of the GNU Lesser General Public
125 + License as published by the Free Software Foundation; either
126 + version 2.1 of the License, or (at your option) any later version.
128 + The GNU C Library is distributed in the hope that it will be useful,
129 + but WITHOUT ANY WARRANTY; without even the implied warranty of
130 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
131 + Lesser General Public License for more details.
133 + You should have received a copy of the GNU Lesser General Public
134 + License along with the GNU C Library; if not, see
135 + <http://www.gnu.org/licenses/>. */
140 +#include "../misc/internals/tempname.h"
142 +/* Generate a unique temporary file name from TEMPLATE.
143 + The last six characters of TEMPLATE must be "XXXXXX";
144 + they are replaced with a string that makes the filename unique.
145 + Then open the file and return a fd. */
147 +mkostemp64 (template, flags)
151 + return __gen_tempname (template, __GT_BIGFILE, flags | O_LARGEFILE);