aboutsummaryrefslogtreecommitdiffstats
path: root/main/libc0.9.32/0001-libc-stdlib-add-mkostemp-helpers.patch
blob: 371177f56158d6178db19b6a798d82471047d2ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
From 42d1b23fc0f3748b8bf474e456d6c44aa7e563fd Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@gentoo.org>
Date: Wed, 14 Nov 2012 00:30:54 -0500
Subject: [PATCH] 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>
---
 include/stdlib.h         | 23 +++++++++++++++++++++++
 libc/stdlib/Makefile.in  |  4 ++--
 libc/stdlib/mkostemp.c   | 32 ++++++++++++++++++++++++++++++++
 libc/stdlib/mkostemp64.c | 33 +++++++++++++++++++++++++++++++++
 4 files changed, 90 insertions(+), 2 deletions(-)
 create mode 100644 libc/stdlib/mkostemp.c
 create mode 100644 libc/stdlib/mkostemp64.c

diff --git a/include/stdlib.h b/include/stdlib.h
index 354fc66..79ccc55 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -652,6 +652,29 @@ extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
 extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur;
 #endif
 
+#ifdef __USE_GNU
+/* Generate a unique temporary file name from TEMPLATE similar to
+   mkstemp.  But allow the caller to pass additional flags which are
+   used in the open call to create the file..
+
+   This function is a possible cancellation point and therefore not
+   marked with __THROW.  */
+# ifndef __USE_FILE_OFFSET64
+extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur;
+# else
+#  ifdef __REDIRECT
+extern int __REDIRECT (mkostemp, (char *__template, int __flags), mkostemp64)
+     __nonnull ((1)) __wur;
+#  else
+#   define mkostemp mkostemp64
+#  endif
+# endif
+# ifdef __USE_LARGEFILE64
+extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur;
+# endif
+
+#endif
+
 
 __BEGIN_NAMESPACE_STD
 /* Execute the given line as a shell command.
diff --git a/libc/stdlib/Makefile.in b/libc/stdlib/Makefile.in
index 3166b8e..b92f7ce 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 0000000..93b50fc
--- /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 0000000..5509d8c
--- /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);
+}
-- 
1.8.3.3