Unix Programming - writing a dup2 function

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2004 > writing a dup2 function





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author writing a dup2 function
Ash

2004-01-23, 5:36 pm

Can somebody tell me how we can write an equivalent of dup2()
function without using fcntl function?
Barry Margolin

2004-01-23, 5:36 pm

In article <60aab6b4.0401192254.6b4132ed@posting.google.com>,
amujoo@yahoo.com (Ash) wrote:
quote:

> Can somebody tell me how we can write an equivalent of dup2()
> function without using fcntl function?



Close the target FD, then call dup() repeatedly until it returns that
FD. Then go back and close all the other FDs that were opened in the
loop (so you'll have to keep a list of them as you go).

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=

2004-01-23, 5:36 pm

Barry Margolin <barmar@alum.mit.edu> writes:
quote:

> In article <60aab6b4.0401192254.6b4132ed@posting.google.com>,
> amujoo@yahoo.com (Ash) wrote:
>
>
> Close the target FD, then call dup() repeatedly until it returns that
> FD. Then go back and close all the other FDs that were opened in the
> loop (so you'll have to keep a list of them as you go).



That's not exactly equivalent. dup2() is atomic, i.e. there is no
instant where the target fd is invalid.

--
Måns Rullgård
mru@kth.se
Barry Margolin

2004-01-23, 5:36 pm

In article <yw1xwu7now5w.fsf@ford.guide>, mru@kth.se (Måns Rullgård)
wrote:
quote:

> Barry Margolin <barmar@alum.mit.edu> writes:
>
>
> That's not exactly equivalent. dup2() is atomic, i.e. there is no
> instant where the target fd is invalid.



OK. If the process is multi-threaded, it needs to disable thread
switching first.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com