Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site elsie.UUCP Path: utzoo!watmath!clyde!floyd!harpo!seismo!rlgvax!cvl!elsie!mark From: mark@elsie.UUCP Newsgroups: net.unix Subject: Re: file descriptors --> filenames Message-ID: <830@elsie.UUCP> Date: Fri, 2-Mar-84 11:03:32 EST Article-I.D.: elsie.830 Posted: Fri Mar 2 11:03:32 1984 Date-Received: Sat, 3-Mar-84 23:17:35 EST References: <16844@sri-arpa.UUCP> Organization: NIH-LEC, Bethesda, MD Lines: 21 There is one way you could get a file name from a file descriptor, but it will be *SLOW*. Use fstat(fd,(struct stat *) buf) to get the inode number and device for the file (see stat(2) of the manual). Then use ncheck(8) to get the full path name of the file. E.g.: fp = popen("ncheck -i '#inode' 'file sys'", "r"); fgets(buf,100,fp); fgets(buf,100,fp); pclose(fp); The second fgets call should retrieve the full file name. Ncheck is slow, it may take a minute or two to return (it has to do a lot of searching). It will not, of course, work for fd's that are to devices or pipes. In general, as others have commented, it is far better to keep the file name around for latter reference. -- Mark J. Miller NIH/NCI/DCE/LEC UUCP: decvax!harpo!seismo!rlgvax!cvl!elsie!mark Phone: (301) 496-5688