summaryrefslogtreecommitdiff
path: root/lib/mkstemps.c
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-11-02 15:33:10 -0700
committerEric Blake <ebb9@byu.net>2009-11-04 19:09:01 -0700
commit964a52336aad0cf4a4d6c08c128560c87742c921 (patch)
tree6ceaf633a54f64a557494d76e5fe9f8cc86f8ccc /lib/mkstemps.c
parent8eb3f17fc7fd54d63cb8f92cee955b398ce63599 (diff)
downloadgnulib-964a52336aad0cf4a4d6c08c128560c87742c921.tar.gz
mkstemps, mkostemps: new modules
* modules/mkostemps: New module. * modules/mkstemps: Likewise. * lib/mkostemps.c (mkostemps): New file. * lib/mkstemps.c (mkstemps): Likewise. * m4/mkostemps.m4 (gl_FUNC_MKOSTEMPS): Likewise. * m4/mkstemps.m4 (gl_FUNC_MKSTEMPS): Likewise. * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Add witnesses. * modules/stdlib (Makefile.am): Substitute them. * lib/stdlib.in.h (mkostemps, mkstemps): Declare them. * doc/glibc-functions/mkstemps.texi (mkstemps): New file. * doc/glibc-functions/mkostemps.texi (mkostemps): Likewise. * doc/gnulib.texi (Glibc stdlib.h): Include them. * MODULES.html.sh (File system functions): Mention them. Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'lib/mkstemps.c')
-rw-r--r--lib/mkstemps.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/mkstemps.c b/lib/mkstemps.c
new file mode 100644
index 0000000000..5ce1697353
--- /dev/null
+++ b/lib/mkstemps.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 1998, 1999, 2001, 2005, 2006, 2007, 2009 Free
+ Software Foundation, Inc.
+ This file is derived from the one in the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if !_LIBC
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#if !_LIBC
+# include <errno.h>
+# include "tempname.h"
+# define __gen_tempname gen_tempname
+# ifndef __GT_FILE
+# define __GT_FILE GT_FILE
+# endif
+# define __set_errno(x) errno = x;
+#endif
+
+#include <stdio.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);
+}