freopen(), access()

Doug Gwyn gwyn at smoke.brl.mil
Thu Jan 24 10:10:49 AEST 1991


In article <YANG.91Jan23145507 at newyork.nff.ncl.omron.co.jp> yang at nff.ncl.omron.co.jp (YANG Liqun) writes:
>In arcticle <15715hh2x at vax5.cit.cornell.edu> writes:
>>Could someone please explain the functions freopen() and access()?

My reaction was, somebody should tell this guy that if he expects to deal
with UNIX source code he should go to his local technical bookstore and
buy a copy of some UNIX Programmer Reference Manual.

>As far I know, [access] is written in assembler in System V.

No, while all the system-call hooks in the C library are tiny assembly-
language modules that merely cause a trap with the proper subcode, the
actual implementation of system calls in the UNIX kernel originates as
C source code.

I suspect that whatever code is using access() already has a bug, since
access() rarely does what any sensible application would want it to do.
(This is a design deficiency in the semantics for access().)

>For freopen(), you can easily rewrite it in C.

But only if you know enough about the specific implementation of stdio
for the system in question.  The main constraint is that the same FILE
structure must be used for the newly opened file.

Odds are good that the application in question can be readily changed 
to use fclose()/fopen() rather than relying on freopen().  That would
be preferable to trying to implement one's own freopen().



More information about the Comp.lang.c mailing list