Thread: dup2 ??
View Single Post
  #2 (permalink)  
Old October 1st, 2003, 06:54 PM
merediths merediths is offline
Authorized User
 
Join Date: Jul 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to merediths
Default

dup2(int src_descriptor, int dst_descriptor) creates a new file descriptor referring to the same file; it is, however, a new file descriptor.

i.e.

int fd1,fd2;
...
..
fd1 = open("/tmp/test", O_RDWR);
dup2(fd1,fd2)
lseek(fd1, SEEK_END,0);
...
..

fd1 and fd2 refer to the same file; however, the file pointer associated with the fd1 descriptor is still in the beginning of the file, fd1 points to the end. They are the same file, but not the same descriptor. HTH.

Regards
Meredith Shaebanyan

Reply With Quote