Skip to content

Commit

Permalink
Release Cosmopolitan v3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Nov 29, 2023
1 parent 41c06c6 commit b7e1dc8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion libc/integral/normalize.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#define __COSMOPOLITAN_MAJOR__ 3
#define __COSMOPOLITAN_MINOR__ 1
#define __COSMOPOLITAN_PATCH__ 0
#define __COSMOPOLITAN_PATCH__ 1
#define __COSMOPOLITAN__ \
(100000000 * __COSMOPOLITAN_MAJOR__ + 1000000 * __COSMOPOLITAN_MINOR__ + \
__COSMOPOLITAN_PATCH__)
Expand Down
41 changes: 21 additions & 20 deletions test/libc/calls/fchmodat_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,54 @@
│ 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/macros.internal.h"
#include "libc/sysv/consts/s.h"
// #include "libc/mem/gc.internal.h"
#include "libc/calls/struct/stat.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/s.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"

void SetUpOnce(void) {
testlib_enable_tmp_setup_teardown();
// ASSERT_SYS(0, 0, pledge("stdio rpath wpath cpath", 0));
}

static void ExpectMode(const char *filename, uint32_t mode) {
struct stat st;
ASSERT_SYS(0, 0, fstatat(AT_FDCWD, filename, &st, AT_SYMLINK_NOFOLLOW));
ASSERT_TRUE((st.st_mode & 0777) == mode);
ASSERT_SYS(0, 0, pledge("stdio rpath wpath cpath fattr", 0));
}

TEST(fchmodat, testFchmodat) {
if (IsWindows()) return; // not advanced enough yet
struct stat st;
umask(022);
ASSERT_SYS(0, 3,
open("regfile", O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, 0644));
ASSERT_SYS(0, 0, close(3));
ASSERT_SYS(0, 0, symlink("regfile", "symlink"));
ExpectMode("regfile", 0644);
struct stat st;
ASSERT_SYS(0, 0, fstatat(AT_FDCWD, "regfile", &st, AT_SYMLINK_NOFOLLOW));
ASSERT_EQ(0644, st.st_mode & 0777);
ASSERT_SYS(0, 0, fstatat(AT_FDCWD, "symlink", &st, AT_SYMLINK_NOFOLLOW));
uint32_t sym_mode = st.st_mode & 0777;
ASSERT_SYS(0, 0, fchmodat(AT_FDCWD, "regfile", 0640, 0));
ExpectMode("regfile", 0640);
ASSERT_SYS(0, 0, fstatat(AT_FDCWD, "regfile", &st, AT_SYMLINK_NOFOLLOW));
ASSERT_EQ(0640, st.st_mode & 0777);
ASSERT_SYS(0, 0, fchmodat(AT_FDCWD, "regfile", 0600, AT_SYMLINK_NOFOLLOW));
ExpectMode("regfile", 0600);
ASSERT_SYS(0, 0, fstatat(AT_FDCWD, "regfile", &st, AT_SYMLINK_NOFOLLOW));
ASSERT_EQ(0600, st.st_mode & 0777);
ASSERT_SYS(0, 0, fchmodat(AT_FDCWD, "symlink", 0640, 0));
ExpectMode("regfile", 0640);
ExpectMode("symlink", sym_mode);
ASSERT_SYS(0, 0, fstatat(AT_FDCWD, "regfile", &st, AT_SYMLINK_NOFOLLOW));
ASSERT_EQ(0640, st.st_mode & 0777);
ASSERT_SYS(0, 0, fstatat(AT_FDCWD, "symlink", &st, AT_SYMLINK_NOFOLLOW));
ASSERT_EQ(sym_mode, st.st_mode & 0777);
int rc = fchmodat(AT_FDCWD, "symlink", 0600, AT_SYMLINK_NOFOLLOW);
if (rc == -1) {
ASSERT_TRUE(errno == ENOTSUP);
ASSERT_EQ(ENOTSUP, errno);
errno = 0;
} else {
ExpectMode("symlink", 0600);
ASSERT_SYS(0, 0, fstatat(AT_FDCWD, "symlink", &st, AT_SYMLINK_NOFOLLOW));
ASSERT_EQ(0600, st.st_mode & 0777);
}
ExpectMode("regfile", 0640);
ASSERT_SYS(0, 0, fstatat(AT_FDCWD, "regfile", &st, AT_SYMLINK_NOFOLLOW));
ASSERT_EQ(0640, st.st_mode & 0777);
}

0 comments on commit b7e1dc8

Please sign in to comment.