Path: utzoo!utgpu!watmath!clyde!att!rutgers!bellcore!texbell!sugar!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.sources.d Subject: Re: Comments on INSERT.c Summary: a small but significant detail of programming style. Message-ID: <2692@ficc.uu.net> Date: 11 Jan 89 16:25:14 GMT References: <308@twwells.uucp> <313@twwells.uucp> Organization: Xenix Support Lines: 35 In article <313@twwells.uucp>, bill@twwells.uucp (T. William Wells) writes: > perror("Error 1 : ((fdin = open(argv[1],O_RDONLY)) == -1):"); > into (after setting up ProgramName) > fprintf(stderr, "%s: error while opening %s for read: ", > ProgramName, argv[1]); > perror(""); On many, if not all, systems this will eventually produce the error message: insert: error while opening foobar.c for read: : Not a typewriter Or: insert: error ...: : Inappropriate ioctl for device. Because that fprintf() will stomp on errno. Please, people, if you're going to do stuff before you call perror save and restore errno, or do this: { char buffer[BUFSIZ]; sprintf(buffer, "%s: error while opening %s for read", ProgramName, argv[1]); perror(buffer); } Don't you just love getting bounced mail with the error message indicating that "Fred Bloggs" is not a typewriter, or even worse that someone attempted to perform an inappropriate ioctl on him? I'm glad I'm not Fred. -- Peter da Silva, Xenix Support, Ferranti International Controls Corporation. Work: uunet.uu.net!ficc!peter, peter@ficc.uu.net, +1 713 274 5180. `-_-' Home: bigtex!texbell!sugar!peter, peter@sugar.uu.net. 'U` Opinions may not represent the policies of FICC or the Xenix Support group.