Path: utzoo!attcan!uunet!lll-winken!ncis.llnl.gov!ncis!helios.ee.lbl.gov!pasteur!ucbvax!decwrl!labrea!rutgers!bellcore!texbell!sugar!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.sources.d Subject: Re: Inapproprtiae ioctl for user (Re: Comments on INSERT.c) Message-ID: <2765@ficc.uu.net> Date: 16 Jan 89 13:42:41 GMT References: <308@twwells.uucp> <852@auspex.UUCP> Organization: Xenix Support Lines: 87 I said: > >The exact code to fix the problem is different, but the place to look > >is the same. In article <852@auspex.UUCP>, guy@auspex.UUCP (Guy Harris) writes: > No, it isn't. Yes it is. The place to look is where you call perror. Then you trace back from there to see how you might get to the call with an invalid perror. > fix - "errno = 0" statements are liberally sprinkled throughout the > source). Which sounds like you've got some incredibly poor design here. When I'm doing a generalised error reporting mechanism, I do something like this: errors.h: #define USE_ERRNO 0 #define L_ESYNTAX 1 #define L_EBOOJUM 2 ... errors.c: #include #include "errors.h" char *local_errlist[] = { "Can't happen", "Syntax error", "Boojum", ... }; int local_nerr = sizeof local_errlist / sizeof local_errlist[0]; extern char *sys_errlist[]; extern int sys_nerr; extern int errno; local_perror(text, code) char text[]; int code; { char **errlist; int nerr; if(code) { errlist = local_errlist; nerr = local_nerr; } else { errlist = sys_errlist; nerr = sys_nerr; code = errno; } if(code < nerr) fprintf(stderr, "%s: %s\n", text, local_errtab[code]); else fprintf(stderr, "%s: Unknown error %d\n", text, code); } random_file.c: if(next_token != ':') { local_perror(line, ESYNTAX); return ERROR; } if(!(fp = fopen(file, "r"))) { local_perror(file, 0); return ERROR; } > You have to look at more than just the routine that produces > the error message.... Yes, you have to look at how it's called. I'm sure there's a Zen koan about this somewhere... maybe the one about the finger and the moon. -- 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.