perror - (was Re: redirecting output)

Scott Merrilees Sm at bhpese.oz.au
Sat Jul 7 12:07:19 AEST 1990


peter at ficc.ferranti.com (Peter da Silva) writes:
>In article <1792 at necisa.ho.necisa.oz> boyd at 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 at bhpese.oz.au                    Phone: +61 49 402132



More information about the Comp.lang.c mailing list