Path: utzoo!attcan!uunet!munnari.oz.au!metro!cluster!nuts!bhpese.oz.au!Sm From: Sm@bhpese.oz.au (Scott Merrilees) Newsgroups: comp.lang.c Subject: Re: perror - (was Re: redirecting output) Message-ID: <1990Jul7.020719.14239@bhpese.oz.au> Date: 7 Jul 90 02:07:19 GMT References: <22931@dartvax.Dartmouth.EDU> <1990Jun29.172429.2818@zoo.toronto.edu> <1792@necisa.ho.necisa.oz> <5XE49LB@xds13.ferranti.com> Organization: BHP Rod & Bar, Newcastle, Australia Lines: 31 peter@ficc.ferranti.com (Peter da Silva) writes: >In article <1792@necisa.ho.necisa.oz> boyd@necisa.ho.necisa.oz (Boyd Roberts) writes: >> if ((my_name = strrchr(argv[0], '/')) == NULLSTR || *++my_name == '\0') >> my_name = argv[0]; >First, this is needlessly obscure. Second, it modifies argv[0], which is not >ps-friendly on UNIX. Obscure? Sm thinks about flamefest ... but decides against it. > >How about: > my_name = strrchr(argv[0], '/'); > if(my_name) > my_name++; > else > my_name = argv[0]; >-- When I looked at Boyd's, I thought it was needlessly verbose, but then I saw that it does one more check than the below fragment that I use, which I like because it fits neatly onto one line. prog = (prog = strrchr(*argv, '/')) == (char *)0 ? *argv : ++prog; I've never come across the need for the *++my_name == '\0' check, has anybody else? Boyd? Also, argv is not modified, only my_name. Sm -- Scott Merrilees, BHP Information Technology, Newcastle, Australia Internet: Sm@bhpese.oz.au Phone: +61 49 402132