mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-12 01:08:00 +00:00
Fix issues for latest GCC toolchain
This commit is contained in:
parent
5cb9b2658c
commit
3b086af91b
22 changed files with 148 additions and 166 deletions
|
@ -24,20 +24,13 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
static textwindows bool SubpathExistsThatsNotDirectory(char16_t *path) {
|
static textwindows bool SubpathExistsThatsNotDirectory(char16_t *path) {
|
||||||
int e;
|
|
||||||
char16_t *p;
|
char16_t *p;
|
||||||
uint32_t attrs;
|
uint32_t attrs;
|
||||||
e = errno;
|
|
||||||
while ((p = strrchr16(path, '\\'))) {
|
while ((p = strrchr16(path, '\\'))) {
|
||||||
*p = u'\0';
|
*p = u'\0';
|
||||||
if ((attrs = GetFileAttributes(path)) != -1u) {
|
if ((attrs = GetFileAttributes(path)) != -1u &&
|
||||||
if (attrs & kNtFileAttributeDirectory) {
|
!(attrs & kNtFileAttributeDirectory)) {
|
||||||
return false;
|
return true;
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
errno = e;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -21,31 +21,40 @@
|
||||||
#include "libc/calls/struct/stat.h"
|
#include "libc/calls/struct/stat.h"
|
||||||
#include "libc/calls/struct/stat.internal.h"
|
#include "libc/calls/struct/stat.internal.h"
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
|
#include "libc/errno.h"
|
||||||
#include "libc/nt/createfile.h"
|
#include "libc/nt/createfile.h"
|
||||||
#include "libc/nt/enum/accessmask.h"
|
#include "libc/nt/enum/accessmask.h"
|
||||||
#include "libc/nt/enum/creationdisposition.h"
|
#include "libc/nt/enum/creationdisposition.h"
|
||||||
#include "libc/nt/enum/fileflagandattributes.h"
|
#include "libc/nt/enum/fileflagandattributes.h"
|
||||||
#include "libc/nt/enum/filesharemode.h"
|
#include "libc/nt/enum/filesharemode.h"
|
||||||
|
#include "libc/nt/errors.h"
|
||||||
#include "libc/nt/runtime.h"
|
#include "libc/nt/runtime.h"
|
||||||
#include "libc/sysv/consts/at.h"
|
#include "libc/sysv/consts/at.h"
|
||||||
|
|
||||||
textwindows int sys_fstatat_nt(int dirfd, const char *path, struct stat *st,
|
textwindows int sys_fstatat_nt(int dirfd, const char *path, struct stat *st,
|
||||||
int flags) {
|
int flags) {
|
||||||
int rc;
|
int rc, e;
|
||||||
int64_t fh;
|
int64_t fh;
|
||||||
|
uint32_t dwDesiredAccess;
|
||||||
uint16_t path16[PATH_MAX];
|
uint16_t path16[PATH_MAX];
|
||||||
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
|
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
|
||||||
BLOCK_SIGNALS;
|
BLOCK_SIGNALS;
|
||||||
|
e = errno;
|
||||||
|
dwDesiredAccess = kNtFileGenericRead;
|
||||||
|
TryAgain:
|
||||||
if ((fh = CreateFile(
|
if ((fh = CreateFile(
|
||||||
path16, kNtFileGenericRead,
|
path16, dwDesiredAccess, 0, 0, kNtOpenExisting,
|
||||||
kNtFileShareRead | kNtFileShareWrite | kNtFileShareDelete, 0,
|
|
||||||
kNtOpenExisting,
|
|
||||||
kNtFileAttributeNormal | kNtFileFlagBackupSemantics |
|
kNtFileAttributeNormal | kNtFileFlagBackupSemantics |
|
||||||
((flags & AT_SYMLINK_NOFOLLOW) ? kNtFileFlagOpenReparsePoint
|
((flags & AT_SYMLINK_NOFOLLOW) ? kNtFileFlagOpenReparsePoint
|
||||||
: 0),
|
: 0),
|
||||||
0)) != -1) {
|
0)) != -1) {
|
||||||
rc = st ? sys_fstat_nt(fh, st) : 0;
|
rc = st ? sys_fstat_nt(fh, st) : 0;
|
||||||
CloseHandle(fh);
|
CloseHandle(fh);
|
||||||
|
} else if (dwDesiredAccess == kNtFileGenericRead &&
|
||||||
|
GetLastError() == kNtErrorSharingViolation) {
|
||||||
|
dwDesiredAccess = kNtFileReadAttributes;
|
||||||
|
errno = e;
|
||||||
|
goto TryAgain;
|
||||||
} else {
|
} else {
|
||||||
rc = __winerr();
|
rc = __winerr();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,15 +26,12 @@
|
||||||
* Returns true if file exists and is a directory on Windows NT.
|
* Returns true if file exists and is a directory on Windows NT.
|
||||||
*/
|
*/
|
||||||
bool isdirectory_nt(const char *path) {
|
bool isdirectory_nt(const char *path) {
|
||||||
int e;
|
|
||||||
uint32_t x;
|
uint32_t x;
|
||||||
char16_t path16[PATH_MAX];
|
char16_t path16[PATH_MAX];
|
||||||
e = errno;
|
|
||||||
if (__mkntpath(path, path16) == -1) return -1;
|
if (__mkntpath(path, path16) == -1) return -1;
|
||||||
if ((x = GetFileAttributes(path16)) != -1u) {
|
if ((x = GetFileAttributes(path16)) != -1u) {
|
||||||
return !!(x & kNtFileAttributeDirectory);
|
return !!(x & kNtFileAttributeDirectory);
|
||||||
} else {
|
} else {
|
||||||
errno = e;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,15 +26,12 @@
|
||||||
* Returns true if file exists and is a regular file on Windows NT.
|
* Returns true if file exists and is a regular file on Windows NT.
|
||||||
*/
|
*/
|
||||||
bool isregularfile_nt(const char *path) {
|
bool isregularfile_nt(const char *path) {
|
||||||
int e;
|
|
||||||
uint32_t x;
|
uint32_t x;
|
||||||
char16_t path16[PATH_MAX];
|
char16_t path16[PATH_MAX];
|
||||||
e = errno;
|
|
||||||
if (__mkntpath(path, path16) == -1) return -1;
|
if (__mkntpath(path, path16) == -1) return -1;
|
||||||
if ((x = GetFileAttributes(path16)) != -1u) {
|
if ((x = GetFileAttributes(path16)) != -1u) {
|
||||||
return !(x & (kNtFileAttributeDirectory | kNtFileAttributeReparsePoint));
|
return !(x & (kNtFileAttributeDirectory | kNtFileAttributeReparsePoint));
|
||||||
} else {
|
} else {
|
||||||
errno = e;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,7 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/errno.h"
|
|
||||||
#include "libc/nt/enum/fileflagandattributes.h"
|
#include "libc/nt/enum/fileflagandattributes.h"
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
|
|
||||||
|
@ -26,15 +24,12 @@
|
||||||
* Returns true if file exists and is a symbolic link on Windows NT.
|
* Returns true if file exists and is a symbolic link on Windows NT.
|
||||||
*/
|
*/
|
||||||
bool issymlink_nt(const char *path) {
|
bool issymlink_nt(const char *path) {
|
||||||
int e;
|
|
||||||
uint32_t x;
|
uint32_t x;
|
||||||
char16_t path16[PATH_MAX];
|
char16_t path16[PATH_MAX];
|
||||||
e = errno;
|
|
||||||
if (__mkntpath(path, path16) == -1) return -1;
|
if (__mkntpath(path, path16) == -1) return -1;
|
||||||
if ((x = GetFileAttributes(path16)) != -1u) {
|
if ((x = GetFileAttributes(path16)) != -1u) {
|
||||||
return !!(x & kNtFileAttributeReparsePoint);
|
return !!(x & kNtFileAttributeReparsePoint);
|
||||||
} else {
|
} else {
|
||||||
errno = e;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
#include "libc/sysv/consts/at.h"
|
#include "libc/sysv/consts/at.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
__msabi extern typeof(GetFileAttributes) *const __imp_GetFileAttributesW;
|
|
||||||
|
|
||||||
static int __mkntpathat_impl(int dirfd, const char *path, int flags,
|
static int __mkntpathat_impl(int dirfd, const char *path, int flags,
|
||||||
char16_t file[hasatleast PATH_MAX]) {
|
char16_t file[hasatleast PATH_MAX]) {
|
||||||
char16_t dir[PATH_MAX];
|
char16_t dir[PATH_MAX];
|
||||||
|
@ -71,7 +69,7 @@ int __mkntpathat(int dirfd, const char *path, int flags,
|
||||||
if (len > 1 && !(len == 3 && file[1] == ':')) {
|
if (len > 1 && !(len == 3 && file[1] == ':')) {
|
||||||
file[--len] = 0;
|
file[--len] = 0;
|
||||||
}
|
}
|
||||||
if ((fattr = __imp_GetFileAttributesW(file)) != -1u &&
|
if ((fattr = GetFileAttributes(file)) != -1u &&
|
||||||
!(fattr & kNtFileAttributeReparsePoint) &&
|
!(fattr & kNtFileAttributeReparsePoint) &&
|
||||||
!(fattr & kNtFileAttributeDirectory)) {
|
!(fattr & kNtFileAttributeDirectory)) {
|
||||||
return enotdir();
|
return enotdir();
|
||||||
|
|
|
@ -57,7 +57,7 @@ static textwindows int64_t sys_open_nt_impl(int dirfd, const char *path,
|
||||||
// you can't open symlinks; use readlink
|
// you can't open symlinks; use readlink
|
||||||
// this flag only applies to the final path component
|
// this flag only applies to the final path component
|
||||||
// if O_NOFOLLOW_ANY is passed (-1 on NT) it'll be rejected later
|
// if O_NOFOLLOW_ANY is passed (-1 on NT) it'll be rejected later
|
||||||
uint32_t fattr = __imp_GetFileAttributesW(path16);
|
uint32_t fattr = GetFileAttributes(path16);
|
||||||
if (flags & O_NOFOLLOW) {
|
if (flags & O_NOFOLLOW) {
|
||||||
if (fattr != -1u && (fattr & kNtFileAttributeReparsePoint)) {
|
if (fattr != -1u && (fattr & kNtFileAttributeReparsePoint)) {
|
||||||
return eloop();
|
return eloop();
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/vga/vga.internal.h"
|
#include "libc/vga/vga.internal.h"
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
|
||||||
ssize_t sys_readv_metal(int fd, const struct iovec *iov, int iovlen) {
|
ssize_t sys_readv_metal(int fd, const struct iovec *iov, int iovlen) {
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include "libc/sock/internal.h"
|
#include "libc/sock/internal.h"
|
||||||
#include "libc/sock/syscall_fd.internal.h"
|
#include "libc/sock/syscall_fd.internal.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
|
||||||
textwindows ssize_t sys_readv_nt(int fd, const struct iovec *iov, int iovlen) {
|
textwindows ssize_t sys_readv_nt(int fd, const struct iovec *iov, int iovlen) {
|
||||||
|
|
|
@ -50,4 +50,4 @@ ssize_t sys_readv_serial(int fd, const struct iovec *iov, int iovlen) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif /* __x86_64__ */
|
||||||
|
|
|
@ -28,9 +28,6 @@
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
__msabi extern typeof(GetFileAttributes) *const __imp_GetFileAttributesW;
|
|
||||||
__msabi extern typeof(RemoveDirectory) *const __imp_RemoveDirectoryW;
|
|
||||||
|
|
||||||
static textwindows bool StripTrailingSlash(char16_t *path) {
|
static textwindows bool StripTrailingSlash(char16_t *path) {
|
||||||
size_t n = strlen16(path);
|
size_t n = strlen16(path);
|
||||||
bool had_trailing_slash = false;
|
bool had_trailing_slash = false;
|
||||||
|
@ -67,8 +64,8 @@ textwindows int sys_renameat_nt(int olddirfd, const char *oldpath, int newdirfd,
|
||||||
// test for some known error conditions ahead of time
|
// test for some known error conditions ahead of time
|
||||||
// the enotdir check can't be done reactively
|
// the enotdir check can't be done reactively
|
||||||
// ideally we should resolve symlinks first
|
// ideally we should resolve symlinks first
|
||||||
uint32_t oldattr = __imp_GetFileAttributesW(M.oldpath16);
|
uint32_t oldattr = GetFileAttributes(M.oldpath16);
|
||||||
uint32_t newattr = __imp_GetFileAttributesW(M.newpath16);
|
uint32_t newattr = GetFileAttributes(M.newpath16);
|
||||||
if ((old_must_be_dir && oldattr != -1u &&
|
if ((old_must_be_dir && oldattr != -1u &&
|
||||||
!(oldattr & kNtFileAttributeDirectory)) ||
|
!(oldattr & kNtFileAttributeDirectory)) ||
|
||||||
(new_must_be_dir && newattr != -1u &&
|
(new_must_be_dir && newattr != -1u &&
|
||||||
|
@ -85,7 +82,7 @@ textwindows int sys_renameat_nt(int olddirfd, const char *oldpath, int newdirfd,
|
||||||
} else if ((oldattr & kNtFileAttributeDirectory) &&
|
} else if ((oldattr & kNtFileAttributeDirectory) &&
|
||||||
(newattr & kNtFileAttributeDirectory)) {
|
(newattr & kNtFileAttributeDirectory)) {
|
||||||
// both old and new are directories
|
// both old and new are directories
|
||||||
if (!__imp_RemoveDirectoryW(M.newpath16) &&
|
if (!RemoveDirectory(M.newpath16) &&
|
||||||
GetLastError() == kNtErrorDirNotEmpty) {
|
GetLastError() == kNtErrorDirNotEmpty) {
|
||||||
return enotempty();
|
return enotempty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,6 @@
|
||||||
#include "libc/runtime/stack.h"
|
#include "libc/runtime/stack.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
__msabi extern typeof(GetFileAttributes) *const __imp_GetFileAttributesW;
|
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
_Atomic(uint32_t) once;
|
_Atomic(uint32_t) once;
|
||||||
_Bool allowed;
|
_Bool allowed;
|
||||||
|
@ -72,7 +70,7 @@ textwindows int sys_symlinkat_nt(const char *target, int newdirfd,
|
||||||
if ((targetlen = __mkntpath(target, M.target16)) == -1) return -1;
|
if ((targetlen = __mkntpath(target, M.target16)) == -1) return -1;
|
||||||
|
|
||||||
// determine if we need directory flag
|
// determine if we need directory flag
|
||||||
if ((attrs = __imp_GetFileAttributesW(M.target16)) != -1u) {
|
if ((attrs = GetFileAttributes(M.target16)) != -1u) {
|
||||||
if (attrs & kNtFileAttributeDirectory) {
|
if (attrs & kNtFileAttributeDirectory) {
|
||||||
flags = kNtSymbolicLinkFlagDirectory;
|
flags = kNtSymbolicLinkFlagDirectory;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -55,8 +55,7 @@ static textwindows bool IsDirectorySymlink(const char16_t *path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static textwindows int sys_rmdir_nt(const char16_t *path) {
|
static textwindows int sys_rmdir_nt(const char16_t *path) {
|
||||||
int e, ms;
|
int ms;
|
||||||
e = errno;
|
|
||||||
for (ms = 1;; ms *= 2) {
|
for (ms = 1;; ms *= 2) {
|
||||||
if (RemoveDirectory(path)) {
|
if (RemoveDirectory(path)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -67,14 +66,13 @@ static textwindows int sys_rmdir_nt(const char16_t *path) {
|
||||||
// Alternative is use Microsoft internal APIs.
|
// Alternative is use Microsoft internal APIs.
|
||||||
// Never could have imagined it'd be this bad.
|
// Never could have imagined it'd be this bad.
|
||||||
if (GetLastError() == kNtErrorDirNotEmpty && ms <= 2048) {
|
if (GetLastError() == kNtErrorDirNotEmpty && ms <= 2048) {
|
||||||
errno = e;
|
|
||||||
Sleep(ms);
|
Sleep(ms);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return __winerr();
|
||||||
}
|
}
|
||||||
|
|
||||||
static textwindows int sys_unlink_nt(const char16_t *path) {
|
static textwindows int sys_unlink_nt(const char16_t *path) {
|
||||||
|
|
|
@ -16,10 +16,8 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
|
||||||
#include "libc/intrin/describeflags.internal.h"
|
#include "libc/intrin/describeflags.internal.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
#include "libc/nt/enum/fileflagandattributes.h"
|
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
#include "libc/nt/thunk/msabi.h"
|
#include "libc/nt/thunk/msabi.h"
|
||||||
|
|
||||||
|
@ -27,15 +25,12 @@ __msabi extern typeof(GetFileAttributes) *const __imp_GetFileAttributesW;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets file info on the New Technology.
|
* Gets file info on the New Technology.
|
||||||
*
|
|
||||||
* @return handle, or -1u on failure
|
* @return handle, or -1u on failure
|
||||||
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
|
|
||||||
*/
|
*/
|
||||||
textwindows uint32_t GetFileAttributes(const char16_t *lpPathName) {
|
textwindows uint32_t GetFileAttributes(const char16_t *lpPathName) {
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
flags = __imp_GetFileAttributesW(lpPathName);
|
flags = __imp_GetFileAttributesW(lpPathName);
|
||||||
if (flags == -1u) __winerr();
|
NTTRACE("GetFileAttributes(%#hs) → %s", lpPathName,
|
||||||
NTTRACE("GetFileAttributes(%#hs) → %s% m", lpPathName,
|
|
||||||
DescribeNtFileFlagAttr(flags));
|
DescribeNtFileFlagAttr(flags));
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/syscall_support-nt.internal.h"
|
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
#include "libc/nt/files.h"
|
#include "libc/nt/files.h"
|
||||||
#include "libc/nt/thunk/msabi.h"
|
#include "libc/nt/thunk/msabi.h"
|
||||||
|
@ -25,12 +24,10 @@ __msabi extern typeof(RemoveDirectory) *const __imp_RemoveDirectoryW;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes existing empty directory on the New Technology.
|
* Deletes existing empty directory on the New Technology.
|
||||||
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
|
|
||||||
*/
|
*/
|
||||||
textwindows bool32 RemoveDirectory(const char16_t *lpPathName) {
|
textwindows bool32 RemoveDirectory(const char16_t *lpPathName) {
|
||||||
bool32 ok;
|
bool32 ok;
|
||||||
ok = __imp_RemoveDirectoryW(lpPathName);
|
ok = __imp_RemoveDirectoryW(lpPathName);
|
||||||
if (!ok) __winerr();
|
NTTRACE("RemoveDirectory(%#hs) → %hhhd", lpPathName, ok);
|
||||||
NTTRACE("RemoveDirectory(%#hs) → %hhhd% m", lpPathName, ok);
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,20 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define __PRIPTR "ll"
|
#define __PRIPTR "ll"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __INT_FAST16_WIDTH__ == 16
|
||||||
|
#define __PRIFAST16 "h"
|
||||||
|
#elif __INT_FAST16_WIDTH__ == 32
|
||||||
|
#define __PRIFAST16 ""
|
||||||
|
#else
|
||||||
|
#define __PRIFAST16 "l"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __INT_FAST32_WIDTH__ == 32
|
||||||
|
#define __PRIFAST32 ""
|
||||||
|
#else
|
||||||
|
#define __PRIFAST32 "l"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||||
│ cosmopolitan § dismal format notation » printf » decimal ─╬─│┼
|
│ cosmopolitan § dismal format notation » printf » decimal ─╬─│┼
|
||||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||||
|
@ -86,8 +100,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define PRIdLEAST128 __PRI128 "d"
|
#define PRIdLEAST128 __PRI128 "d"
|
||||||
|
|
||||||
#define PRIdFAST8 __PRI8 "d"
|
#define PRIdFAST8 __PRI8 "d"
|
||||||
#define PRIdFAST16 __PRI32 "d"
|
#define PRIdFAST16 __PRIFAST16 "d"
|
||||||
#define PRIdFAST32 __PRI32 "d"
|
#define PRIdFAST32 __PRIFAST32 "d"
|
||||||
#define PRIdFAST64 __PRI64 "d"
|
#define PRIdFAST64 __PRI64 "d"
|
||||||
#define PRIdFAST128 __PRI128 "d"
|
#define PRIdFAST128 __PRI128 "d"
|
||||||
|
|
||||||
|
@ -108,8 +122,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define PRIuLEAST128 __PRI128 "u"
|
#define PRIuLEAST128 __PRI128 "u"
|
||||||
|
|
||||||
#define PRIuFAST8 __PRI8 "u"
|
#define PRIuFAST8 __PRI8 "u"
|
||||||
#define PRIuFAST16 __PRI32 "u"
|
#define PRIuFAST16 __PRIFAST16 "u"
|
||||||
#define PRIuFAST32 __PRI32 "u"
|
#define PRIuFAST32 __PRIFAST32 "u"
|
||||||
#define PRIuFAST64 __PRI64 "u"
|
#define PRIuFAST64 __PRI64 "u"
|
||||||
#define PRIuFAST128 __PRI128 "u"
|
#define PRIuFAST128 __PRI128 "u"
|
||||||
|
|
||||||
|
@ -130,8 +144,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define PRIiLEAST128 __PRI128 "i"
|
#define PRIiLEAST128 __PRI128 "i"
|
||||||
|
|
||||||
#define PRIiFAST8 __PRI8 "i"
|
#define PRIiFAST8 __PRI8 "i"
|
||||||
#define PRIiFAST16 __PRI32 "i"
|
#define PRIiFAST16 __PRIFAST16 "i"
|
||||||
#define PRIiFAST32 __PRI32 "i"
|
#define PRIiFAST32 __PRIFAST32 "i"
|
||||||
#define PRIiFAST64 __PRI64 "i"
|
#define PRIiFAST64 __PRI64 "i"
|
||||||
#define PRIiFAST128 __PRI128 "i"
|
#define PRIiFAST128 __PRI128 "i"
|
||||||
|
|
||||||
|
@ -152,8 +166,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define PRIoLEAST128 __PRI128 "o"
|
#define PRIoLEAST128 __PRI128 "o"
|
||||||
|
|
||||||
#define PRIoFAST8 __PRI8 "o"
|
#define PRIoFAST8 __PRI8 "o"
|
||||||
#define PRIoFAST16 __PRI32 "o"
|
#define PRIoFAST16 __PRIFAST16 "o"
|
||||||
#define PRIoFAST32 __PRI32 "o"
|
#define PRIoFAST32 __PRIFAST32 "o"
|
||||||
#define PRIoFAST64 __PRI64 "o"
|
#define PRIoFAST64 __PRI64 "o"
|
||||||
#define PRIoFAST128 __PRI128 "o"
|
#define PRIoFAST128 __PRI128 "o"
|
||||||
|
|
||||||
|
@ -174,8 +188,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define PRIxLEAST128 __PRI128 "x"
|
#define PRIxLEAST128 __PRI128 "x"
|
||||||
|
|
||||||
#define PRIxFAST8 __PRI8 "x"
|
#define PRIxFAST8 __PRI8 "x"
|
||||||
#define PRIxFAST16 __PRI32 "x"
|
#define PRIxFAST16 __PRIFAST16 "x"
|
||||||
#define PRIxFAST32 __PRI32 "x"
|
#define PRIxFAST32 __PRIFAST32 "x"
|
||||||
#define PRIxFAST64 __PRI64 "x"
|
#define PRIxFAST64 __PRI64 "x"
|
||||||
#define PRIxFAST128 __PRI128 "x"
|
#define PRIxFAST128 __PRI128 "x"
|
||||||
|
|
||||||
|
@ -192,8 +206,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define PRIXLEAST128 __PRI128 "X"
|
#define PRIXLEAST128 __PRI128 "X"
|
||||||
|
|
||||||
#define PRIXFAST8 __PRI8 "X"
|
#define PRIXFAST8 __PRI8 "X"
|
||||||
#define PRIXFAST16 __PRI32 "X"
|
#define PRIXFAST16 __PRIFAST16 "X"
|
||||||
#define PRIXFAST32 __PRI32 "X"
|
#define PRIXFAST32 __PRIFAST32 "X"
|
||||||
#define PRIXFAST64 __PRI64 "X"
|
#define PRIXFAST64 __PRI64 "X"
|
||||||
#define PRIXFAST128 __PRI128 "X"
|
#define PRIXFAST128 __PRI128 "X"
|
||||||
|
|
||||||
|
@ -214,8 +228,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define PRIbLEAST128 __PRI128 "b"
|
#define PRIbLEAST128 __PRI128 "b"
|
||||||
|
|
||||||
#define PRIbFAST8 __PRI8 "b"
|
#define PRIbFAST8 __PRI8 "b"
|
||||||
#define PRIbFAST16 __PRI32 "b"
|
#define PRIbFAST16 __PRIFAST16 "b"
|
||||||
#define PRIbFAST32 __PRI32 "b"
|
#define PRIbFAST32 __PRIFAST32 "b"
|
||||||
#define PRIbFAST64 __PRI64 "b"
|
#define PRIbFAST64 __PRI64 "b"
|
||||||
#define PRIbFAST128 __PRI128 "b"
|
#define PRIbFAST128 __PRI128 "b"
|
||||||
|
|
||||||
|
@ -232,8 +246,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define PRIBLEAST128 __PRI128 "B"
|
#define PRIBLEAST128 __PRI128 "B"
|
||||||
|
|
||||||
#define PRIBFAST8 __PRI8 "B"
|
#define PRIBFAST8 __PRI8 "B"
|
||||||
#define PRIBFAST16 __PRI32 "B"
|
#define PRIBFAST16 __PRIFAST16 "B"
|
||||||
#define PRIBFAST32 __PRI32 "B"
|
#define PRIBFAST32 __PRIFAST32 "B"
|
||||||
#define PRIBFAST64 __PRI64 "B"
|
#define PRIBFAST64 __PRI64 "B"
|
||||||
#define PRIBFAST128 __PRI128 "B"
|
#define PRIBFAST128 __PRI128 "B"
|
||||||
|
|
||||||
|
@ -272,8 +286,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define SCNdLEAST128 __PRI128 "d"
|
#define SCNdLEAST128 __PRI128 "d"
|
||||||
|
|
||||||
#define SCNdFAST8 __PRI8 "d"
|
#define SCNdFAST8 __PRI8 "d"
|
||||||
#define SCNdFAST16 __PRI32 "d"
|
#define SCNdFAST16 __PRIFAST16 "d"
|
||||||
#define SCNdFAST32 __PRI32 "d"
|
#define SCNdFAST32 __PRIFAST32 "d"
|
||||||
#define SCNdFAST64 __PRI64 "d"
|
#define SCNdFAST64 __PRI64 "d"
|
||||||
#define SCNdFAST128 __PRI128 "d"
|
#define SCNdFAST128 __PRI128 "d"
|
||||||
|
|
||||||
|
@ -294,8 +308,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define SCNiLEAST128 __PRI128 "i"
|
#define SCNiLEAST128 __PRI128 "i"
|
||||||
|
|
||||||
#define SCNiFAST8 __PRI8 "i"
|
#define SCNiFAST8 __PRI8 "i"
|
||||||
#define SCNiFAST16 __PRI32 "i"
|
#define SCNiFAST16 __PRIFAST16 "i"
|
||||||
#define SCNiFAST32 __PRI32 "i"
|
#define SCNiFAST32 __PRIFAST32 "i"
|
||||||
#define SCNiFAST64 __PRI64 "i"
|
#define SCNiFAST64 __PRI64 "i"
|
||||||
#define SCNiFAST128 __PRI128 "i"
|
#define SCNiFAST128 __PRI128 "i"
|
||||||
|
|
||||||
|
@ -316,8 +330,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define SCNuLEAST128 __PRI128 "u"
|
#define SCNuLEAST128 __PRI128 "u"
|
||||||
|
|
||||||
#define SCNuFAST8 __PRI8 "u"
|
#define SCNuFAST8 __PRI8 "u"
|
||||||
#define SCNuFAST16 __PRI32 "u"
|
#define SCNuFAST16 __PRIFAST16 "u"
|
||||||
#define SCNuFAST32 __PRI32 "u"
|
#define SCNuFAST32 __PRIFAST32 "u"
|
||||||
#define SCNuFAST64 __PRI64 "u"
|
#define SCNuFAST64 __PRI64 "u"
|
||||||
#define SCNuFAST128 __PRI128 "u"
|
#define SCNuFAST128 __PRI128 "u"
|
||||||
|
|
||||||
|
@ -338,8 +352,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define SCNoLEAST128 __PRI128 "o"
|
#define SCNoLEAST128 __PRI128 "o"
|
||||||
|
|
||||||
#define SCNoFAST8 __PRI8 "o"
|
#define SCNoFAST8 __PRI8 "o"
|
||||||
#define SCNoFAST16 __PRI32 "o"
|
#define SCNoFAST16 __PRIFAST16 "o"
|
||||||
#define SCNoFAST32 __PRI32 "o"
|
#define SCNoFAST32 __PRIFAST32 "o"
|
||||||
#define SCNoFAST64 __PRI64 "o"
|
#define SCNoFAST64 __PRI64 "o"
|
||||||
#define SCNoFAST128 __PRI128 "o"
|
#define SCNoFAST128 __PRI128 "o"
|
||||||
|
|
||||||
|
@ -360,8 +374,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define SCNxLEAST128 __PRI128 "x"
|
#define SCNxLEAST128 __PRI128 "x"
|
||||||
|
|
||||||
#define SCNxFAST8 __PRI8 "x"
|
#define SCNxFAST8 __PRI8 "x"
|
||||||
#define SCNxFAST16 __PRI32 "x"
|
#define SCNxFAST16 __PRIFAST16 "x"
|
||||||
#define SCNxFAST32 __PRI32 "x"
|
#define SCNxFAST32 __PRIFAST32 "x"
|
||||||
#define SCNxFAST64 __PRI64 "x"
|
#define SCNxFAST64 __PRI64 "x"
|
||||||
#define SCNxFAST128 __PRI128 "x"
|
#define SCNxFAST128 __PRI128 "x"
|
||||||
|
|
||||||
|
@ -382,8 +396,8 @@ typedef __UINT_FAST64_TYPE__ uint_fast64_t;
|
||||||
#define SCNbLEAST128 __PRI128 "b"
|
#define SCNbLEAST128 __PRI128 "b"
|
||||||
|
|
||||||
#define SCNbFAST8 __PRI8 "b"
|
#define SCNbFAST8 __PRI8 "b"
|
||||||
#define SCNbFAST16 __PRI32 "b"
|
#define SCNbFAST16 __PRIFAST16 "b"
|
||||||
#define SCNbFAST32 __PRI32 "b"
|
#define SCNbFAST32 __PRIFAST32 "b"
|
||||||
#define SCNbFAST64 __PRI64 "b"
|
#define SCNbFAST64 __PRI64 "b"
|
||||||
#define SCNbFAST128 __PRI128 "b"
|
#define SCNbFAST128 __PRI128 "b"
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,9 @@ struct NtWin32FindData {
|
||||||
uint32_t dwReserved1;
|
uint32_t dwReserved1;
|
||||||
char16_t cFileName[260];
|
char16_t cFileName[260];
|
||||||
char16_t cAlternateFileName[14];
|
char16_t cAlternateFileName[14];
|
||||||
uint32_t dwFileType;
|
uint32_t dwFileType; /* obsolete */
|
||||||
uint32_t dwCreatorType;
|
uint32_t dwCreatorType; /* obsolete */
|
||||||
uint16_t wFinderFlags;
|
uint16_t wFinderFlags; /* obsolete */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
|
|
|
@ -16,18 +16,11 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/dce.h"
|
|
||||||
#include "libc/intrin/bits.h"
|
|
||||||
#include "libc/intrin/safemacros.internal.h"
|
|
||||||
#include "libc/nt/enum/fileflagandattributes.h"
|
|
||||||
#include "libc/nt/files.h"
|
|
||||||
#include "libc/nt/thunk/msabi.h"
|
|
||||||
#include "libc/runtime/internal.h"
|
#include "libc/runtime/internal.h"
|
||||||
|
#include "libc/stdio/sysparam.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/str/utf16.h"
|
#include "libc/str/utf16.h"
|
||||||
|
|
||||||
__msabi extern typeof(GetFileAttributes) *const __imp_GetFileAttributesW;
|
|
||||||
|
|
||||||
struct DosArgv {
|
struct DosArgv {
|
||||||
const char16_t *s;
|
const char16_t *s;
|
||||||
char *p;
|
char *p;
|
||||||
|
@ -143,7 +136,7 @@ textwindows int GetDosArgv(const char16_t *cmdline, char *buf, size_t size,
|
||||||
AppendDosArgv('\0', st);
|
AppendDosArgv('\0', st);
|
||||||
}
|
}
|
||||||
AppendDosArgv('\0', st);
|
AppendDosArgv('\0', st);
|
||||||
if (size) buf[min(st->p - buf, size - 1)] = '\0';
|
if (size) buf[MIN(st->p - buf, size - 1)] = '\0';
|
||||||
if (max) argv[min(argc, max - 1)] = NULL;
|
if (max) argv[MIN(argc, max - 1)] = NULL;
|
||||||
return argc;
|
return argc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/assert.h"
|
|
||||||
#include "libc/calls/struct/iovec.h"
|
#include "libc/calls/struct/iovec.h"
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
#include "libc/sock/internal.h"
|
#include "libc/sock/internal.h"
|
||||||
|
|
|
@ -185,6 +185,10 @@ static textwindows uint8_t GetNtDirentType(struct NtWin32FindData *w) {
|
||||||
|
|
||||||
static textwindows dontinline struct dirent *readdir_nt(DIR *dir) {
|
static textwindows dontinline struct dirent *readdir_nt(DIR *dir) {
|
||||||
TryAgain:
|
TryAgain:
|
||||||
|
while (!dir->isdone &&
|
||||||
|
(dir->windata.dwFileAttributes & kNtFileAttributeSystem)) {
|
||||||
|
dir->isdone = !FindNextFile(dir->hand, &dir->windata);
|
||||||
|
}
|
||||||
if (dir->isdone) {
|
if (dir->isdone) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ static const char gmt[] = "GMT";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct ttinfo { /* time type information */
|
struct ttinfo { /* time type information */
|
||||||
int_fast32_t tt_utoff; /* UT offset in seconds */
|
int32_t tt_utoff; /* UT offset in seconds */
|
||||||
bool tt_isdst; /* used to set tm_isdst */
|
bool tt_isdst; /* used to set tm_isdst */
|
||||||
int tt_desigidx; /* abbreviation list index */
|
int tt_desigidx; /* abbreviation list index */
|
||||||
bool tt_ttisstd; /* transition is std time */
|
bool tt_ttisstd; /* transition is std time */
|
||||||
|
@ -126,7 +126,7 @@ struct ttinfo { /* time type information */
|
||||||
|
|
||||||
struct lsinfo { /* leap second information */
|
struct lsinfo { /* leap second information */
|
||||||
time_t ls_trans; /* transition time */
|
time_t ls_trans; /* transition time */
|
||||||
int_fast32_t ls_corr; /* correction to apply */
|
int32_t ls_corr; /* correction to apply */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SMALLEST(a, b) (((a) < (b)) ? (a) : (b))
|
#define SMALLEST(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
|
@ -180,16 +180,16 @@ struct rule {
|
||||||
int r_day; /* day number of rule */
|
int r_day; /* day number of rule */
|
||||||
int r_week; /* week number of rule */
|
int r_week; /* week number of rule */
|
||||||
int r_mon; /* month number of rule */
|
int r_mon; /* month number of rule */
|
||||||
int_fast32_t r_time; /* transition time of rule */
|
int32_t r_time; /* transition time of rule */
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct tm *gmtsub(struct state const *, time_t const *, int_fast32_t,
|
static struct tm *gmtsub(struct state const *, time_t const *, int32_t,
|
||||||
struct tm *);
|
struct tm *);
|
||||||
static bool increment_overflow(int *, int);
|
static bool increment_overflow(int *, int);
|
||||||
static bool increment_overflow_time(time_t *, int_fast32_t);
|
static bool increment_overflow_time(time_t *, int32_t);
|
||||||
static int_fast32_t leapcorr(struct state const *, time_t);
|
static int32_t leapcorr(struct state const *, time_t);
|
||||||
static bool normalize_overflow32(int_fast32_t *, int *, int);
|
static bool normalize_overflow32(int32_t *, int *, int);
|
||||||
static struct tm *localtime_timesub(time_t const *, int_fast32_t,
|
static struct tm *localtime_timesub(time_t const *, int32_t,
|
||||||
struct state const *, struct tm *);
|
struct state const *, struct tm *);
|
||||||
static bool localtime_typesequiv(struct state const *, int, int);
|
static bool localtime_typesequiv(struct state const *, int, int);
|
||||||
static bool localtime_tzparse(char const *, struct state *, struct state *);
|
static bool localtime_tzparse(char const *, struct state *, struct state *);
|
||||||
|
@ -230,7 +230,7 @@ long altzone;
|
||||||
|
|
||||||
/* Initialize *S to a value based on UTOFF, ISDST, and DESIGIDX. */
|
/* Initialize *S to a value based on UTOFF, ISDST, and DESIGIDX. */
|
||||||
static void
|
static void
|
||||||
init_ttinfo(struct ttinfo *s, int_fast32_t utoff, bool isdst, int desigidx)
|
init_ttinfo(struct ttinfo *s, int32_t utoff, bool isdst, int desigidx)
|
||||||
{
|
{
|
||||||
s->tt_utoff = utoff;
|
s->tt_utoff = utoff;
|
||||||
s->tt_isdst = isdst;
|
s->tt_isdst = isdst;
|
||||||
|
@ -248,11 +248,11 @@ ttunspecified(struct state const *sp, int i)
|
||||||
return memcmp(abbr, UNSPEC, sizeof UNSPEC) == 0;
|
return memcmp(abbr, UNSPEC, sizeof UNSPEC) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline int_fast32_t detzcode(const char *const codep) {
|
forceinline int32_t detzcode(const char *const codep) {
|
||||||
return READ32BE(codep);
|
return READ32BE(codep);
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline int_fast64_t detzcode64(const char *const codep) {
|
forceinline int64_t detzcode64(const char *const codep) {
|
||||||
return READ64BE(codep);
|
return READ64BE(codep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,15 +429,15 @@ localtime_tzloadbody_(char const *name, struct state *sp, bool doextend,
|
||||||
for (stored = 4; stored <= 8; stored *= 2) {
|
for (stored = 4; stored <= 8; stored *= 2) {
|
||||||
char version = up->tzhead.tzh_version[0];
|
char version = up->tzhead.tzh_version[0];
|
||||||
bool skip_datablock = stored == 4 && version;
|
bool skip_datablock = stored == 4 && version;
|
||||||
int_fast32_t datablock_size;
|
int32_t datablock_size;
|
||||||
int_fast32_t ttisstdcnt = detzcode(up->tzhead.tzh_ttisstdcnt);
|
int32_t ttisstdcnt = detzcode(up->tzhead.tzh_ttisstdcnt);
|
||||||
int_fast32_t ttisutcnt = detzcode(up->tzhead.tzh_ttisutcnt);
|
int32_t ttisutcnt = detzcode(up->tzhead.tzh_ttisutcnt);
|
||||||
int_fast64_t prevtr = -1;
|
int64_t prevtr = -1;
|
||||||
int_fast32_t prevcorr = 0;
|
int32_t prevcorr = 0;
|
||||||
int_fast32_t leapcnt = detzcode(up->tzhead.tzh_leapcnt);
|
int32_t leapcnt = detzcode(up->tzhead.tzh_leapcnt);
|
||||||
int_fast32_t timecnt = detzcode(up->tzhead.tzh_timecnt);
|
int32_t timecnt = detzcode(up->tzhead.tzh_timecnt);
|
||||||
int_fast32_t typecnt = detzcode(up->tzhead.tzh_typecnt);
|
int32_t typecnt = detzcode(up->tzhead.tzh_typecnt);
|
||||||
int_fast32_t charcnt = detzcode(up->tzhead.tzh_charcnt);
|
int32_t charcnt = detzcode(up->tzhead.tzh_charcnt);
|
||||||
char const *p = up->buf + tzheadsize;
|
char const *p = up->buf + tzheadsize;
|
||||||
/* Although tzfile(5) currently requires typecnt to be nonzero,
|
/* Although tzfile(5) currently requires typecnt to be nonzero,
|
||||||
support future formats that may allow zero typecnt
|
support future formats that may allow zero typecnt
|
||||||
|
@ -476,7 +476,7 @@ localtime_tzloadbody_(char const *name, struct state *sp, bool doextend,
|
||||||
occurred at TIME_T_MIN. */
|
occurred at TIME_T_MIN. */
|
||||||
timecnt = 0;
|
timecnt = 0;
|
||||||
for (i = 0; i < sp->timecnt; ++i) {
|
for (i = 0; i < sp->timecnt; ++i) {
|
||||||
int_fast64_t at
|
int64_t at
|
||||||
= stored == 4 ? detzcode(p) : detzcode64(p);
|
= stored == 4 ? detzcode(p) : detzcode64(p);
|
||||||
sp->types[i] = at <= TIME_T_MAX;
|
sp->types[i] = at <= TIME_T_MAX;
|
||||||
if (sp->types[i]) {
|
if (sp->types[i]) {
|
||||||
|
@ -528,8 +528,8 @@ localtime_tzloadbody_(char const *name, struct state *sp, bool doextend,
|
||||||
/* Read leap seconds, discarding those out of time_t range. */
|
/* Read leap seconds, discarding those out of time_t range. */
|
||||||
leapcnt = 0;
|
leapcnt = 0;
|
||||||
for (i = 0; i < sp->leapcnt; ++i) {
|
for (i = 0; i < sp->leapcnt; ++i) {
|
||||||
int_fast64_t tr = stored == 4 ? detzcode(p) : detzcode64(p);
|
int64_t tr = stored == 4 ? detzcode(p) : detzcode64(p);
|
||||||
int_fast32_t corr = detzcode(p + stored);
|
int32_t corr = detzcode(p + stored);
|
||||||
p += stored + 4;
|
p += stored + 4;
|
||||||
|
|
||||||
/* Leap seconds cannot occur before the Epoch,
|
/* Leap seconds cannot occur before the Epoch,
|
||||||
|
@ -876,10 +876,10 @@ getnum(register const char *strp, int *const nump, const int min, const int max)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
getsecs(register const char *strp, int_fast32_t *const secsp)
|
getsecs(register const char *strp, int32_t *const secsp)
|
||||||
{
|
{
|
||||||
int num;
|
int num;
|
||||||
int_fast32_t secsperhour = SECSPERHOUR;
|
int32_t secsperhour = SECSPERHOUR;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** 'HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
|
** 'HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
|
||||||
|
@ -917,7 +917,7 @@ getsecs(register const char *strp, int_fast32_t *const secsp)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
getoffset(register const char *strp, int_fast32_t *const offsetp)
|
getoffset(register const char *strp, int32_t *const offsetp)
|
||||||
{
|
{
|
||||||
register bool neg = false;
|
register bool neg = false;
|
||||||
|
|
||||||
|
@ -992,12 +992,12 @@ getrule(const char *strp, register struct rule *const rulep)
|
||||||
** effect, calculate the year-relative time that rule takes effect.
|
** effect, calculate the year-relative time that rule takes effect.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int_fast32_t
|
static int32_t
|
||||||
transtime(const int year, register const struct rule *const rulep,
|
transtime(const int year, register const struct rule *const rulep,
|
||||||
const int_fast32_t offset)
|
const int32_t offset)
|
||||||
{
|
{
|
||||||
register bool leapyear;
|
register bool leapyear;
|
||||||
register int_fast32_t value;
|
register int32_t value;
|
||||||
register int i;
|
register int i;
|
||||||
int d, m1, yy0, yy1, yy2, dow;
|
int d, m1, yy0, yy1, yy2, dow;
|
||||||
|
|
||||||
|
@ -1092,8 +1092,8 @@ localtime_tzparse(const char *name, struct state *sp, struct state *basep)
|
||||||
size_t stdlen;
|
size_t stdlen;
|
||||||
size_t dstlen;
|
size_t dstlen;
|
||||||
size_t charcnt;
|
size_t charcnt;
|
||||||
int_fast32_t stdoffset;
|
int32_t stdoffset;
|
||||||
int_fast32_t dstoffset;
|
int32_t dstoffset;
|
||||||
register char * cp;
|
register char * cp;
|
||||||
register bool load_ok;
|
register bool load_ok;
|
||||||
time_t atlo = TIME_T_MIN, leaplo = TIME_T_MIN;
|
time_t atlo = TIME_T_MIN, leaplo = TIME_T_MIN;
|
||||||
|
@ -1163,7 +1163,7 @@ localtime_tzparse(const char *name, struct state *sp, struct state *basep)
|
||||||
register int year;
|
register int year;
|
||||||
register int timecnt;
|
register int timecnt;
|
||||||
time_t janfirst;
|
time_t janfirst;
|
||||||
int_fast32_t janoffset = 0;
|
int32_t janoffset = 0;
|
||||||
int yearbeg, yearlim;
|
int yearbeg, yearlim;
|
||||||
|
|
||||||
++name;
|
++name;
|
||||||
|
@ -1187,7 +1187,7 @@ localtime_tzparse(const char *name, struct state *sp, struct state *basep)
|
||||||
yearbeg = EPOCH_YEAR;
|
yearbeg = EPOCH_YEAR;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int_fast32_t yearsecs
|
int32_t yearsecs
|
||||||
= year_lengths[isleap(yearbeg - 1)] * SECSPERDAY;
|
= year_lengths[isleap(yearbeg - 1)] * SECSPERDAY;
|
||||||
yearbeg--;
|
yearbeg--;
|
||||||
if (increment_overflow_time(&janfirst, -yearsecs)) {
|
if (increment_overflow_time(&janfirst, -yearsecs)) {
|
||||||
|
@ -1198,7 +1198,7 @@ localtime_tzparse(const char *name, struct state *sp, struct state *basep)
|
||||||
&& EPOCH_YEAR - YEARSPERREPEAT / 2 < yearbeg);
|
&& EPOCH_YEAR - YEARSPERREPEAT / 2 < yearbeg);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int_fast32_t yearsecs
|
int32_t yearsecs
|
||||||
= year_lengths[isleap(yearbeg)] * SECSPERDAY;
|
= year_lengths[isleap(yearbeg)] * SECSPERDAY;
|
||||||
int yearbeg1 = yearbeg;
|
int yearbeg1 = yearbeg;
|
||||||
time_t janfirst1 = janfirst;
|
time_t janfirst1 = janfirst;
|
||||||
|
@ -1214,15 +1214,15 @@ localtime_tzparse(const char *name, struct state *sp, struct state *basep)
|
||||||
if (increment_overflow(&yearlim, YEARSPERREPEAT + 1))
|
if (increment_overflow(&yearlim, YEARSPERREPEAT + 1))
|
||||||
yearlim = INT_MAX;
|
yearlim = INT_MAX;
|
||||||
for (year = yearbeg; year < yearlim; year++) {
|
for (year = yearbeg; year < yearlim; year++) {
|
||||||
int_fast32_t
|
int32_t
|
||||||
starttime = transtime(year, &start, stdoffset),
|
starttime = transtime(year, &start, stdoffset),
|
||||||
endtime = transtime(year, &end, dstoffset);
|
endtime = transtime(year, &end, dstoffset);
|
||||||
int_fast32_t
|
int32_t
|
||||||
yearsecs = (year_lengths[isleap(year)]
|
yearsecs = (year_lengths[isleap(year)]
|
||||||
* SECSPERDAY);
|
* SECSPERDAY);
|
||||||
bool reversed = endtime < starttime;
|
bool reversed = endtime < starttime;
|
||||||
if (reversed) {
|
if (reversed) {
|
||||||
int_fast32_t swap = starttime;
|
int32_t swap = starttime;
|
||||||
starttime = endtime;
|
starttime = endtime;
|
||||||
endtime = swap;
|
endtime = swap;
|
||||||
}
|
}
|
||||||
|
@ -1263,9 +1263,9 @@ localtime_tzparse(const char *name, struct state *sp, struct state *basep)
|
||||||
} else if (YEARSPERREPEAT < year - yearbeg)
|
} else if (YEARSPERREPEAT < year - yearbeg)
|
||||||
sp->goback = sp->goahead = true;
|
sp->goback = sp->goahead = true;
|
||||||
} else {
|
} else {
|
||||||
register int_fast32_t theirstdoffset;
|
register int32_t theirstdoffset;
|
||||||
register int_fast32_t theirdstoffset;
|
register int32_t theirdstoffset;
|
||||||
register int_fast32_t theiroffset;
|
register int32_t theiroffset;
|
||||||
register bool isdst;
|
register bool isdst;
|
||||||
register int i;
|
register int i;
|
||||||
register int j;
|
register int j;
|
||||||
|
@ -1479,13 +1479,13 @@ localtime_gmtcheck(void)
|
||||||
** set the applicable parts of tzname, timezone and altzone;
|
** set the applicable parts of tzname, timezone and altzone;
|
||||||
** however, it's OK to omit this step if the timezone is POSIX-compatible,
|
** however, it's OK to omit this step if the timezone is POSIX-compatible,
|
||||||
** since in that case tzset should have already done this step correctly.
|
** since in that case tzset should have already done this step correctly.
|
||||||
** SETNAME's type is int_fast32_t for compatibility with gmtsub,
|
** SETNAME's type is int32_t for compatibility with gmtsub,
|
||||||
** but it is actually a boolean and its value should be 0 or 1.
|
** but it is actually a boolean and its value should be 0 or 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
static struct tm *
|
static struct tm *
|
||||||
localsub(struct state const *sp, time_t const *timep, int_fast32_t setname,
|
localsub(struct state const *sp, time_t const *timep, int32_t setname,
|
||||||
struct tm *const tmp)
|
struct tm *const tmp)
|
||||||
{
|
{
|
||||||
register const struct ttinfo * ttisp;
|
register const struct ttinfo * ttisp;
|
||||||
|
@ -1523,7 +1523,7 @@ localsub(struct state const *sp, time_t const *timep, int_fast32_t setname,
|
||||||
return NULL; /* "cannot happen" */
|
return NULL; /* "cannot happen" */
|
||||||
result = localsub(sp, &newt, setname, tmp);
|
result = localsub(sp, &newt, setname, tmp);
|
||||||
if (result) {
|
if (result) {
|
||||||
register int_fast64_t newy;
|
register int64_t newy;
|
||||||
|
|
||||||
newy = result->tm_year;
|
newy = result->tm_year;
|
||||||
if (t < sp->ats[0])
|
if (t < sp->ats[0])
|
||||||
|
@ -1595,7 +1595,7 @@ localtime_r(const time_t *timep, struct tm *tmp)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static struct tm *
|
static struct tm *
|
||||||
gmtsub(struct state const *sp, time_t const *timep, int_fast32_t offset,
|
gmtsub(struct state const *sp, time_t const *timep, int32_t offset,
|
||||||
struct tm *tmp)
|
struct tm *tmp)
|
||||||
{
|
{
|
||||||
register struct tm * result;
|
register struct tm * result;
|
||||||
|
@ -1655,15 +1655,15 @@ leaps_thru_end_of(time_t y)
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct tm *
|
static struct tm *
|
||||||
localtime_timesub(const time_t *timep, int_fast32_t offset,
|
localtime_timesub(const time_t *timep, int32_t offset,
|
||||||
const struct state *sp, struct tm *tmp)
|
const struct state *sp, struct tm *tmp)
|
||||||
{
|
{
|
||||||
register const struct lsinfo * lp;
|
register const struct lsinfo * lp;
|
||||||
register time_t tdays;
|
register time_t tdays;
|
||||||
register const int * ip;
|
register const int * ip;
|
||||||
register int_fast32_t corr;
|
register int32_t corr;
|
||||||
register int i;
|
register int i;
|
||||||
int_fast32_t idays, rem, dayoff, dayrem;
|
int32_t idays, rem, dayoff, dayrem;
|
||||||
time_t y;
|
time_t y;
|
||||||
|
|
||||||
/* If less than SECSPERMIN, the number of seconds since the
|
/* If less than SECSPERMIN, the number of seconds since the
|
||||||
|
@ -1709,7 +1709,7 @@ localtime_timesub(const time_t *timep, int_fast32_t offset,
|
||||||
/* Increase Y and decrease IDAYS until IDAYS is in range for Y. */
|
/* Increase Y and decrease IDAYS until IDAYS is in range for Y. */
|
||||||
while (year_lengths[isleap(y)] <= idays) {
|
while (year_lengths[isleap(y)] <= idays) {
|
||||||
int tdelta = idays / DAYSPERLYEAR;
|
int tdelta = idays / DAYSPERLYEAR;
|
||||||
int_fast32_t ydelta = tdelta + !tdelta;
|
int32_t ydelta = tdelta + !tdelta;
|
||||||
time_t newy = y + ydelta;
|
time_t newy = y + ydelta;
|
||||||
register int leapdays;
|
register int leapdays;
|
||||||
leapdays = leaps_thru_end_of(newy - 1) -
|
leapdays = leaps_thru_end_of(newy - 1) -
|
||||||
|
@ -1801,16 +1801,16 @@ increment_overflow(int *ip, int j)
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline bool
|
forceinline bool
|
||||||
increment_overflow32(int_fast32_t *const lp, int const m)
|
increment_overflow32(int32_t *const lp, int const m)
|
||||||
{
|
{
|
||||||
#if defined(__GNUC__) && __GNUC__ >= 6
|
#if defined(__GNUC__) && __GNUC__ >= 6
|
||||||
int_fast32_t i = *lp;
|
int32_t i = *lp;
|
||||||
if (__builtin_add_overflow(i, m, &i)) return true;
|
if (__builtin_add_overflow(i, m, &i)) return true;
|
||||||
*lp = i;
|
*lp = i;
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
register int_fast32_t const l = *lp;
|
register int32_t const l = *lp;
|
||||||
if ((l >= 0) ? (m > INT_FAST32_MAX - l) : (m < INT_FAST32_MIN - l))
|
if ((l >= 0) ? (m > INT32_MAX - l) : (m < INT32_MIN - l))
|
||||||
return true;
|
return true;
|
||||||
*lp += m;
|
*lp += m;
|
||||||
return false;
|
return false;
|
||||||
|
@ -1818,7 +1818,7 @@ increment_overflow32(int_fast32_t *const lp, int const m)
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline bool
|
forceinline bool
|
||||||
increment_overflow_time(time_t *tp, int_fast32_t j)
|
increment_overflow_time(time_t *tp, int32_t j)
|
||||||
{
|
{
|
||||||
#if defined(__GNUC__) && __GNUC__ >= 6
|
#if defined(__GNUC__) && __GNUC__ >= 6
|
||||||
time_t i = *tp;
|
time_t i = *tp;
|
||||||
|
@ -1853,7 +1853,7 @@ normalize_overflow(int *const tensptr, int *const unitsptr, const int base)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
normalize_overflow32(int_fast32_t *tensptr, int *unitsptr, int base)
|
normalize_overflow32(int32_t *tensptr, int *unitsptr, int base)
|
||||||
{
|
{
|
||||||
register int tensdelta;
|
register int tensdelta;
|
||||||
|
|
||||||
|
@ -1884,19 +1884,19 @@ static time_t
|
||||||
localtime_time2sub(
|
localtime_time2sub(
|
||||||
struct tm *const tmp,
|
struct tm *const tmp,
|
||||||
struct tm *(*funcp)(struct state const *, time_t const *,
|
struct tm *(*funcp)(struct state const *, time_t const *,
|
||||||
int_fast32_t, struct tm *),
|
int32_t, struct tm *),
|
||||||
struct state const *sp,
|
struct state const *sp,
|
||||||
const int_fast32_t offset,
|
const int32_t offset,
|
||||||
bool *okayp,
|
bool *okayp,
|
||||||
bool do_norm_secs)
|
bool do_norm_secs)
|
||||||
{
|
{
|
||||||
register int dir;
|
register int dir;
|
||||||
register int i, j;
|
register int i, j;
|
||||||
register int saved_seconds;
|
register int saved_seconds;
|
||||||
register int_fast32_t li;
|
register int32_t li;
|
||||||
register time_t lo;
|
register time_t lo;
|
||||||
register time_t hi;
|
register time_t hi;
|
||||||
int_fast32_t y;
|
int32_t y;
|
||||||
time_t newt;
|
time_t newt;
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm yourtm, mytm;
|
struct tm yourtm, mytm;
|
||||||
|
@ -2011,10 +2011,10 @@ localtime_time2sub(
|
||||||
&& (yourtm.TM_GMTOFF < 0
|
&& (yourtm.TM_GMTOFF < 0
|
||||||
? (-SECSPERDAY <= yourtm.TM_GMTOFF
|
? (-SECSPERDAY <= yourtm.TM_GMTOFF
|
||||||
&& (mytm.TM_GMTOFF <=
|
&& (mytm.TM_GMTOFF <=
|
||||||
(SMALLEST(INT_FAST32_MAX, LONG_MAX)
|
(SMALLEST(INT32_MAX, LONG_MAX)
|
||||||
+ yourtm.TM_GMTOFF)))
|
+ yourtm.TM_GMTOFF)))
|
||||||
: (yourtm.TM_GMTOFF <= SECSPERDAY
|
: (yourtm.TM_GMTOFF <= SECSPERDAY
|
||||||
&& ((BIGGEST(INT_FAST32_MIN, LONG_MIN)
|
&& ((BIGGEST(INT32_MIN, LONG_MIN)
|
||||||
+ yourtm.TM_GMTOFF)
|
+ yourtm.TM_GMTOFF)
|
||||||
<= mytm.TM_GMTOFF)))) {
|
<= mytm.TM_GMTOFF)))) {
|
||||||
/* MYTM matches YOURTM except with the wrong UT offset.
|
/* MYTM matches YOURTM except with the wrong UT offset.
|
||||||
|
@ -2022,7 +2022,7 @@ localtime_time2sub(
|
||||||
It's OK if YOURTM.TM_GMTOFF contains uninitialized data,
|
It's OK if YOURTM.TM_GMTOFF contains uninitialized data,
|
||||||
since the guess gets checked. */
|
since the guess gets checked. */
|
||||||
time_t altt = t;
|
time_t altt = t;
|
||||||
int_fast32_t diff = mytm.TM_GMTOFF - yourtm.TM_GMTOFF;
|
int32_t diff = mytm.TM_GMTOFF - yourtm.TM_GMTOFF;
|
||||||
if (!increment_overflow_time(&altt, diff)) {
|
if (!increment_overflow_time(&altt, diff)) {
|
||||||
struct tm alttm;
|
struct tm alttm;
|
||||||
if (funcp(sp, &altt, offset, &alttm)
|
if (funcp(sp, &altt, offset, &alttm)
|
||||||
|
@ -2084,9 +2084,9 @@ static time_t
|
||||||
localtime_time2(
|
localtime_time2(
|
||||||
struct tm * const tmp,
|
struct tm * const tmp,
|
||||||
struct tm *(*funcp)(struct state const *, time_t const *,
|
struct tm *(*funcp)(struct state const *, time_t const *,
|
||||||
int_fast32_t, struct tm *),
|
int32_t, struct tm *),
|
||||||
struct state const *sp,
|
struct state const *sp,
|
||||||
const int_fast32_t offset,
|
const int32_t offset,
|
||||||
bool *okayp)
|
bool *okayp)
|
||||||
{
|
{
|
||||||
time_t t;
|
time_t t;
|
||||||
|
@ -2104,9 +2104,9 @@ static time_t
|
||||||
localtime_time1(
|
localtime_time1(
|
||||||
struct tm *const tmp,
|
struct tm *const tmp,
|
||||||
struct tm *(*funcp)(struct state const *, time_t const *,
|
struct tm *(*funcp)(struct state const *, time_t const *,
|
||||||
int_fast32_t, struct tm *),
|
int32_t, struct tm *),
|
||||||
struct state const *sp,
|
struct state const *sp,
|
||||||
const int_fast32_t offset)
|
const int32_t offset)
|
||||||
{
|
{
|
||||||
register time_t t;
|
register time_t t;
|
||||||
register int samei, otheri;
|
register int samei, otheri;
|
||||||
|
@ -2218,7 +2218,7 @@ timeoff(struct tm *tmp, long offset)
|
||||||
return localtime_time1(tmp, gmtsub, gmtptr, offset);
|
return localtime_time1(tmp, gmtsub, gmtptr, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int_fast32_t
|
static int32_t
|
||||||
leapcorr(struct state const *sp, time_t t)
|
leapcorr(struct state const *sp, time_t t)
|
||||||
{
|
{
|
||||||
register struct lsinfo const * lp;
|
register struct lsinfo const * lp;
|
||||||
|
|
|
@ -487,12 +487,12 @@ char *ctime_r(int64_t const *, char *);
|
||||||
#define DAYSPERNYEAR 365
|
#define DAYSPERNYEAR 365
|
||||||
#define DAYSPERLYEAR 366
|
#define DAYSPERLYEAR 366
|
||||||
#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
|
#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
|
||||||
#define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
|
#define SECSPERDAY ((int32_t) SECSPERHOUR * HOURSPERDAY)
|
||||||
#define MONSPERYEAR 12
|
#define MONSPERYEAR 12
|
||||||
|
|
||||||
#define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
|
#define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
|
||||||
#define DAYSPERREPEAT ((int_fast32_t) 400 * 365 + 100 - 4 + 1)
|
#define DAYSPERREPEAT ((int32_t) 400 * 365 + 100 - 4 + 1)
|
||||||
#define SECSPERREPEAT ((int_fast64_t) DAYSPERREPEAT * SECSPERDAY)
|
#define SECSPERREPEAT ((int64_t) DAYSPERREPEAT * SECSPERDAY)
|
||||||
#define AVGSECSPERYEAR (SECSPERREPEAT / YEARSPERREPEAT)
|
#define AVGSECSPERYEAR (SECSPERREPEAT / YEARSPERREPEAT)
|
||||||
|
|
||||||
#define TM_SUNDAY 0
|
#define TM_SUNDAY 0
|
||||||
|
|
Loading…
Reference in a new issue