Module Name: src
Committed By: christos
Date: Wed Jun 18 17:47:58 UTC 2014
Modified Files:
src/lib/libc: shlib_version
src/lib/libc/stdio: Makefile.inc gettemp.c local.h mkdtemp.c mkstemp.c
mktemp.3 mktemp.c
Added Files:
src/lib/libc/stdio: gettemp.h mkostemp.c mkostemps.c mkstemps.c
Log Message:
add mkostemp, mkostemps, mkstemps from FreeBSD.
To generate a diff of this commit:
cvs rdiff -u -r1.251 -r1.252 src/lib/libc/shlib_version
cvs rdiff -u -r1.43 -r1.44 src/lib/libc/stdio/Makefile.inc
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdio/gettemp.c
cvs rdiff -u -r0 -r1.1 src/lib/libc/stdio/gettemp.h \
src/lib/libc/stdio/mkostemp.c src/lib/libc/stdio/mkostemps.c \
src/lib/libc/stdio/mkstemps.c
cvs rdiff -u -r1.37 -r1.38 src/lib/libc/stdio/local.h
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/stdio/mkdtemp.c \
src/lib/libc/stdio/mkstemp.c
cvs rdiff -u -r1.28 -r1.29 src/lib/libc/stdio/mktemp.3
cvs rdiff -u -r1.20 -r1.21 src/lib/libc/stdio/mktemp.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/shlib_version
diff -u src/lib/libc/shlib_version:1.251 src/lib/libc/shlib_version:1.252
--- src/lib/libc/shlib_version:1.251 Fri Jun 13 11:45:05 2014
+++ src/lib/libc/shlib_version Wed Jun 18 13:47:58 2014
@@ -1,4 +1,4 @@
-# $NetBSD: shlib_version,v 1.251 2014/06/13 15:45:05 joerg Exp $
+# $NetBSD: shlib_version,v 1.252 2014/06/18 17:47:58 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
# things we wish to do on next major version bump:
@@ -41,4 +41,4 @@
# - redo stdin/stdout/stderr to not require copy relocations
# - move gethostbyname to a compat library
major=12
-minor=191
+minor=192
Index: src/lib/libc/stdio/Makefile.inc
diff -u src/lib/libc/stdio/Makefile.inc:1.43 src/lib/libc/stdio/Makefile.inc:1.44
--- src/lib/libc/stdio/Makefile.inc:1.43 Thu Jan 16 15:31:43 2014
+++ src/lib/libc/stdio/Makefile.inc Wed Jun 18 13:47:58 2014
@@ -1,5 +1,5 @@
# from: @(#)Makefile.inc 5.7 (Berkeley) 6/27/91
-# $NetBSD: Makefile.inc,v 1.43 2014/01/16 20:31:43 christos Exp $
+# $NetBSD: Makefile.inc,v 1.44 2014/06/18 17:47:58 christos Exp $
# stdio sources
.PATH: ${.CURDIR}/stdio
@@ -13,8 +13,9 @@ SRCS+= clrerr.c dprintf.c fclose.c fdope
fread.c freopen.c fscanf.c fseek.c fseeko.c fsetpos.c ftell.c ftello.c \
funopen.c fvwrite.c fwalk.c fwide.c fwprintf.c fwrite.c fwscanf.c \
getc.c getchar.c getdelim.c getline.c gettemp.c getw.c getwc.c \
- getwchar.c makebuf.c mkdtemp.c mkstemp.c perror.c printf.c putc.c \
- putchar.c puts.c putw.c putwc.c putwchar.c refill.c remove.c rewind.c \
+ getwchar.c makebuf.c mkdtemp.c mkstemp.c mkstemps.c mkostemp.c \
+ mkostemps.c perror.c printf.c putc.c putchar.c puts.c putw.c putwc.c \
+ putwchar.c refill.c remove.c rewind.c \
rget.c scanf.c setbuf.c setbuffer.c setvbuf.c snprintf_ss.c \
sscanf.c stdio.c swprintf.c swscanf.c tmpfile.c ungetc.c ungetwc.c \
vasprintf.c vdprintf.c vfprintf.c vfscanf.c vfwprintf.c vfwscanf.c \
Index: src/lib/libc/stdio/gettemp.c
diff -u src/lib/libc/stdio/gettemp.c:1.17 src/lib/libc/stdio/gettemp.c:1.18
--- src/lib/libc/stdio/gettemp.c:1.17 Tue Jan 21 14:09:48 2014
+++ src/lib/libc/stdio/gettemp.c Wed Jun 18 13:47:58 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: gettemp.c,v 1.17 2014/01/21 19:09:48 seanb Exp $ */
+/* $NetBSD: gettemp.c,v 1.18 2014/06/18 17:47:58 christos Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -29,9 +29,7 @@
* SUCH DAMAGE.
*/
-#if HAVE_NBTOOL_CONFIG_H
-#include "nbtool_config.h"
-#endif
+#include "gettemp.h"
#if !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP || !HAVE_MKDTEMP
@@ -40,129 +38,119 @@
#if 0
static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: gettemp.c,v 1.17 2014/01/21 19:09:48 seanb Exp $");
+__RCSID("$NetBSD: gettemp.c,v 1.18 2014/06/18 17:47:58 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
+#include <sys/param.h>
#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
+#include <string.h>
-#if HAVE_NBTOOL_CONFIG_H
-#define GETTEMP __nbcompat_gettemp
-#else
-#include "reentrant.h"
-#include "local.h"
-#define GETTEMP __gettemp
-#endif
+static const unsigned char padchar[] =
+"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int
-GETTEMP(char *path, int *doopen, int domkdir)
+GETTEMP(char *path, int *doopen, int domkdir, int slen, int oflags)
{
- char *start, *trv;
+ char *start, *trv, *suffp, *carryp;
+ char *pad;
struct stat sbuf;
- u_int pid;
-
- /* To guarantee multiple calls generate unique names even if
- the file is not created. 676 different possibilities with 7
- or more X's, 26 with 6 or less. */
- static char xtra[2] = "aa";
- int xcnt = 0;
+ int rval;
+ uint32_t rand;
+ char carrybuf[MAXPATHLEN];
_DIAGASSERT(path != NULL);
/* doopen may be NULL */
+ if ((doopen != NULL && domkdir) || slen < 0 ||
+ (oflags & ~(O_APPEND | O_DIRECT | O_SHLOCK | O_EXLOCK | O_SYNC |
+ O_CLOEXEC)) != 0) {
+ errno = EINVAL;
+ return 0;
+ }
- pid = getpid();
+ for (trv = path; *trv != '\0'; ++trv)
+ continue;
- /* Move to end of path and count trailing X's. */
- for (trv = path; *trv; ++trv)
- if (*trv == 'X')
- xcnt++;
- else
- xcnt = 0;
-
- /* Use at least one from xtra. Use 2 if more than 6 X's. */
- if (xcnt > 0) {
- *--trv = xtra[0];
- xcnt--;
- }
- if (xcnt > 5) {
- *--trv = xtra[1];
- xcnt--;
- }
-
- /* Set remaining X's to pid digits with 0's to the left. */
- for (; xcnt > 0; xcnt--) {
- *--trv = (pid % 10) + '0';
- pid /= 10;
- }
-
- /* update xtra for next call. */
- if (xtra[0] != 'z')
- xtra[0]++;
- else {
- xtra[0] = 'a';
- if (xtra[1] != 'z')
- xtra[1]++;
- else
- xtra[1] = 'a';
+ if (trv - path >= MAXPATHLEN) {
+ errno = ENAMETOOLONG;
+ return 0;
}
+ trv -= slen;
+ suffp = trv;
+ --trv;
+ if (trv < path || NULL != strchr(suffp, '/')) {
+ errno = EINVAL;
+ return 0;
+ }
+
+ /* Fill space with random characters */
+ while (trv >= path && *trv == 'X') {
+ rand = arc4random_uniform(sizeof(padchar) - 1);
+ *trv-- = padchar[rand];
+ }
+ start = trv + 1;
+
+ /* save first combination of random characters */
+ memcpy(carrybuf, start, suffp - start);
/*
- * check the target directory; if you have six X's and it
- * doesn't exist this runs for a *very* long time.
+ * check the target directory.
*/
- for (start = trv + 1;; --trv) {
- if (trv <= path)
- break;
- if (*trv == '/') {
- int e;
- *trv = '\0';
- e = stat(path, &sbuf);
- *trv = '/';
- if (e == -1)
- return doopen == NULL && !domkdir;
- if (!S_ISDIR(sbuf.st_mode)) {
- errno = ENOTDIR;
- return doopen == NULL && !domkdir;
+ if (doopen != NULL || domkdir) {
+ for (; trv > path; --trv) {
+ if (*trv == '/') {
+ *trv = '\0';
+ rval = stat(path, &sbuf);
+ *trv = '/';
+ if (rval != 0)
+ return 0;
+ if (!S_ISDIR(sbuf.st_mode)) {
+ errno = ENOTDIR;
+ return 0;
+ }
+ break;
}
- break;
}
}
for (;;) {
if (doopen) {
- if ((*doopen =
- open(path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0)
+ if ((*doopen = open(path, O_CREAT|O_EXCL|O_RDWR|oflags,
+ 0600)) != -1)
return 1;
if (errno != EEXIST)
return 0;
} else if (domkdir) {
- if (mkdir(path, 0700) >= 0)
+ if (mkdir(path, 0700) != -1)
return 1;
if (errno != EEXIST)
return 0;
} else if (lstat(path, &sbuf))
- return errno == ENOENT ? 1 : 0;
+ return errno == ENOENT;
- /* tricky little algorithm for backward compatibility */
- for (trv = start;;) {
- if (!*trv)
+ /*
+ * If we have a collision,
+ * cycle through the space of filenames
+ */
+ for (trv = start, carryp = carrybuf;;) {
+ /* have we tried all possible permutations? */
+ if (trv == suffp)
+ return 0; /* yes - exit with EEXIST */
+ pad = strchr((const char *)padchar, *trv);
+ if (pad == NULL) {
+ /* this should never happen */
+ errno = EIO;
return 0;
- if (*trv == 'z')
- *trv++ = 'a';
- else {
- if (isdigit((unsigned char)*trv))
- *trv = 'a';
- else
- ++*trv;
+ }
+ /* increment character */
+ *trv = (*++pad == '\0') ? padchar[0] : *pad;
+ /* carry to next position? */
+ if (*trv == *carryp) {
+ /* increment position and loop */
+ ++trv;
+ ++carryp;
+ } else {
+ /* try with new name */
break;
}
}
Index: src/lib/libc/stdio/local.h
diff -u src/lib/libc/stdio/local.h:1.37 src/lib/libc/stdio/local.h:1.38
--- src/lib/libc/stdio/local.h:1.37 Fri Oct 4 16:49:16 2013
+++ src/lib/libc/stdio/local.h Wed Jun 18 13:47:58 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: local.h,v 1.37 2013/10/04 20:49:16 christos Exp $ */
+/* $NetBSD: local.h,v 1.38 2014/06/18 17:47:58 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -60,7 +60,7 @@ extern void (*__cleanup)(void);
extern void __smakebuf(FILE *);
extern int __swhatbuf(FILE *, size_t *, int *);
extern int _fwalk(int (*)(FILE *));
-extern char *_mktemp(char *);
+extern char *_mktemp(char *);
extern int __swsetup(FILE *);
extern int __sflags(const char *, int *);
extern int __svfscanf(FILE * __restrict, const char * __restrict,
@@ -75,8 +75,6 @@ extern int __vfprintf_unlocked_l(FILE *
extern int __sdidinit;
-extern int __gettemp(char *, int *, int);
-
extern wint_t __fgetwc_unlock(FILE *);
extern wint_t __fputwc_unlock(wchar_t, FILE *);
Index: src/lib/libc/stdio/mkdtemp.c
diff -u src/lib/libc/stdio/mkdtemp.c:1.11 src/lib/libc/stdio/mkdtemp.c:1.12
--- src/lib/libc/stdio/mkdtemp.c:1.11 Thu Mar 15 14:22:30 2012
+++ src/lib/libc/stdio/mkdtemp.c Wed Jun 18 13:47:58 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: mkdtemp.c,v 1.11 2012/03/15 18:22:30 christos Exp $ */
+/* $NetBSD: mkdtemp.c,v 1.12 2014/06/18 17:47:58 christos Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -29,9 +29,7 @@
* SUCH DAMAGE.
*/
-#if HAVE_NBTOOL_CONFIG_H
-#include "nbtool_config.h"
-#endif
+#include "gettemp.h"
#if !HAVE_NBTOOL_CONFIG_H || !HAVE_MKDTEMP
@@ -40,29 +38,16 @@
#if 0
static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: mkdtemp.c,v 1.11 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: mkdtemp.c,v 1.12 2014/06/18 17:47:58 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
-#if HAVE_NBTOOL_CONFIG_H
-#define GETTEMP __nbcompat_gettemp
-#else
-#include <assert.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "reentrant.h"
-#include "local.h"
-#define GETTEMP __gettemp
-#endif
-
char *
mkdtemp(char *path)
{
_DIAGASSERT(path != NULL);
- return GETTEMP(path, NULL, 1) ? path : NULL;
+ return GETTEMP(path, NULL, 1, 0, 0) ? path : NULL;
}
#endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKDTEMP */
Index: src/lib/libc/stdio/mkstemp.c
diff -u src/lib/libc/stdio/mkstemp.c:1.11 src/lib/libc/stdio/mkstemp.c:1.12
--- src/lib/libc/stdio/mkstemp.c:1.11 Thu Mar 15 14:22:30 2012
+++ src/lib/libc/stdio/mkstemp.c Wed Jun 18 13:47:58 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: mkstemp.c,v 1.11 2012/03/15 18:22:30 christos Exp $ */
+/* $NetBSD: mkstemp.c,v 1.12 2014/06/18 17:47:58 christos Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -28,10 +28,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-
-#if HAVE_NBTOOL_CONFIG_H
-#include "nbtool_config.h"
-#endif
+#include "gettemp.h"
#if !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP
@@ -40,25 +37,10 @@
#if 0
static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: mkstemp.c,v 1.11 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: mkstemp.c,v 1.12 2014/06/18 17:47:58 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
-#include "namespace.h"
-
-#if HAVE_NBTOOL_CONFIG_H
-#define GETTEMP __nbcompat_gettemp
-#else
-#include <assert.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "reentrant.h"
-#include "local.h"
-#define GETTEMP __gettemp
-#endif
-
#ifdef __weak_alias
__weak_alias(mkstemp,_mkstemp)
#endif
@@ -70,7 +52,7 @@ mkstemp(char *path)
_DIAGASSERT(path != NULL);
- return GETTEMP(path, &fd, 0) ? fd : -1;
+ return GETTEMP(path, &fd, 0, 0, 0) ? fd : -1;
}
#endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP */
Index: src/lib/libc/stdio/mktemp.3
diff -u src/lib/libc/stdio/mktemp.3:1.28 src/lib/libc/stdio/mktemp.3:1.29
--- src/lib/libc/stdio/mktemp.3:1.28 Thu May 13 23:22:49 2010
+++ src/lib/libc/stdio/mktemp.3 Wed Jun 18 13:47:58 2014
@@ -1,4 +1,4 @@
-.\" $NetBSD: mktemp.3,v 1.28 2010/05/14 03:22:49 joerg Exp $
+.\" $NetBSD: mktemp.3,v 1.29 2014/06/18 17:47:58 christos Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -45,8 +45,15 @@
.Fn mktemp "char *template"
.Ft int
.Fn mkstemp "char *template"
+.Ft int
+.Fn mkostemp "char *template" "int oflags"
+.Ft int
+.Fn mkostemps "char *template" "int suffixlen" "int oflags"
.Ft char *
.Fn mkdtemp "char *template"
+.In unistd.h
+.Ft int
+.Fn mkstemps "char *template" "int suffixlen"
.Sh DESCRIPTION
The
.Fn mktemp
@@ -92,6 +99,42 @@ makes the same replacement to the templa
mode 0600, returning a file descriptor opened for reading and writing.
This avoids the race between testing for a file's existence and opening it
for use.
+The
+.Fn mkostemp
+function
+is like
+.Fn mkstemp
+but allows specifying additional
+.Xr open 2
+flags (defined in
+.In fcntl.h ) .
+The permitted flags are
+.Dv O_APPEND ,
+.Dv O_DIRECT ,
+.Dv O_SHLOCK ,
+.Dv O_EXLOCK ,
+.Dv O_SYNC
+and
+.Dv O_CLOEXEC .
+.Pp
+The
+.Fn mkstemps
+and
+.Fn mkostemps
+functions act the same as
+.Fn mkstemp
+and
+.Fn mkostemp
+respectively,
+except they permit a suffix to exist in the template.
+The template should be of the form
+.Pa /tmp/tmpXXXXXXsuffix .
+The
+.Fn mkstemps
+and
+.Fn mkostemps
+function
+are told the length of the suffix string.
.Pp
The
.Fn mkdtemp
@@ -115,8 +158,12 @@ return a pointer to the template on succ
.Dv NULL
on failure.
The
-.Fn mkstemp
-function
+.Fn mkstemp ,
+.Fn mkostemp ,
+.Fn mkstemps
+and
+.Fn mkostemps
+functions
returns \-1 if no suitable file could be created.
If either call fails an error code is placed in the global variable
.Va errno .
@@ -201,8 +248,10 @@ of
.Er EEXIST .
.Sh ERRORS
The
-.Fn mktemp ,
-.Fn mkstemp
+.Fn mkstemp ,
+.Fn mkostemp ,
+.Fn mkstemps ,
+.Fn mkostemps
and
.Fn mkdtemp
functions
@@ -281,6 +330,22 @@ The
.Fn mkdtemp
function appeared in
.Nx 1.4 .
+The
+.Fn mkstemps
+function first appeared in
+.Ox 2.4 ,
+and later in
+.Fx 3.4
+and
+.Nx 7.0
+The
+.Fn mkostemp
+and
+.Fn mkostemps
+functions appeared in
+.Fx 10.0
+and
+.Nx 7.0
.Sh BUGS
For
.Fn mktemp
Index: src/lib/libc/stdio/mktemp.c
diff -u src/lib/libc/stdio/mktemp.c:1.20 src/lib/libc/stdio/mktemp.c:1.21
--- src/lib/libc/stdio/mktemp.c:1.20 Thu Mar 15 14:22:30 2012
+++ src/lib/libc/stdio/mktemp.c Wed Jun 18 13:47:58 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: mktemp.c,v 1.20 2012/03/15 18:22:30 christos Exp $ */
+/* $NetBSD: mktemp.c,v 1.21 2014/06/18 17:47:58 christos Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -28,22 +28,17 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+#include "gettemp.h"
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: mktemp.c,v 1.20 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: mktemp.c,v 1.21 2014/06/18 17:47:58 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
-#include <assert.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "reentrant.h"
#include "local.h"
char *
@@ -52,7 +47,7 @@ _mktemp(char *path)
_DIAGASSERT(path != NULL);
- return __gettemp(path, NULL, 0) ? path : NULL;
+ return GETTEMP(path, NULL, 0, 0, 0) ? path : NULL;
}
__warn_references(mktemp,
@@ -64,5 +59,5 @@ mktemp(char *path)
_DIAGASSERT(path != NULL);
- return __gettemp(path, NULL, 0) ? path : NULL;
+ return GETTEMP(path, NULL, 0, 0, 0) ? path : NULL;
}
Added files:
Index: src/lib/libc/stdio/gettemp.h
diff -u /dev/null src/lib/libc/stdio/gettemp.h:1.1
--- /dev/null Wed Jun 18 13:47:58 2014
+++ src/lib/libc/stdio/gettemp.h Wed Jun 18 13:47:58 2014
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _GETTEMP_H_
+#define _GETTEMP_H_
+
+#include "namespace.h"
+
+#if HAVE_NBTOOL_CONFIG_H
+# include "nbtool_config.h"
+# define GETTEMP __nbcompat_gettemp
+#else
+# include <assert.h>
+# include <errno.h>
+# include <stdio.h>
+# include <stdlib.h>
+# include <unistd.h>
+# include "reentrant.h"
+# define GETTEMP __gettemp
+#endif
+
+__BEGIN_DECLS
+int GETTEMP(char *, int *, int, int, int);
+__END_DECLS
+
+#endif /* _GETTEMP_H_ */
Index: src/lib/libc/stdio/mkostemp.c
diff -u /dev/null src/lib/libc/stdio/mkostemp.c:1.1
--- /dev/null Wed Jun 18 13:47:58 2014
+++ src/lib/libc/stdio/mkostemp.c Wed Jun 18 13:47:58 2014
@@ -0,0 +1,36 @@
+/* $NetBSD: mkostemp.c,v 1.1 2014/06/18 17:47:58 christos Exp $ */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "gettemp.h"
+
+int
+mkostemp(char *path, int oflags)
+{
+ int fd;
+
+ return GETTEMP(path, &fd, 0, 0, oflags) ? fd : -1;
+}
Index: src/lib/libc/stdio/mkostemps.c
diff -u /dev/null src/lib/libc/stdio/mkostemps.c:1.1
--- /dev/null Wed Jun 18 13:47:58 2014
+++ src/lib/libc/stdio/mkostemps.c Wed Jun 18 13:47:58 2014
@@ -0,0 +1,36 @@
+/* $NetBSD: mkostemps.c,v 1.1 2014/06/18 17:47:58 christos Exp $ */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "gettemp.h"
+
+int
+mkostemps(char *path, int slen, int oflags)
+{
+ int fd;
+
+ return GETTEMP(path, &fd, 0, slen, oflags) ? fd : -1;
+}
Index: src/lib/libc/stdio/mkstemps.c
diff -u /dev/null src/lib/libc/stdio/mkstemps.c:1.1
--- /dev/null Wed Jun 18 13:47:58 2014
+++ src/lib/libc/stdio/mkstemps.c Wed Jun 18 13:47:58 2014
@@ -0,0 +1,36 @@
+/* $NetBSD: mkstemps.c,v 1.1 2014/06/18 17:47:58 christos Exp $ */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "gettemp.h"
+
+int
+mkstemps(char *path, int slen)
+{
+ int fd;
+
+ return GETTEMP(path, &fd, 0, slen, 0) ? fd : -1;
+}