summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/mktemp.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio/mktemp.c')
-rw-r--r--lib/libc/stdio/mktemp.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c
index 58783dd..6fc552a 100644
--- a/lib/libc/stdio/mktemp.c
+++ b/lib/libc/stdio/mktemp.c
@@ -47,17 +47,33 @@ __FBSDID("$FreeBSD$");
char *_mktemp(char *);
-static int _gettemp(char *, int *, int, int);
+static int _gettemp(char *, int *, int, int, int);
static const unsigned char padchar[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int
+mkostemps(char *path, int slen, int oflags)
+{
+ int fd;
+
+ return (_gettemp(path, &fd, 0, slen, oflags) ? fd : -1);
+}
+
+int
mkstemps(char *path, int slen)
{
int fd;
- return (_gettemp(path, &fd, 0, slen) ? fd : -1);
+ return (_gettemp(path, &fd, 0, slen, 0) ? fd : -1);
+}
+
+int
+mkostemp(char *path, int oflags)
+{
+ int fd;
+
+ return (_gettemp(path, &fd, 0, 0, oflags) ? fd : -1);
}
int
@@ -65,19 +81,19 @@ mkstemp(char *path)
{
int fd;
- return (_gettemp(path, &fd, 0, 0) ? fd : -1);
+ return (_gettemp(path, &fd, 0, 0, 0) ? fd : -1);
}
char *
mkdtemp(char *path)
{
- return (_gettemp(path, (int *)NULL, 1, 0) ? path : (char *)NULL);
+ return (_gettemp(path, (int *)NULL, 1, 0, 0) ? path : (char *)NULL);
}
char *
_mktemp(char *path)
{
- return (_gettemp(path, (int *)NULL, 0, 0) ? path : (char *)NULL);
+ return (_gettemp(path, (int *)NULL, 0, 0, 0) ? path : (char *)NULL);
}
__warn_references(mktemp,
@@ -90,7 +106,7 @@ mktemp(char *path)
}
static int
-_gettemp(char *path, int *doopen, int domkdir, int slen)
+_gettemp(char *path, int *doopen, int domkdir, int slen, int oflags)
{
char *start, *trv, *suffp, *carryp;
char *pad;
@@ -99,7 +115,9 @@ _gettemp(char *path, int *doopen, int domkdir, int slen)
uint32_t rand;
char carrybuf[MAXPATHLEN];
- if ((doopen != NULL && domkdir) || slen < 0) {
+ if ((doopen != NULL && domkdir) || slen < 0 ||
+ (oflags & ~(O_APPEND | O_DIRECT | O_SHLOCK | O_EXLOCK | O_SYNC |
+ O_CLOEXEC)) != 0) {
errno = EINVAL;
return (0);
}
@@ -151,7 +169,8 @@ _gettemp(char *path, int *doopen, int domkdir, int slen)
for (;;) {
if (doopen) {
if ((*doopen =
- _open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0)
+ _open(path, O_CREAT|O_EXCL|O_RDWR|oflags, 0600)) >=
+ 0)
return (1);
if (errno != EEXIST)
return (0);
OpenPOWER on IntegriCloud