Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!usenet.ins.cwru.edu!ncoast!allbery From: allbery@NCoast.ORG (Brandon S. Allbery KB8JRR/KT) Newsgroups: comp.unix.internals Subject: Re: Is it possible to get filename from file descriptor ? Message-ID: <1990Sep17.170603.27144@NCoast.ORG> Date: 17 Sep 90 17:06:03 GMT References: <870@gtenmc.UUCP> Reply-To: allbery@ncoast.ORG (Brandon S. Allbery KB8JRR/KT) Followup-To: comp.unix.internals Organization: North Coast Public Access *NIX, Cleveland, OH Lines: 32 As quoted from <870@gtenmc.UUCP> by kumar@gtenmc.UUCP (S.Kumar): +--------------- | (This would be very useful to me to find out the filename which | tmpfile() has created which I could then pass to other programs) +--------------- Someone else answered your question; I'll address this. You're doing this wrong.... (1) tmpfile() creates a named file, then unlinks it. By the time you get control back from tmpfile(), the file it creates doesn't *have* a name. (2) In any case, what you want is bass-ackwards. You have to do major work to get the filename from a file descriptor (that is, if it *has* one; pipes, un-"bind"-ed (AF_UNIX) sockets, etc. need not apply). It's much easier to do it in the proper order: char tf_name[L_tmpnam]; FILE *tf_fp; tmpnam(tf_name); tf_fp = fopen(tf_name, "w"); Much easier, no? ++Brandon -- Me: Brandon S. Allbery VHF/UHF: KB8JRR/KT on 220, 2m, 440 Internet: allbery@NCoast.ORG Packet: KB8JRR @ WA8BXN America OnLine: KB8JRR AMPR: KB8JRR.AmPR.ORG [44.70.4.88] uunet!usenet.ins.cwru.edu!ncoast!allbery Delphi: ALLBERY