Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 25th, 2003, 08:22 PM
Registered User
 
Join Date: Sep 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ohwail
Default dup2 ??

I am a bit confused on how does dup2() works, does it make a copy of the file descriptor or does it change the file descriptor itself, any help here would be usefull.

Reply With Quote
  #2 (permalink)  
Old October 1st, 2003, 06:54 PM
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









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.