diff --git a/lib/libc/tests/sys/dup2.c b/lib/libc/tests/sys/dup2.c new file mode 100644 index 0000000..e134ef3 --- /dev/null +++ b/lib/libc/tests/sys/dup2.c @@ -0,0 +1,73 @@ +/* + * This tests whether or not a dup2() of STDOUT_FILENO in a child + * process makes STDOUT_FILENO unusable in the parent process. It should + * not. + * + * Indirectly, it also tests screate(2), ssignal(2), and swait(2). + * + * Devin Reade, 1997 + * + * $Id: dup2.c,v 1.1 1997/09/21 18:11:42 gdr Exp $ + */ + +#pragma optimize 72 +#pragma debug 0 + +#include +#include +#include +#include +#include + +#define TEST_MSG "this is the test message\r" +#define PARENT_MSG_1 "doing fork\r" +#define PARENT_MSG_2 "parent waking up\r" +#define CHILD_MSG_1 "child sleeping\r" +#define CHILD_MSG_2 "child doing sema up\r" +#define CHILD_FAIL_1 "dup2() failed in child\r" + +#if 1 +#define LENGTH(str) (sizeof(str) -1) +#else +#include +#define LENGTH(str) strlen(str) +#endif + +int sema; + +static void +_child (void) { + write(STDOUT_FILENO, CHILD_MSG_1, LENGTH(CHILD_MSG_1)); + sleep(1); + if (dup2(STDERR_FILENO, STDOUT_FILENO) == -1) { + write(STDOUT_FILENO, CHILD_FAIL_1, LENGTH(CHILD_FAIL_1)); + } else { + write(STDOUT_FILENO, CHILD_MSG_2, LENGTH(CHILD_MSG_2)); + } + ssignal(sema); + _exit(0); +} + + +int +main (int argc, char **argv) { + + if ((sema = screate(0)) == -1) { + perror("couldn't create semaphore"); + exit(1); + } + + write(STDOUT_FILENO, PARENT_MSG_1, LENGTH(PARENT_MSG_1)); + sleep(1); + + switch(fork(_child)) { + case -1: + perror("fork failed"); + exit(1); + default: + swait(sema); + write(STDOUT_FILENO, PARENT_MSG_2, LENGTH(PARENT_MSG_2)); + write(STDOUT_FILENO, TEST_MSG, LENGTH(TEST_MSG)); + } + return 0; +} diff --git a/lib/libc/tests/sys/fcntl.c b/lib/libc/tests/sys/fcntl.c new file mode 100644 index 0000000..afd418e --- /dev/null +++ b/lib/libc/tests/sys/fcntl.c @@ -0,0 +1,19 @@ +/* + * tests fcntl (F_GETFL) for stdin, stdout, stderr + * + * $Id: fcntl.c,v 1.1 1997/09/21 18:11:42 gdr Exp $ + */ + +#include +#include +#include + +int +main(int argc, char **argv) { + + printf("starting\n"); + printf("flags for stdin are 0x%x\n", fcntl(STDIN_FILENO, F_GETFL)); + printf("flags for stdout are 0x%x\n", fcntl(STDOUT_FILENO, F_GETFL)); + printf("flags for stderr are 0x%x\n", fcntl(STDERR_FILENO, F_GETFL)); + return 0; +} diff --git a/lib/libc/tests/sys/pipe1.c b/lib/libc/tests/sys/pipe1.c new file mode 100644 index 0000000..395ce92 --- /dev/null +++ b/lib/libc/tests/sys/pipe1.c @@ -0,0 +1,30 @@ +/* + * tests simply that we can create a pipe. It also fstat's the result. + * + * $Id: pipe1.c,v 1.1 1997/09/21 18:11:42 gdr Exp $ + */ + +#include +#include +#include +#include +#include + +int main(int argc, char **argv) { + int pdes[2], i, pval; + struct stat sbuf; + + if (pipe(pdes) < 0) { + perror("pipe failed"); + exit(1); + } + + for (i=0; i<2; i++) { + if (fstat(pdes[i], &sbuf) < 0) { + perror("stat failed"); + exit(1); + } + printf("fd %d: st_mode is 0x%lx\n", i, (unsigned long) sbuf.st_mode); + } + return 0; +}