Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <fcntl.h>
- int fd;
- int f1()
- {
- static int j = 1;
- if (j > 10) return 0;
- write(fd, &j, sizeof(int));
- printf("write %d -- %d\n", fd, j++);
- return 1;
- }
- void f2()
- {
- int i;
- lseek(fd, -sizeof(int), 1);
- read(fd, &i, sizeof(int));
- printf("read %d -- %d\n", fd, i);
- }
- int main(int argc, char *argv[])
- {
- if (argc < 2)
- puts("Format: rw filename");
- else
- {
- fd = open(argv[1], O_CREAT | O_RDWR);
- while (f1())
- f2();
- close(fd);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement