Commit 79eadcf9 authored by Mattia Monga's avatar Mattia Monga

make io.c ANSI

parent 51393fef
......@@ -68,3 +68,11 @@ setarch $(uname -m) -RL bash
On my machine 100000 is too low to get a data race.
### p. 9
`io.c` doesn't compile without `sys/stat.h`
```c
#include <sys/stat.h>
```
......@@ -2,16 +2,19 @@
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
void do_work() {
int fd = open("/tmp/file", O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR);
assert(fd >= 0);
int fd, rc;
char buffer[20];
fd = open("/tmp/file", O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR);
assert(fd >= 0);
sprintf(buffer, "hello world\n");
int rc = write(fd, buffer, strlen(buffer));
rc = write(fd, buffer, strlen(buffer));
assert(rc == strlen(buffer));
printf("wrote %d bytes\n", rc);
fsync(fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment