On Sat, Dec 13, 2008 at 12:07:51AM +0100, Roland Mainz wrote: > > > Is there anything special needed ? > > > > the system having /dev/fd/N is one part of it > > the other part is, given fd==3 already open for reading, does > > fd = open("/dev/fd/3", O_RDONLY); > > simply do > > fd = dup(3); > > Somehow I suspect this is the case for Solaris... does the POSIX > standard say anything about this (I suspect it leaves this item > "undefined") and how do other platforms, e.g. FreeBSD, Darwin, Linux > behave ? > > > if so then 3 and fd will have the same seek offsets > > the the open() does a real open then 3 and fd will have > > independent file struct with independent seek offsets > > > > or if you really believe the system provides open() semantics > > then the test could be flawed > > I am not sure... that's why I've CC:'ed the *...@opensolaris.org lists for > feedback...
I've tested it using ksh93 itself: % integer i=1000 % while ((i<1500)) > do > ((i+=1)) > print $i > done > /tmp/foo % redirect 9<>/tmp/foo % (read line <#((200)) ; print $line ; read line </dev/fd/9 ; print $line) <&9 1041 1042 % So, yes, open(2) of /dev/fd/N is as a dup(2) of N. Nico --