peter@sugar.uu.net (Peter da Silva) (02/26/89)
In article <49803@uunet.UU.NET>, allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) writes: > execvp(argv[optind], argv + optind); > + fprintf(stderr, "%s: ", argv[0]); > + perror(argv[optind]); Please, folks. If you call perror you have to either avoid doing any other system called before you call it, or you have to save and restore errno. Even successful I/O calls can munge errno. This is how you get programs that come up with such helpful advice as: "frobozz: Not a terminal". Yes, I know it's not a terminal... Sigh. This should be: { char buffer[BIG]; sprintf(buffer, "%s: %s", argv[0], argv[optind]); perror(buffer); } Or: { extern int errno; int errno_save; errno_save = errno; fprintf(stderr, "%s: ", argv[0]); errno = errno_save; perror(argv[optind]); } Or: myperror(argv[0], argv[optind]); ... myperror(prog, object) char *prog, *object; { extern int errno; extern char *sys_errlist; extern int sys_nerr; if(errno < 0 || errno >= sys_nerr) fprintf(stderr, "%s: %s: Error %d\n", prog, object, errno); else fprintf(stderr, "%s: %s: %s\n", prog, object, sys_errlist[errno]); } -- Peter "Have you hugged your wolf today" da Silva `-_-' Hackercorp. ...texbell!sugar!peter, or peter@sugar.uu.net 'U`