mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-15 23:29:56 +00:00
Make improvements
- Invent openatemp() API - Invent O_UNLINK open flag - Introduce getenv_secure() API - Remove `git pull` from cosmocc - Fix utimes() when path is NULL - Fix mktemp() to never return NULL - Fix utimensat() UTIME_OMIT on XNU - Improve utimensat() code for RHEL5 - Turn `argv[0]` C:/ to /C/ on Windows - Introduce tmpnam() and tmpnam_r() APIs - Fix more const issues with internal APIs - Permit utimes() on WIN32 in O_RDONLY mode - Fix fdopendir() to check fd is a directory - Fix recent crash regression in landlock make - Fix futimens(AT_FDCWD, NULL) to return EBADF - Use workaround so `make -j` doesn't fork bomb - Rename dontdiscard to __wur (just like glibc) - Fix st_size for WIN32 symlinks containing UTF-8 - Introduce stdio ext APIs needed by GNU coreutils - Fix lstat() on WIN32 for symlinks to directories - Move some constants from normalize.inc to limits.h - Fix segv with memchr() and memcmp() overlapping page - Implement POSIX fflush() behavior for reader streams - Implement AT_SYMLINK_NOFOLLOW for utimensat() on WIN32 - Don't change read-only status of existing files on WIN32 - Correctly handle `0x[^[:xdigit:]]` case in strtol() functions
This commit is contained in:
parent
8596e83cce
commit
f531acc8f9
297 changed files with 1920 additions and 1681 deletions
|
@ -44,7 +44,7 @@ TEST(clock_gettime, test) {
|
|||
#ifndef __aarch64__
|
||||
bool isfast;
|
||||
// we support vdso on aarch64 but qemu-aarch64 won't let us test it
|
||||
if (__is_linux_2_6_23()) {
|
||||
if (IsLinux() && __is_linux_2_6_23()) {
|
||||
ASSERT_GT((intptr_t)__clock_gettime_get(&isfast),
|
||||
getauxval(AT_SYSINFO_EHDR));
|
||||
ASSERT_TRUE(isfast);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/temp.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/subprocess.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
@ -69,8 +69,8 @@ TEST(execve, testArgPassing) {
|
|||
}
|
||||
|
||||
TEST(execve, ziposELF) {
|
||||
if (IsFreebsd()) return; // TODO: fixme on freebsd
|
||||
if (!__is_linux_2_6_23()) return; // TODO: fixme on old linux
|
||||
if (IsFreebsd()) return; // TODO: fixme on freebsd
|
||||
if (IsLinux() && !__is_linux_2_6_23()) return; // TODO: fixme on old linux
|
||||
if (!IsLinux() && !IsFreebsd()) {
|
||||
EXPECT_SYS(ENOSYS, -1,
|
||||
execve("/zip/life.elf", (char *const[]){0}, (char *const[]){0}));
|
||||
|
@ -83,8 +83,8 @@ TEST(execve, ziposELF) {
|
|||
}
|
||||
|
||||
TEST(execve, ziposAPE) {
|
||||
if (IsFreebsd()) return; // TODO: fixme on freebsd
|
||||
if (!__is_linux_2_6_23()) return; // TODO: fixme on old linux
|
||||
if (IsFreebsd()) return; // TODO: fixme on freebsd
|
||||
if (IsLinux() && !__is_linux_2_6_23()) return; // TODO: fixme on old linux
|
||||
if (!IsLinux() && !IsFreebsd()) {
|
||||
EXPECT_EQ(-1, execve("/zip/life-nomod.com", (char *const[]){0},
|
||||
(char *const[]){0}));
|
||||
|
|
|
@ -37,7 +37,7 @@ char testlib_enable_tmp_setup_teardown;
|
|||
|
||||
void SetUp(void) {
|
||||
if (IsFreebsd()) exit(0); // TODO: fixme on freebsd
|
||||
if (!__is_linux_2_6_23()) exit(0); // TODO: fixme on old linux
|
||||
if (IsLinux() && !__is_linux_2_6_23()) exit(0); // TODO: fixme on old linux
|
||||
}
|
||||
|
||||
TEST(execve, elfIsUnreadable_mayBeExecuted) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/libgen.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
@ -26,7 +28,12 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
#include "libc/sysv/consts/fd.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/testlib/subprocess.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "libc/x/xasprintf.h"
|
||||
|
@ -36,7 +43,7 @@
|
|||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
void SetUpOnce(void) {
|
||||
ASSERT_SYS(0, 0, pledge("stdio rpath wpath cpath fattr", 0));
|
||||
ASSERT_SYS(0, 0, pledge("stdio rpath wpath cpath fattr proc id", 0));
|
||||
}
|
||||
|
||||
TEST(open, efault) {
|
||||
|
@ -72,6 +79,18 @@ TEST(open, doubleSlash_worksAndGetsNormalizedOnWindows) {
|
|||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(open, fdWillBeInheritedByExecutedPrograms) {
|
||||
ASSERT_SYS(0, 3, open("x", O_RDWR | O_CREAT | O_TRUNC, 0666));
|
||||
ASSERT_SYS(0, 0, fcntl(3, F_GETFD));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(open, fdWillBeClosedByExecveAutomatically) {
|
||||
ASSERT_SYS(0, 3, open("x", O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0666));
|
||||
ASSERT_SYS(0, FD_CLOEXEC, fcntl(3, F_GETFD));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(open, enametoolong) {
|
||||
size_t n = 260;
|
||||
char *s = gc(xcalloc(1, n + 1));
|
||||
|
@ -320,3 +339,159 @@ TEST(open, drive) {
|
|||
ASSERT_SYS(0, 3, open("/", O_RDONLY));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(open, readOnlyCreatMode) {
|
||||
char buf[8];
|
||||
struct stat st;
|
||||
ASSERT_SYS(0, 3, open("x", O_RDWR | O_CREAT | O_TRUNC, 0500));
|
||||
ASSERT_SYS(0, 2, pwrite(3, "hi", 2, 0));
|
||||
ASSERT_SYS(0, 2, pread(3, buf, 8, 0));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
ASSERT_SYS(0, 0, stat("x", &st));
|
||||
ASSERT_EQ(0100500, st.st_mode);
|
||||
if (getuid()) {
|
||||
ASSERT_SYS(EACCES, -1, open("x", O_RDWR));
|
||||
ASSERT_SYS(EACCES, -1, open("x", O_RDWR | O_CREAT));
|
||||
} else {
|
||||
// root is invulnerable to eacces
|
||||
ASSERT_SYS(0, 3, open("x", O_RDWR));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
ASSERT_SYS(0, 3, open("x", O_RDWR | O_CREAT));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
SPAWN(fork);
|
||||
setuid(1000);
|
||||
setgid(1000);
|
||||
ASSERT_SYS(EACCES, -1, open("x", O_RDWR));
|
||||
ASSERT_SYS(EACCES, -1, open("x", O_RDWR | O_CREAT));
|
||||
EXITS(0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(open, parentSymlink) {
|
||||
struct stat st;
|
||||
ASSERT_SYS(0, 0, mkdir("parent", 0755));
|
||||
// create directory symlink
|
||||
ASSERT_SYS(0, 0, symlink("parent", "parent-link"));
|
||||
// test the symlink we just made is a symlink
|
||||
ASSERT_SYS(0, 0, lstat("parent-link", &st));
|
||||
ASSERT_TRUE(S_ISLNK(st.st_mode));
|
||||
// create regular file when parent component is symlink dir
|
||||
ASSERT_SYS(0, 0, touch("parent-link/regular", 0644));
|
||||
// test stat works
|
||||
ASSERT_SYS(0, 0, stat("parent-link/regular", &st));
|
||||
ASSERT_TRUE(S_ISREG(st.st_mode));
|
||||
// test open works
|
||||
ASSERT_SYS(0, 3, open("parent-link/regular", O_RDONLY));
|
||||
ASSERT_SYS(0, 0, fstat(3, &st));
|
||||
ASSERT_TRUE(S_ISREG(st.st_mode));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
// test O_NOFOLLOW doesn't apply to parent components
|
||||
ASSERT_SYS(0, 3, open("parent-link/regular", O_RDONLY | O_NOFOLLOW));
|
||||
ASSERT_SYS(0, 0, fstat(3, &st));
|
||||
ASSERT_TRUE(S_ISREG(st.st_mode));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
// create regular symlink
|
||||
ASSERT_SYS(0, 0, symlink("regular", "parent-link/regular-link"));
|
||||
// test stat works
|
||||
ASSERT_SYS(0, 0, stat("parent-link/regular-link", &st));
|
||||
ASSERT_TRUE(S_ISREG(st.st_mode));
|
||||
ASSERT_SYS(0, 0, lstat("parent-link/regular-link", &st));
|
||||
ASSERT_TRUE(S_ISLNK(st.st_mode));
|
||||
// test open works
|
||||
ASSERT_SYS(0, 3, open("parent-link/regular-link", O_RDONLY));
|
||||
ASSERT_SYS(0, 0, fstat(3, &st));
|
||||
ASSERT_TRUE(S_ISREG(st.st_mode));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
// test O_NOFOLLOW applies to last component
|
||||
ASSERT_SYS(ELOOP, -1,
|
||||
open("parent-link/regular-link", O_RDONLY | O_NOFOLLOW));
|
||||
}
|
||||
|
||||
TEST(open, readonlyCreateMode_dontChangeStatusIfExists) {
|
||||
char buf[8];
|
||||
struct stat st;
|
||||
ASSERT_SYS(0, 3, creat("wut", 0700));
|
||||
ASSERT_SYS(0, 2, pwrite(3, "hi", 2, 0));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
// since the file already exists, unix doesn't change read-only
|
||||
ASSERT_SYS(0, 3, open("wut", O_CREAT | O_TRUNC | O_RDWR, 0500));
|
||||
ASSERT_SYS(0, 0, pread(3, buf, 8, 0));
|
||||
ASSERT_SYS(0, 0, fstat(3, &st));
|
||||
ASSERT_EQ(0100700, st.st_mode);
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(open, creatRdonly) {
|
||||
char buf[8];
|
||||
ASSERT_SYS(EINVAL, -1, open("foo", O_CREAT | O_TRUNC | O_RDONLY, 0700));
|
||||
ASSERT_SYS(0, 3, open("foo", O_CREAT | O_RDONLY, 0700));
|
||||
ASSERT_SYS(EBADF, -1, pwrite(3, "hi", 2, 0));
|
||||
ASSERT_SYS(0, 0, pread(3, buf, 8, 0));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(open, sequentialRandom_EINVAL) {
|
||||
if (!IsWindows()) return;
|
||||
ASSERT_SYS(
|
||||
EINVAL, -1,
|
||||
open("foo", O_CREAT | O_TRUNC | O_RDWR | O_SEQUENTIAL | O_RANDOM, 0700));
|
||||
}
|
||||
|
||||
// "If O_CREAT is set and the file did not previously exist, upon
|
||||
// successful completion, open() shall mark for update the last data
|
||||
// access, last data modification, and last file status change
|
||||
// timestamps of the file and the last data modification and last
|
||||
// file status change timestamps of the parent directory." -POSIX
|
||||
TEST(open, creatFile_touchesDirectory) {
|
||||
struct stat st;
|
||||
struct timespec birth;
|
||||
ASSERT_SYS(0, 0, mkdir("dir", 0755));
|
||||
ASSERT_SYS(0, 0, stat("dir", &st));
|
||||
birth = st.st_ctim;
|
||||
// check we can read time without changing it
|
||||
sleep(1);
|
||||
ASSERT_SYS(0, 0, stat("dir", &st));
|
||||
EXPECT_EQ(0, timespec_cmp(st.st_ctim, birth));
|
||||
EXPECT_EQ(0, timespec_cmp(st.st_mtim, birth));
|
||||
EXPECT_EQ(0, timespec_cmp(st.st_atim, birth));
|
||||
// check that the directory time changes when file is made
|
||||
sleep(1);
|
||||
ASSERT_SYS(0, 0, touch("dir/file", 0644));
|
||||
ASSERT_SYS(0, 0, stat("dir", &st));
|
||||
EXPECT_EQ(1, timespec_cmp(st.st_ctim, birth));
|
||||
EXPECT_EQ(1, timespec_cmp(st.st_mtim, birth));
|
||||
// TODO: Maybe statfs() for noatime / relative?
|
||||
// EXPECT_EQ(1, timespec_cmp(st.st_atim, birth));
|
||||
}
|
||||
|
||||
// "If O_TRUNC is set and the file did previously exist, upon successful
|
||||
// completion, open() shall mark for update the last data modification
|
||||
// and last file status change timestamps of the file." -POSIX
|
||||
TEST(open, trunc_touchesMtimCtim) {
|
||||
struct stat st;
|
||||
struct timespec birth;
|
||||
ASSERT_SYS(0, 0, touch("regular", 0755));
|
||||
ASSERT_SYS(0, 0, stat("regular", &st));
|
||||
birth = st.st_ctim;
|
||||
sleep(1);
|
||||
ASSERT_SYS(0, 3, open("regular", O_RDWR | O_TRUNC));
|
||||
ASSERT_SYS(0, 0, fstat(3, &st));
|
||||
EXPECT_EQ(1, timespec_cmp(st.st_ctim, birth));
|
||||
EXPECT_EQ(1, timespec_cmp(st.st_mtim, birth));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(open, mereOpen_doesntTouch) {
|
||||
struct stat st;
|
||||
struct timespec birth;
|
||||
ASSERT_SYS(0, 0, touch("regular", 0755));
|
||||
ASSERT_SYS(0, 0, stat("regular", &st));
|
||||
birth = st.st_ctim;
|
||||
sleep(1);
|
||||
ASSERT_SYS(0, 3, open("regular", O_RDWR));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
ASSERT_SYS(0, 0, stat("regular", &st));
|
||||
EXPECT_EQ(0, timespec_cmp(st.st_ctim, birth));
|
||||
EXPECT_EQ(0, timespec_cmp(st.st_mtim, birth));
|
||||
EXPECT_EQ(0, timespec_cmp(st.st_atim, birth));
|
||||
}
|
||||
|
|
115
test/libc/calls/openatemp_test.c
Normal file
115
test/libc/calls/openatemp_test.c
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/temp.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
TEST(openatemp, test) {
|
||||
char path[] = "foo.XXXXXX";
|
||||
ASSERT_SYS(0, 3, openatemp(AT_FDCWD, path, 0, O_CLOEXEC, 0));
|
||||
ASSERT_NE(0, strcmp(path, "foo.XXXXXX"));
|
||||
EXPECT_TRUE(fileexists(path));
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(openatemp, dirfd) {
|
||||
ASSERT_SYS(0, 3, open(kTmpPath, O_RDONLY | O_DIRECTORY));
|
||||
char path[] = "foo.XXXXXX.txt";
|
||||
ASSERT_SYS(0, 4, openatemp(3, path, 4, 0, 0));
|
||||
EXPECT_TRUE(fileexists(gc(xjoinpaths(kTmpPath, path))));
|
||||
EXPECT_SYS(0, 0, close(4));
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(openatemp, unlink) {
|
||||
char path[] = "foo.XXXXXX";
|
||||
ASSERT_SYS(0, 3, openatemp(AT_FDCWD, path, 0, O_UNLINK, 0));
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
EXPECT_FALSE(fileexists(path));
|
||||
}
|
||||
|
||||
TEST(openatemp, mode) {
|
||||
if (IsWindows()) return;
|
||||
unsigned omask = umask(0);
|
||||
char path[] = "foo.XXXXXX";
|
||||
ASSERT_SYS(0, 3, openatemp(AT_FDCWD, path, 0, 0, 0764));
|
||||
struct stat st;
|
||||
ASSERT_SYS(0, 0, stat(path, &st));
|
||||
ASSERT_SYS(0, 0, fstat(3, &st));
|
||||
EXPECT_EQ(0100764, st.st_mode);
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
umask(omask);
|
||||
}
|
||||
|
||||
TEST(openatemp, tooFewX_EINVAL) {
|
||||
char path[] = "foo.XXXXX";
|
||||
ASSERT_SYS(EINVAL, -1, openatemp(AT_FDCWD, path, 0, O_CLOEXEC, 0));
|
||||
}
|
||||
|
||||
TEST(openatemp, suffixTooFewX_EINVAL) {
|
||||
char path[] = "foo.XXXXX.txt";
|
||||
ASSERT_SYS(EINVAL, -1, openatemp(AT_FDCWD, path, 4, O_CLOEXEC, 0));
|
||||
}
|
||||
|
||||
TEST(openatemp, badSuffixLen_EINVAL) {
|
||||
char path[] = "foo.XXXXXX";
|
||||
ASSERT_SYS(EINVAL, -1, openatemp(AT_FDCWD, path, -1, O_CLOEXEC, 0));
|
||||
ASSERT_SYS(EINVAL, -1, openatemp(AT_FDCWD, path, -6, O_CLOEXEC, 0));
|
||||
ASSERT_SYS(EINVAL, -1, openatemp(AT_FDCWD, path, 11, O_CLOEXEC, 0));
|
||||
ASSERT_SYS(EINVAL, -1, openatemp(AT_FDCWD, path, 99, O_CLOEXEC, 0));
|
||||
}
|
||||
|
||||
TEST(openatemp, missingDir_ENOENT) {
|
||||
char path[] = "missing/foo.XXXXXX";
|
||||
ASSERT_SYS(ENOENT, -1, openatemp(AT_FDCWD, path, 0, O_CLOEXEC, 0));
|
||||
}
|
||||
|
||||
TEST(openatemp, notDir_ENOTDIR) {
|
||||
char path[] = "regular/foo.XXXXXX";
|
||||
ASSERT_SYS(0, 0, touch("regular", 0644));
|
||||
ASSERT_SYS(ENOTDIR, -1, openatemp(AT_FDCWD, path, 0, O_CLOEXEC, 0));
|
||||
}
|
||||
|
||||
TEST(mktemp, fails_returnsEmptyString) {
|
||||
char path[] = "regular/foo.XXXXXX";
|
||||
ASSERT_SYS(0, 0, touch("regular", 0644));
|
||||
ASSERT_STREQ("", mktemp(path));
|
||||
ASSERT_STREQ("", path);
|
||||
ASSERT_EQ(ENOTDIR, errno);
|
||||
errno = 0;
|
||||
}
|
||||
|
||||
TEST(mkstemp, fails_returnsNull) {
|
||||
char path[] = "regular/foo.XXXXXX";
|
||||
ASSERT_SYS(0, 0, touch("regular", 0644));
|
||||
ASSERT_SYS(ENOTDIR, -1, mkstemp(path));
|
||||
ASSERT_STREQ("regular/foo.XXXXXX", path);
|
||||
}
|
|
@ -28,8 +28,8 @@
|
|||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
void CheckPlatform(void) {
|
||||
if (IsOpenbsd()) return;
|
||||
if (__is_linux_2_6_23()) return;
|
||||
if (IsOpenbsd()) return; // openbsd is ok
|
||||
if (IsLinux() && __is_linux_2_6_23()) return; // non-ancient linux is ok
|
||||
kprintf("skipping openbsd_test\n");
|
||||
exit(0);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ void OnSig(int sig) {
|
|||
gotsig = true;
|
||||
}
|
||||
|
||||
dontdiscard char *FormatPollFd(struct pollfd p[2]) {
|
||||
__wur char *FormatPollFd(struct pollfd p[2]) {
|
||||
return xasprintf("fd:%d revents:%s\n"
|
||||
"fd:%d revents:%s\n",
|
||||
p[0].fd, "<TODO:kPollNames>", p[1].fd, "<TODO:kPollNames>");
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
|
@ -96,10 +97,10 @@ TEST(readlinkat, frootloop) {
|
|||
|
||||
TEST(readlinkat, statReadsNameLength) {
|
||||
struct stat st;
|
||||
ASSERT_SYS(0, 0, symlink("froot", "froot"));
|
||||
ASSERT_SYS(0, 0, fstatat(AT_FDCWD, "froot", &st, AT_SYMLINK_NOFOLLOW));
|
||||
ASSERT_SYS(0, 0, symlink("froÒt", "froÒt"));
|
||||
ASSERT_SYS(0, 0, fstatat(AT_FDCWD, "froÒt", &st, AT_SYMLINK_NOFOLLOW));
|
||||
EXPECT_TRUE(S_ISLNK(st.st_mode));
|
||||
EXPECT_EQ(5, st.st_size);
|
||||
EXPECT_EQ(6, st.st_size);
|
||||
}
|
||||
|
||||
TEST(readlinkat, realpathReturnsLongPath) {
|
||||
|
|
|
@ -75,7 +75,7 @@ TEST(reservefd, testGrowthOfFdsDataStructure) {
|
|||
for (i = 0; i < n; ++i) {
|
||||
ASSERT_SYS(0, i + 3, open("/zip/usr/share/zoneinfo/UTC", O_RDONLY));
|
||||
}
|
||||
ASSERT_GT(g_fds.n, OPEN_MAX);
|
||||
ASSERT_GT(g_fds.n, 16);
|
||||
for (i = 0; i < n; ++i) {
|
||||
ASSERT_SYS(0, 0, close(i + 3));
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ bool CanUseSeccomp(void) {
|
|||
}
|
||||
|
||||
void SetUp(void) {
|
||||
if (!__is_linux_2_6_23() || !CanUseSeccomp()) {
|
||||
if (!IsLinux() || !__is_linux_2_6_23() || !CanUseSeccomp()) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/directmap.internal.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/sysv/consts/auxv.h"
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
|
|
|
@ -18,11 +18,13 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/struct/stat.macros.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/utime.h"
|
||||
|
@ -70,15 +72,6 @@ TEST(futimes, test) {
|
|||
EXPECT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(futimes, rhel5_enosys) {
|
||||
if (IsLinux() && !__is_linux_2_6_23()) {
|
||||
struct timeval tv[2] = {{1655455857}, {827727928}};
|
||||
EXPECT_SYS(0, 3, creat("boop", 0644));
|
||||
EXPECT_SYS(ENOSYS, -1, futimes(3, tv));
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(utimensat, test) {
|
||||
struct stat st;
|
||||
struct timespec ts[2] = {
|
||||
|
@ -127,3 +120,39 @@ TEST(utimensat, testOmit) {
|
|||
EXPECT_NE(123, st.st_atim.tv_sec);
|
||||
EXPECT_NE(123, st.st_mtim.tv_sec);
|
||||
}
|
||||
|
||||
TEST(futimens, test2) {
|
||||
struct timespec ts[2];
|
||||
int fd = creat("foo", 0600);
|
||||
if (fd < 0) exit(1);
|
||||
struct stat st;
|
||||
int64_t birth;
|
||||
ASSERT_SYS(0, 0, fstat(fd, &st));
|
||||
ASSERT_EQ(st.st_ctime, st.st_atime);
|
||||
ASSERT_EQ(st.st_ctime, st.st_mtime);
|
||||
birth = st.st_ctime;
|
||||
ts[0].tv_sec = 1;
|
||||
ts[0].tv_nsec = UTIME_OMIT;
|
||||
ts[1].tv_sec = 1;
|
||||
ts[1].tv_nsec = UTIME_NOW;
|
||||
errno = 0;
|
||||
ASSERT_SYS(EBADF, -1, futimens(AT_FDCWD, NULL));
|
||||
ASSERT_SYS(0, 0, futimens(fd, ts));
|
||||
sleep(1);
|
||||
ts[0].tv_nsec = UTIME_NOW; // change access time
|
||||
ts[1].tv_nsec = UTIME_OMIT; // don't change modified time
|
||||
close(fd);
|
||||
fd = open("foo", O_RDONLY);
|
||||
ASSERT_SYS(0, 0, futimens(fd, ts));
|
||||
ASSERT_SYS(0, 0, fstat(fd, &st));
|
||||
// check time of last status change equals access time
|
||||
ASSERT_GT(st.st_atime, birth);
|
||||
ASSERT_EQ(st.st_mtime, birth);
|
||||
// NetBSD doesn't appear to change ctime even though it says it does
|
||||
if (!IsNetbsd()) {
|
||||
ASSERT_GT(st.st_ctime, birth);
|
||||
ASSERT_EQ(st.st_ctime, st.st_atime);
|
||||
ASSERT_GT(st.st_ctime, st.st_mtime);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue