Fix STDIN and STDOUT
This commit is contained in:
parent
0caa6320b1
commit
39e797f937
14
buildtest.c
14
buildtest.c
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// Test the write syscall
|
// Test the write syscall
|
||||||
intptr_t n = write(STDIO, "Hello\n", 6);
|
intptr_t n = write(STDOUT, "Hello\n", 6);
|
||||||
if(n != 6) return n;
|
if(n != 6) return n;
|
||||||
|
|
||||||
// Test the fork syscall
|
// Test the fork syscall
|
||||||
@ -19,7 +19,7 @@ int main() {
|
|||||||
else {c = nibble + '0';}
|
else {c = nibble + '0';}
|
||||||
msg[i] = c;
|
msg[i] = c;
|
||||||
}
|
}
|
||||||
write(STDIO, msg, 17);
|
write(STDOUT, msg, 17);
|
||||||
|
|
||||||
// Child process exits
|
// Child process exits
|
||||||
if(pid == 0) return 0;
|
if(pid == 0) return 0;
|
||||||
@ -28,20 +28,20 @@ int main() {
|
|||||||
// Test the read syscall
|
// Test the read syscall
|
||||||
#define INPUT_BUFFER_LEN 4096
|
#define INPUT_BUFFER_LEN 4096
|
||||||
char input_buffer[INPUT_BUFFER_LEN] = {0};
|
char input_buffer[INPUT_BUFFER_LEN] = {0};
|
||||||
write(STDIO, "Enter some text:", 16);
|
write(STDOUT, "Enter some text:", 16);
|
||||||
intptr_t n_read = read(STDIO, input_buffer, INPUT_BUFFER_LEN);
|
intptr_t n_read = read(STDIN, input_buffer, INPUT_BUFFER_LEN);
|
||||||
write(STDIO, input_buffer, n_read);
|
write(STDOUT, input_buffer, n_read);
|
||||||
|
|
||||||
// Test the open syscall
|
// Test the open syscall
|
||||||
int32_t file = open("/proc/version", O_RDONLY);
|
int32_t file = open("/proc/version", O_RDONLY);
|
||||||
if (file > 0) {
|
if (file > 0) {
|
||||||
int i = read(file, input_buffer, INPUT_BUFFER_LEN);
|
int i = read(file, input_buffer, INPUT_BUFFER_LEN);
|
||||||
while(i > 0) {
|
while(i > 0) {
|
||||||
write(STDIO, input_buffer, i);
|
write(STDOUT, input_buffer, i);
|
||||||
i = read(file, input_buffer, INPUT_BUFFER_LEN);
|
i = read(file, input_buffer, INPUT_BUFFER_LEN);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
write(STDIO, "Could not open /proc/version\n", 29);
|
write(STDOUT, "Could not open /proc/version\n", 29);
|
||||||
}
|
}
|
||||||
return 69;
|
return 69;
|
||||||
}
|
}
|
||||||
|
|||||||
3
sys.h
3
sys.h
@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
void exit(int8_t status);
|
void exit(int8_t status);
|
||||||
|
|
||||||
#define STDIO 1
|
#define STDIN 0
|
||||||
|
#define STDOUT 1
|
||||||
#define STDERR 2
|
#define STDERR 2
|
||||||
intptr_t write(int32_t fd, const void* buf, intptr_t size);
|
intptr_t write(int32_t fd, const void* buf, intptr_t size);
|
||||||
intptr_t read(int32_t fd, const void* buf, intptr_t size);
|
intptr_t read(int32_t fd, const void* buf, intptr_t size);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user