POSIX 2024: add mkostemp

Change-Id: I254b3e5c64f5036e99a94513f05d8c491cbd6273
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8590
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
PulkoMandy
2024-11-25 22:01:21 +00:00
committed by waddlesplash
parent 4da2ed4103
commit 8fbddf13a1
2 changed files with 19 additions and 7 deletions
+1
View File
@@ -68,6 +68,7 @@ extern int system(const char *command);
extern char *mktemp(char *name); extern char *mktemp(char *name);
extern char *mkdtemp(char *templat); extern char *mkdtemp(char *templat);
extern int mkstemp(char *templat); extern int mkstemp(char *templat);
extern int mkostemp(char *templat, int oflags);
extern char *ecvt(double value, int digits, int *_decimalPoint, int *_sign); extern char *ecvt(double value, int digits, int *_decimalPoint, int *_sign);
extern char *fcvt(double value, int precision, int *_decimalPoint, extern char *fcvt(double value, int precision, int *_decimalPoint,
+18 -7
View File
@@ -46,7 +46,7 @@
#include <errno_private.h> #include <errno_private.h>
static int _gettemp(char *, int *, int, int); static int _gettemp(char *, int *, int, int, int);
static const char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; static const char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
@@ -55,7 +55,7 @@ int
mkstemps(char *path, int slen) mkstemps(char *path, int slen)
{ {
int fd; int fd;
return _gettemp(path, &fd, 0, slen) ? fd : -1; return _gettemp(path, &fd, 0, slen, 0) ? fd : -1;
} }
@@ -63,7 +63,18 @@ int
mkstemp(char *path) mkstemp(char *path)
{ {
int fd; int fd;
if (_gettemp(path, &fd, 0, 0)) if (_gettemp(path, &fd, 0, 0, 0))
return fd;
return -1;
}
int
mkostemp(char *path, int oflags)
{
int fd;
if (_gettemp(path, &fd, 0, 0, oflags))
return fd; return fd;
return -1; return -1;
@@ -74,14 +85,14 @@ char *
mkdtemp(path) mkdtemp(path)
char *path; char *path;
{ {
return (_gettemp(path, (int *)NULL, 1, 0) ? path : (char *)NULL); return (_gettemp(path, (int *)NULL, 1, 0, 0) ? path : (char *)NULL);
} }
char * char *
mktemp(char *path) mktemp(char *path)
{ {
if (_gettemp(path, (int *)NULL, 0, 0)) if (_gettemp(path, (int *)NULL, 0, 0, 0))
return path; return path;
return NULL; return NULL;
@@ -89,7 +100,7 @@ mktemp(char *path)
static int 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; char *start, *trv, *suffp;
char *pad; char *pad;
@@ -149,7 +160,7 @@ _gettemp(char *path, int *doopen, int domkdir, int slen)
for (;;) { for (;;) {
if (doopen) { 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)) >= 0)
return 1; return 1;
if (errno != EEXIST) if (errno != EEXIST)
return 0; return 0;