Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!cmcl2!brl-adm!umd5!mimsy!chris From: chris@mimsy.UUCP Newsgroups: comp.lang.c Subject: Re: closing stdout Message-ID: <9658@mimsy.UUCP> Date: Mon, 7-Dec-87 05:04:54 EST Article-I.D.: mimsy.9658 Posted: Mon Dec 7 05:04:54 1987 Date-Received: Sat, 12-Dec-87 09:31:40 EST References: <442@cresswell.quintus.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 25 Keywords: Yes it IS a buggy library In article <442@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: >... putc() is supposed to return EOF (-1) on error. >Writing to an INPUT stream isn't an error? Unfortunately, putc is supposed to be an efficient macro, and testing for write permission there slows it down. In fact, 4.3BSD stdio will allow this: FILE *fp = fopen("foo", "r"); ... fprintf(fp, ...) ... fputs(..., fp) ... /* etc */ if (fflush(fp) || ferror(fp) || fclose(fp)) fprintf(stderr, "something went wrong\n"); Everything works (with all the appropriate text appearing in file `foo') IF AND ONLY IF FILE foo DID NOT EXIST BEFORE THE fopen! My version of 4.3BSD's stdio catches this sort of thing in all function calls. My stdio might be in 4.4. . . . -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris