mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Fix bug with temporary files on Windows
This commit is contained in:
parent
ab9a284640
commit
6942d7b820
45 changed files with 55 additions and 58 deletions
|
@ -76,7 +76,7 @@
|
|||
# some notes on this compiler
|
||||
#
|
||||
# - the underlying compiler itself is gcc
|
||||
# - we use cosmopoiltan libc rather than glibc
|
||||
# - we use cosmopolitan libc rather than glibc
|
||||
# - we use llvm's compiler-rt and libcxx runtimes
|
||||
# - we patched gcc so switch case can have symbols
|
||||
# - our scanf() implementation is somewhat troubled
|
||||
|
|
|
@ -100,7 +100,6 @@ textwindows int GetNtOpenFlags(int flags, int mode, uint32_t *out_perm,
|
|||
if (flags & _O_SEQUENTIAL) attr |= kNtFileFlagSequentialScan;
|
||||
if (flags & _O_RANDOM) attr |= kNtFileFlagRandomAccess;
|
||||
if (flags & _O_DIRECT) attr |= kNtFileFlagNoBuffering;
|
||||
if (flags & _O_NDELAY) attr |= kNtFileFlagWriteThrough;
|
||||
|
||||
if (out_perm) *out_perm = perm;
|
||||
if (out_share) *out_share = share;
|
||||
|
|
|
@ -66,9 +66,7 @@ int mkstemp(char *template) {
|
|||
w /= 36;
|
||||
}
|
||||
e = errno;
|
||||
if ((fd = open(template,
|
||||
O_RDWR | O_CREAT | O_EXCL | (IsWindows() ? 0x00410000 : 0),
|
||||
0600)) != -1) {
|
||||
if ((fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600)) != -1) {
|
||||
return fd;
|
||||
} else if (errno == EEXIST) {
|
||||
errno = e;
|
||||
|
|
|
@ -40,8 +40,7 @@ int mkostempsmi(char *tpl, int slen, unsigned flags, uint64_t *rando, int mode,
|
|||
if (len < wildlen || slen > len - wildlen) return einval();
|
||||
char *ss = tpl + len - wildlen - slen;
|
||||
npassert(memcmp(ss, WILDCARD, wildlen) == 0);
|
||||
flags = (flags & ~(flags & O_ACCMODE)) | O_RDWR | O_CREAT | O_EXCL |
|
||||
(IsWindows() ? 0x00410000 : 0);
|
||||
flags = (flags & ~(flags & O_ACCMODE)) | O_RDWR | O_CREAT | O_EXCL;
|
||||
unsigned attempts = ATTEMPTS;
|
||||
do {
|
||||
char *p = ss;
|
||||
|
|
|
@ -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 0xffffffff # 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 0x00410000 # 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 af,AF_ALG,38,38,0,0,0,0,0,0
|
||||
.syscon af,AF_ALG,38,38,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_ASH,18,18,0,0,0,0,0,0
|
||||
.syscon af,AF_ASH,18,18,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_ATMPVC,8,8,0,0,0,0,0,0
|
||||
.syscon af,AF_ATMPVC,8,8,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_ATMSVC,20,20,0,0,0,0,0,0
|
||||
.syscon af,AF_ATMSVC,20,20,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_AX25,3,3,0,0,0,0,0,0
|
||||
.syscon af,AF_AX25,3,3,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_BLUETOOTH,31,31,0,0,36,0x20,31,0
|
||||
.syscon af,AF_BLUETOOTH,31,31,-1,-1,36,0x20,31,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_BRIDGE,7,7,0,0,0,0,0,0
|
||||
.syscon af,AF_BRIDGE,7,7,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_CAIF,37,37,0,0,0,0,0,0
|
||||
.syscon af,AF_CAIF,37,37,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_CAN,29,29,0,0,0,0,35,0
|
||||
.syscon af,AF_CAN,29,29,-1,-1,-1,-1,35,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_ECONET,19,19,0,0,0,0,0,0
|
||||
.syscon af,AF_ECONET,19,19,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_FILE,1,1,0,0,0,0,0,0
|
||||
.syscon af,AF_FILE,1,1,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_IB,27,27,0,0,0,0,0,0
|
||||
.syscon af,AF_IB,27,27,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_IEEE802154,36,36,0,0,0,0,0,0
|
||||
.syscon af,AF_IEEE802154,36,36,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_IRDA,23,23,0,0,0,0,0,0
|
||||
.syscon af,AF_IRDA,23,23,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_ISDN,34,34,28,28,26,26,26,0
|
||||
.syscon af,AF_ISDN,34,34,28,28,26,26,26,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_IUCV,0x20,0x20,0,0,0,0,0,0
|
||||
.syscon af,AF_IUCV,0x20,0x20,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_KCM,41,41,0,0,0,0,0,0
|
||||
.syscon af,AF_KCM,41,41,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_KEY,15,15,0,0,0,30,0,0
|
||||
.syscon af,AF_KEY,15,15,-1,-1,-1,30,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_LINK,0,0,18,18,18,18,18,0
|
||||
.syscon af,AF_LINK,-1,-1,18,18,18,18,18,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_LLC,26,26,0,0,0,0,0,0
|
||||
.syscon af,AF_LLC,26,26,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_MPLS,28,28,0,0,0,33,33,0
|
||||
.syscon af,AF_MPLS,28,28,-1,-1,-1,33,33,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_NETBEUI,13,13,0,0,0,0,0,0
|
||||
.syscon af,AF_NETBEUI,13,13,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_NETLINK,16,16,0,0,0,0,0,0
|
||||
.syscon af,AF_NETLINK,16,16,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_NETROM,6,6,0,0,0,0,0,0
|
||||
.syscon af,AF_NETROM,6,6,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_NFC,39,39,0,0,0,0,0,0
|
||||
.syscon af,AF_NFC,39,39,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_PACKET,17,17,0,0,0,0,0,0
|
||||
.syscon af,AF_PACKET,17,17,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_PHONET,35,35,0,0,0,0,0,0
|
||||
.syscon af,AF_PHONET,35,35,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_PPPOX,24,24,0,0,0,0,0,0
|
||||
.syscon af,AF_PPPOX,24,24,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_RDS,21,21,0,0,0,0,0,0
|
||||
.syscon af,AF_RDS,21,21,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_ROSE,11,11,0,0,0,0,0,0
|
||||
.syscon af,AF_ROSE,11,11,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_ROUTE,16,16,17,17,17,17,34,0
|
||||
.syscon af,AF_ROUTE,16,16,17,17,17,17,34,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_RXRPC,33,33,0,0,0,0,0,0
|
||||
.syscon af,AF_RXRPC,33,33,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_SECURITY,14,14,0,0,0,0,0,0
|
||||
.syscon af,AF_SECURITY,14,14,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_TIPC,30,30,0,0,0,0,0,0
|
||||
.syscon af,AF_TIPC,30,30,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_VSOCK,40,40,0,0,0,0,0,0
|
||||
.syscon af,AF_VSOCK,40,40,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_WANPIPE,25,25,0,0,0,0,0,0
|
||||
.syscon af,AF_WANPIPE,25,25,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon af,AF_X25,9,9,0,0,0,0,0,0
|
||||
.syscon af,AF_X25,9,9,-1,-1,-1,-1,-1,-1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#include "libc/sysv/consts/syscon.internal.h"
|
||||
.syscon open,O_TMPFILE,0x00410000,0x00404000,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff
|
||||
.syscon open,O_TMPFILE,0x00410000,0x00404000,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0x00410000
|
||||
|
|
|
@ -71,22 +71,27 @@ COSMOPOLITAN_C_END_
|
|||
#define SIGXCPU 24
|
||||
#define SIGXFSZ 25
|
||||
|
||||
/*
|
||||
* - No macro is define for SIGIO and SIGPOLL in order to persuade
|
||||
* ./configure scripts to favor using poll() or select() instead of
|
||||
* interrupt-based i/o.
|
||||
*
|
||||
* - No macros are defined for SIGRTMIN and SIGRTMAX because the project
|
||||
* hasn't fleshed them out yet.
|
||||
*
|
||||
* - SIGTHR doesn't have a macro since it's internal to posix threads.
|
||||
*/
|
||||
|
||||
#define SIGBUS SIGBUS
|
||||
#define SIGTHR SIGTHR
|
||||
#define SIGCHLD SIGCHLD
|
||||
#define SIGCONT SIGCONT
|
||||
#define SIGEMT SIGEMT
|
||||
#define SIGINFO SIGINFO
|
||||
#define SIGIO SIGIO
|
||||
#define SIGPOLL SIGPOLL
|
||||
#define SIGPWR SIGPWR
|
||||
#define SIGRTMAX SIGRTMAX
|
||||
#define SIGRTMIN SIGRTMIN
|
||||
#define SIGSTKFLT SIGSTKFLT
|
||||
#define SIGSTOP SIGSTOP
|
||||
#define SIGSYS SIGSYS
|
||||
#define SIGTSTP SIGTSTP
|
||||
#define SIGUNUSED SIGUNUSED
|
||||
#define SIGURG SIGURG
|
||||
#define SIGUSR1 SIGUSR1
|
||||
#define SIGUSR2 SIGUSR2
|
||||
|
@ -95,6 +100,4 @@ COSMOPOLITAN_C_END_
|
|||
#define SIG_SETMASK SIG_SETMASK
|
||||
#define SIG_UNBLOCK SIG_UNBLOCK
|
||||
|
||||
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_SIG_H_ */
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
|
||||
/**
|
||||
|
@ -57,9 +57,7 @@ int main(int argc, char *argv[]) {
|
|||
w /= 36;
|
||||
}
|
||||
int fd;
|
||||
if ((fd = open(template,
|
||||
O_RDWR | O_CREAT | O_EXCL | (IsWindows() ? 0x00410000 : 0),
|
||||
0600)) == -1) {
|
||||
if ((fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600)) == -1) {
|
||||
DieSys(template);
|
||||
}
|
||||
close(fd);
|
||||
|
|
Loading…
Reference in a new issue