Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!snorkelwacker!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!munnari.oz.au!metro!cluster!necisa!boyd From: boyd@necisa.ho.necisa.oz (Boyd Roberts) Newsgroups: comp.lang.c Subject: perror - (was Re: redirecting output) Message-ID: <1792@necisa.ho.necisa.oz> Date: 3 Jul 90 02:00:05 GMT References: <22931@dartvax.Dartmouth.EDU> <1990Jun29.172429.2818@zoo.toronto.edu> Organization: NEC Information Systems Australia Pty. Ltd. Lines: 46 perror(3) is good, but this is better: char * sysmess() { extern int errno; extern int sys_nerr; extern char *sys_errlist[]; if (errno < 0 || errno >= sys_nerr) return "Unknown error"; return sys_errlist[errno]; } void could_not(what, with) register char *what; register char *with; { fprintf(stderr, "%s: Could not %s \"%s\". %s\n", my_name, what, with, sysmess()); exit(1); /* NOTREACHED*/ } So then we go: if ((fd = open(file, O_RDONLY)) == -1) { could_not("open", file); /* NOTREACHED */ } Of course, my_name is: char *my_name; And main() goes: if ((my_name = strrchr(argv[0], '/')) == NULLSTR || *++my_name == '\0') my_name = argv[0]; Boyd Roberts boyd@necisa.ho.necisa.oz.au ``When the going gets wierd, the weird turn pro...''