Created
February 14, 2014 11:38
-
-
Save kotaroito/8999689 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #include <fcntl.h> | |
| #include <unistd.h> | |
| #include <sys/types.h> | |
| #define FD 100 | |
| void print_cur_pos(int fd) | |
| { | |
| int pos; | |
| pos = lseek(fd, 0, SEEK_CUR); | |
| printf("pos[%d]\n", (int)pos); | |
| } | |
| int inc_pos(int fd) | |
| { | |
| int pos = lseek(fd, 1, SEEK_CUR); | |
| return pos; | |
| } | |
| int main(void) | |
| { | |
| int fd, fd2; | |
| off_t pos; | |
| fd = open("/tmp/test", O_RDONLY); | |
| fd2 = dup2(fd, FD); | |
| print_cur_pos(fd2); // 0 | |
| inc_pos(fd); | |
| print_cur_pos(fd2); // 1 | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment