Initial programs from intro chapter
This commit is contained in:
19
intro/io.c
Normal file
19
intro/io.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int fd = open("/tmp/file", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
assert(fd >= 0);
|
||||
char buffer[20];
|
||||
sprintf(buffer, "hello world\n");
|
||||
int rc = write(fd, buffer, strlen(buffer));
|
||||
assert(rc == (strlen(buffer)));
|
||||
fsync(fd);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user