Skip to content

Instantly share code, notes, and snippets.

@kotaroito
Created February 14, 2014 11:38
Show Gist options
  • Select an option

  • Save kotaroito/8999689 to your computer and use it in GitHub Desktop.

Select an option

Save kotaroito/8999689 to your computer and use it in GitHub Desktop.
#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