mirror of
https://github.com/jart/cosmopolitan.git
synced 2024-05-18 03:22:40 +00:00
/dev/(u)random return eperm on write, update ioctl fionread to linux behavior, cleanup tests
This commit is contained in:
parent
542b817cc8
commit
1c9f462e77
|
@ -106,10 +106,10 @@ static int ioctl_fionread(int fd, uint32_t *arg) {
|
|||
int bytes = CountConsoleInputBytes();
|
||||
*arg = MAX(0, bytes);
|
||||
return 0;
|
||||
} else if (g_fds.p[fd].kind == kFdDevNull ||
|
||||
g_fds.p[fd].kind == kFdDevRandom) {
|
||||
*arg = 1;
|
||||
return 0;
|
||||
} else if (g_fds.p[fd].kind == kFdDevNull) {
|
||||
return enotty();
|
||||
} else if (g_fds.p[fd].kind == kFdDevRandom) {
|
||||
return einval();
|
||||
} else if (GetFileType(handle) == kNtFileTypePipe) {
|
||||
uint32_t avail;
|
||||
if (PeekNamedPipe(handle, 0, 0, 0, &avail, 0)) {
|
||||
|
|
|
@ -52,9 +52,9 @@ static textwindows ssize_t sys_write_nt_impl(int fd, void *data, size_t size,
|
|||
struct Fd *f = g_fds.p + fd;
|
||||
bool isconsole = f->kind == kFdConsole;
|
||||
|
||||
// not implemented
|
||||
// not implemented, XNU returns eperm();
|
||||
if (f->kind == kFdDevRandom) {
|
||||
return enosys();
|
||||
return eperm();
|
||||
}
|
||||
|
||||
// determine win32 handle for writing
|
||||
|
|
|
@ -27,9 +27,12 @@
|
|||
|
||||
int pipefd[2];
|
||||
int stdoutBack;
|
||||
int allowMask;
|
||||
|
||||
void SetUpOnce(void) {
|
||||
testlib_enable_tmp_setup_teardown();
|
||||
// qemu-aarch64 defines o_largefile wrong
|
||||
allowMask = ~(O_LARGEFILE | 0x00008000);
|
||||
}
|
||||
|
||||
void CaptureStdout(void) {
|
||||
|
@ -47,8 +50,7 @@ void RestoreStdout(void) {
|
|||
|
||||
TEST(specialfile, devNull) {
|
||||
ASSERT_SYS(0, 3, creat("/dev/null", 0644));
|
||||
// qemu-aarch64 defines o_largefile wrong
|
||||
ASSERT_EQ(O_WRONLY, fcntl(3, F_GETFL) & ~(O_LARGEFILE | 0x00008000));
|
||||
ASSERT_EQ(O_WRONLY, fcntl(3, F_GETFL) & allowMask);
|
||||
ASSERT_SYS(0, 2, write(3, "hi", 2));
|
||||
ASSERT_SYS(0, 2, pwrite(3, "hi", 2, 0));
|
||||
ASSERT_SYS(0, 2, pwrite(3, "hi", 2, 2));
|
||||
|
@ -65,8 +67,7 @@ TEST(specialfile, devNull) {
|
|||
TEST(specialfile, devNullRead) {
|
||||
char buf[8] = {0};
|
||||
ASSERT_SYS(0, 3, open("/dev/null", O_RDONLY));
|
||||
// qemu-aarch64 defines o_largefile wrong
|
||||
ASSERT_EQ(O_RDONLY, fcntl(3, F_GETFL) & ~(O_LARGEFILE | 0x00008000));
|
||||
ASSERT_EQ(O_RDONLY, fcntl(3, F_GETFL) & allowMask);
|
||||
ASSERT_SYS(0, 0, read(3, buf, 8));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
@ -74,8 +75,7 @@ TEST(specialfile, devNullRead) {
|
|||
TEST(specialfile, devRandomRead) {
|
||||
char buf[8] = {0};
|
||||
ASSERT_SYS(0, 3, open("/dev/random", O_RDONLY));
|
||||
// qemu-aarch64 defines o_largefile wrong
|
||||
ASSERT_EQ(O_RDONLY, fcntl(3, F_GETFL) & ~(O_LARGEFILE | 0x00008000));
|
||||
ASSERT_EQ(O_RDONLY, fcntl(3, F_GETFL) & allowMask);
|
||||
ASSERT_SYS(0, 8, read(3, buf, 8));
|
||||
ASSERT_NE(0, memcmp(buf, " ", 8));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
|
@ -84,8 +84,7 @@ TEST(specialfile, devRandomRead) {
|
|||
TEST(specialfile, devUrandomRead) {
|
||||
char buf[8] = {0};
|
||||
ASSERT_SYS(0, 3, open("/dev/urandom", O_RDONLY));
|
||||
// qemu-aarch64 defines o_largefile wrong
|
||||
ASSERT_EQ(O_RDONLY, fcntl(3, F_GETFL) & ~(O_LARGEFILE | 0x00008000));
|
||||
ASSERT_EQ(O_RDONLY, fcntl(3, F_GETFL) & allowMask);
|
||||
ASSERT_SYS(0, 8, read(3, buf, 8));
|
||||
ASSERT_NE(0, memcmp(buf, " ", 8));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
|
@ -97,9 +96,8 @@ TEST(specialfile, devRandomWrite_fails_on_nt) {
|
|||
}
|
||||
char buf[8] = {0};
|
||||
ASSERT_SYS(0, 3, creat("/dev/random", 0644));
|
||||
// qemu-aarch64 defines o_largefile wrong
|
||||
ASSERT_EQ(O_WRONLY, fcntl(3, F_GETFL) & ~(O_LARGEFILE | 0x00008000));
|
||||
ASSERT_SYS(ENOSYS, -1, write(3, buf, 8));
|
||||
ASSERT_EQ(O_WRONLY, fcntl(3, F_GETFL) & allowMask);
|
||||
ASSERT_SYS(EPERM, -1, write(3, buf, 8));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
|
@ -109,9 +107,8 @@ TEST(specialfile, devUrandomWrite_fails_on_nt) {
|
|||
}
|
||||
char buf[8] = {0};
|
||||
ASSERT_SYS(0, 3, creat("/dev/urandom", 0644));
|
||||
// qemu-aarch64 defines o_largefile wrong
|
||||
ASSERT_EQ(O_WRONLY, fcntl(3, F_GETFL) & ~(O_LARGEFILE | 0x00008000));
|
||||
ASSERT_SYS(ENOSYS, -1, write(3, buf, 8));
|
||||
ASSERT_EQ(O_WRONLY, fcntl(3, F_GETFL) & allowMask);
|
||||
ASSERT_SYS(EPERM, -1, write(3, buf, 8));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue