mirror of
https://github.com/GnoConsortium/gno.git
synced 2025-03-10 23:33:18 +00:00
initial checkin
This commit is contained in:
parent
7a88871b21
commit
d671eaa752
73
lib/libc/tests/sys/dup2.c
Normal file
73
lib/libc/tests/sys/dup2.c
Normal file
@ -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 <sys/types.h>
|
||||
#include <gno/gno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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 <string.h>
|
||||
#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;
|
||||
}
|
19
lib/libc/tests/sys/fcntl.c
Normal file
19
lib/libc/tests/sys/fcntl.c
Normal file
@ -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 <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
}
|
30
lib/libc/tests/sys/pipe1.c
Normal file
30
lib/libc/tests/sys/pipe1.c
Normal file
@ -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 <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user