Is it possible to get filename from file descriptor ?
Brandon S. Allbery KB8JRR/KT
allbery at NCoast.ORG
Tue Sep 18 03:06:03 AEST 1990
As quoted from <870 at gtenmc.UUCP> by kumar at 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 at 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
More information about the Comp.unix.internals
mailing list