how safe is it to read/write with fopen'ed files?

Tanner Andrews tanner at ki4pv.UUCP
Thu Aug 29 02:17:20 AEST 1985


] note referenced asks how safe it is to use read(2) with files
] opened using fopen(3)

If you do not extract the file descriptor from the fp structure
returned by fopen(2), many systems won't like it.  The pointer value
from fopen(3) is not likely to make a good fd.

If you do extract the fd, chances are reasonably good that it will
work.  Of course, you must either (a) not be buffering your i/o,
or (b) flush your buffers before you use read(2)/write(2).

As good form you do well not to intermix section 2 i/o calls and
section 3 i/o calls on the same file.  Consider using open(2).

-- 
<std dsclm, copies upon request>	   Tanner Andrews, KI4PV
uucp:					...!decvax!ucf-cs!ki4pv!tanner



More information about the Comp.unix.wizards mailing list