From owner-freebsd-current Sat Apr 5 15:08:41 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id PAA05643 for current-outgoing; Sat, 5 Apr 1997 15:08:41 -0800 (PST) Received: from hydrogen.nike.efn.org (resnet.uoregon.edu [128.223.170.28]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id PAA05634 for ; Sat, 5 Apr 1997 15:08:37 -0800 (PST) Received: (from jmg@localhost) by hydrogen.nike.efn.org (8.8.4/8.8.4) id PAA21300; Sat, 5 Apr 1997 15:08:35 -0800 (PST) Message-ID: <19970405150835.41585@hydrogen.nike.efn.org> Date: Sat, 5 Apr 1997 15:08:35 -0800 From: John-Mark Gurney To: freebsd-current@freebsd.org Subject: Re: using opendir, but passing a fd instead of path... References: <19970405042421.06894@hydrogen.nike.efn.org> <199704052011.NAA23502@phaeton.artisoft.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.67 In-Reply-To: <199704052011.NAA23502@phaeton.artisoft.com>; from Terry Lambert on Sat, Apr 05, 1997 at 01:11:41PM -0700 Reply-To: John-Mark Gurney Organization: Cu Networking X-Operating-System: FreeBSD 2.2-960801-SNAP i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ Sender: owner-current@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Terry Lambert scribbled this message on Apr 5: > > I was looking at the man page for opendir, and currently there isn't > > a way to open a dir from a file descriptor... would this be a useful > > addition to the opendir set of routines? or would this be a "wart" on > > something that really shouldn't be touched? > > > > the reason I ask is because of a program that I'm writing, and I don't > > feel like having to pass the path to a subfunction, but I am passing > > an open fd of the dir... > > How did you get the open fd of the dir? fd=open("directory", O_RDONLY, 0); then I pass fd to my function... > Probably you should be passing around a DIR *, not an fd. well.. I'm trying to make a generic interface that will handle the differt types of files properly... i.e. after I open the "possible" file, the I fstat the file.. and then, depending on the st_mode of the struct stat... I call different functions... > I admit that there is a discrepancy in the interface between > the reflexive stdio "fdopen". > > If you are passing around the fd for fchdir, you should be able to > reference the fd out of the dir struct. This would be an interface > violation, too, but a minor one: there is a defined macro "dirfd(DIR *)" > which returns the fd out of the DIR * in dirent.h, even though it > isn't part of the POSIX definition. yeh... I noticed that one... but as above it doesn't help me.. :( > The reason, if you are interested, is that POSIX does not require a > directory to be a normal file accessable through "open". ahhh... that's a good reason that opendir doesn't have a fopendir or similar call... > Probably a cleaner overall fix would be to get a "dichdir(DIR *)" > defined, but that's not going to happen any time soon, if at all. as I describe above... this won't help me any... thanks for the extra info... opendir makes a bit more sense now... ttyl.. -- John-Mark Cu Networking Modem/FAX: +1 541 683 6954 Live in Peace, destroy Micro$oft, support free software, run FreeBSD