how can I get filename from file descriptor?

andrew.m.shaw ams at cbnewsl.ATT.COM
Tue Aug 29 04:32:42 AEST 1989


In article <10850 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>In article <1639 at cbnewsl.ATT.COM> ams at cbnewsl.ATT.COM (andrew.m.shaw,580,) writes:
>> Please tell me how to "send EOF" to a pipe reader without closing 
>> the FIFO...
>
>If your pipe implementation is any good (most are not), simply write 0
>bytes to it.

'Twon't work in System V, and my POSIX says (emphasis mine) (6.1.4.2):
	(1)	If no process has the pipe open for writing, read() shall
	return 0 to indicate end-of-file.
	(2)	...
	(3)	If some process has the pipe open for writing and O_NONBLOCK
	is clear, read() shall block until *some* data is written or the
	pipe is closed by all processes that opened the pipe for writing.
Now, is a null write writing *some* data?  From POSIX 6.4.2.2:
	If nbyte is zero, the write function shall return zero *and have
	no other results* if the file is a regular file; otherwise the
	results are implementation dependent. ... Write requests to a pipe
	(or FIFO) shall be handled the same as a regular file with the
	following exceptions: 
		[4 exceptions listed, none germane to topic at hand].

So my feeling is that any implementation that supports "write 0 bytes to
satisfy the read" is non-POSIX-compliant, and therefore code that relies
on it is non-portable, &c, &c.

	Andrew Shaw



More information about the Comp.unix.wizards mailing list