Contents of argv[0]

Peter da Silva peter at ficc.uu.net
Sat Aug 19 21:25:25 AEST 1989


In article <1989Aug18.130710.13954 at jarvis.csri.toronto.edu>, flaps at dgp.toronto.edu (Alan J Rosenthal) writes:
> peter at ficc.uu.net (Peter da Silva) writes:
> >	parse_file(name, buffer)
> >		...name will be modified ... to null-terminate the elements
> >		of buffer. ...missing or meaningless elements will contain
> >		null pointers.

> Problem is, there aren't always characters available in the right places in
> name to be overwritten with zeroes to terminate the various strings.  In unix,
> consider the file name "/file".  The directory is "/", the file name is "file",
> but there's nowhere to put the zero to terminate the string "/".  A directory
> name of "" is not acceptable; it will work under some circumstances (namely,
> when a slash and a file name is appended) but not in all.

But since you can't portably do anything with the name directly... you will
have to call build_file() to create a new file name... then build_file() can
be written to properly distinguish root (the directory ""), and the current
directory (either "." or no directory in the file name, so the directory is
NULL).

To put it another way, a slash and a file name would always be appended.

The question of what the name of the root in UNIX is is another topic, hashed
over at great length in comp.sys.amiga some time last year.
-- 
Peter da Silva, *NIX support guy @ Ferranti International Controls Corporation.
Biz: peter at ficc.uu.net, +1 713 274 5180. Fun: peter at sugar.hackercorp.com. `-_-'
"Optimization is not some mystical state of grace, it is an intricate act   U
   of human labor which carries real costs and real risks." -- Tom Neff



More information about the Comp.lang.c mailing list