Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!usc!cs.utexas.edu!uunet!dgis!IDA.ORG!roskos From: roskos@IDA.ORG (Eric Roskos) Newsgroups: alt.sources.d Subject: Re: face2ps Message-ID: <1989Aug2.132936.8919@IDA.ORG> Date: 2 Aug 89 13:29:36 GMT References: <17286@bellcore.bellcore.com> Distribution: alt Organization: IDA, Alexandria, VA Lines: 37 > it dumps core on a Sun That's because the person who wrote it, alas, is suffering from a DOS-induced coding disorder. He assumes that when you invoke it, argv[0] contains slashes in it, since that's what DOS does (it puts the full path name in there and you have to take it off yourself), and if it doesn't, he doesn't detect the NULL coming back from strrchr properly. Notice he remembered that Unix uses forward slashes instead of backwards slashes, but forgot that it doesn't always stick in the full path name for argv[0] the way DOS (or, more accurately, that C compiler) does. The corrected code segment for the Sun should look like this (I compiled under gcc to avoid having to remove the ANSI additions): main(argc,argv) int argc; char *argv[]; { int option; /* the option letter */ #ifdef __MSDOS__ char *progend; program = max(strrchr(argv[0], '\\'),strrchr(argv[0], '/')); progend = strchr(program, '.'); if (progend) *progend = '\0'; #else program = strrchr(argv[0], '/'); if (program == NULL) program = argv[0]; else #endif program++; -- Eric Roskos (roskos@CS.IDA.ORG or Roskos@DOCKMASTER.NCSC.MIL) -- Eric Roskos (roskos@CS.IDA.ORG or Roskos@DOCKMASTER.NCSC.MIL)