mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-02 23:18:44 +00:00
Fix the build
This commit is contained in:
parent
6942d7b820
commit
b40d41085d
4 changed files with 32 additions and 26 deletions
|
@ -26,6 +26,32 @@
|
|||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
int _mkstemp(char *template, int oflags) {
|
||||
uint64_t w;
|
||||
int i, n, e, fd;
|
||||
if ((n = strlen(template)) < 6 ||
|
||||
READ16LE(template + n - 2) != READ16LE("XX") ||
|
||||
READ32LE(template + n - 6) != READ32LE("XXXX")) {
|
||||
return einval();
|
||||
}
|
||||
for (;;) {
|
||||
w = _rand64();
|
||||
for (i = 0; i < 6; ++i) {
|
||||
template[n - 6 + i] = "0123456789abcdefghijklmnopqrstuvwxyz"[w % 36];
|
||||
w /= 36;
|
||||
}
|
||||
e = errno;
|
||||
if ((fd = open(template, O_RDWR | O_CREAT | O_EXCL | oflags, 0600)) != -1) {
|
||||
return fd;
|
||||
} else if (errno == EEXIST) {
|
||||
errno = e;
|
||||
} else {
|
||||
template[0] = 0;
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates temporary file name and file descriptor.
|
||||
*
|
||||
|
@ -52,27 +78,5 @@
|
|||
* @see tmpfd() if you don't need a path
|
||||
*/
|
||||
int mkstemp(char *template) {
|
||||
uint64_t w;
|
||||
int i, n, e, fd;
|
||||
if ((n = strlen(template)) < 6 ||
|
||||
READ16LE(template + n - 2) != READ16LE("XX") ||
|
||||
READ32LE(template + n - 6) != READ32LE("XXXX")) {
|
||||
return einval();
|
||||
}
|
||||
for (;;) {
|
||||
w = _rand64();
|
||||
for (i = 0; i < 6; ++i) {
|
||||
template[n - 6 + i] = "0123456789abcdefghijklmnopqrstuvwxyz"[w % 36];
|
||||
w /= 36;
|
||||
}
|
||||
e = errno;
|
||||
if ((fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600)) != -1) {
|
||||
return fd;
|
||||
} else if (errno == EEXIST) {
|
||||
errno = e;
|
||||
} else {
|
||||
template[0] = 0;
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
return _mkstemp(template, 0);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
#define _O_TMPFILE 000020200000
|
||||
|
||||
int _mkstemp(char *, int);
|
||||
|
||||
/**
|
||||
* Returns file descriptor of open anonymous file, e.g.
|
||||
*
|
||||
|
@ -88,7 +90,7 @@ int tmpfd(void) {
|
|||
if (!(prog = program_invocation_short_name)) prog = "tmp";
|
||||
strlcat(path, prog, sizeof(path));
|
||||
strlcat(path, ".XXXXXX", sizeof(path));
|
||||
if ((fd = mkstemp(path)) == -1) return -1;
|
||||
if ((fd = _mkstemp(path, IsWindows() ? 0x00410000 : 0)) == -1) return -1;
|
||||
if (!IsWindows()) unassert(!unlink(path));
|
||||
return fd;
|
||||
}
|
||||
|
|
|
@ -193,7 +193,7 @@ syscon open O_SEQUENTIAL 0 0 0 0 0 0 0 0x40000000 # kNtFileFl
|
|||
syscon open O_COMPRESSED 0 0 0 0 0 0 0 0x20000000 # kNtFileAttributeCompressed [SYNC libc/calls/open-nt.c]
|
||||
syscon open O_INDEXED 0 0 0 0 0 0 0 0x10000000 # !kNtFileAttributeNotContentIndexed [SYNC libc/calls/open-nt.c]
|
||||
syscon open O_CLOEXEC 0x00080000 0x00080000 0x01000000 0x01000000 0x00100000 0x00010000 0x00400000 0x00080000 # NT faked as Linux [SYNC libc/calls/open-nt.c]
|
||||
syscon open O_TMPFILE 0x00410000 0x00404000 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0x00410000 # please use tmpfd(); Linux 3.11+ (c. 2013) __O_TMPFILE | O_DIRECTORY; kNtFileAttributeTemporary|kNtFileFlagDeleteOnClose [SYNC libc/calls/open-nt.c]
|
||||
syscon open O_TMPFILE 0x00410000 0x00404000 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff # please use tmpfd(); Linux 3.11+ (c. 2013) __O_TMPFILE | O_DIRECTORY; kNtFileAttributeTemporary|kNtFileFlagDeleteOnClose [SYNC libc/calls/open-nt.c]
|
||||
syscon open O_SPARSE 0 0 0 0 0 0 0 0 # wut
|
||||
syscon open O_NONBLOCK 0x00000800 0x00000800 0x00000004 0x00000004 0x00000004 0x00000004 0x00000004 0x00000800 # bsd consensus
|
||||
syscon open O_ASYNC 0x00002000 0x00002000 0x00000040 0x00000040 0x00000040 0x00000040 0x00000040 0 # bsd consensus
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon open,O_TMPFILE,0x00410000,0x00404000,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0x00410000
|
||||
.syscon open,O_TMPFILE,0x00410000,0x00404000,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff
|
||||
|
|
Loading…
Add table
Reference in a new issue