stuart@oasys.dt.navy.mil (Stuart Pearlman) (11/30/90)
In article <14603@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: >In article <1990Nov28.152146.19560@ssd.kodak.com> weimer@ssd.kodak.com (Gary Weimer) writes: >> if ((fp[i]=fopen(file_name[i],"r+")) <= 0) >> perror("Error opening file"); > >Please don't do this; on UNIX, perror() will report the reason for the last >SYSTEM CALL failure, not the reason for failure of a library routine such as >fopen(). Is perror() specified in the ansi C standard? I avoid using perror() after library routines such as fopen() because they can fail for other reasons besides the system calls they make failing. Are any of the library functions specified in the standard guaranteed to set errno? (Is errno even guaranteed to exist?) What about posix 1003.1? Does it specify what functions you can call perror() after? -- Stuart Pearlman stuart@dt.navy.mil Trandes Corporation +1 301 459 0200 On-Contract-To: David Taylor Research Center +1 202 227 1428
gwyn@smoke.brl.mil (Doug Gwyn) (11/30/90)
In article <4573@oasys.dt.navy.mil> stuart@oasys.dt.navy.mil (Stuart Pearlman) writes: >Is perror() specified in the ansi C standard? I avoid using perror() >after library routines such as fopen() because they can fail for other >reasons besides the system calls they make failing. Are any of the >library functions specified in the standard guaranteed to set errno? >(Is errno even guaranteed to exist?) What about posix 1003.1? Does >it specify what functions you can call perror() after? perror() is required for ANSI C conformance. errno is required, but only a few of the standard functions (mainly math functions) are required to set errno (upon certain conditions). IEEE Std 1003.1 specifies that errno is to be set for error returns from a large number of functions (mainly those normally implemented on UNIX as genuine system calls). The allowable values of errno (<errno.h> macros) are specified for each function.