Contents of argv[0]

ody davidsen at sungod.crd.ge.com
Thu Aug 17 00:58:23 AEST 1989


In article <2364 at wyse.wyse.com> bob at wyse.UUCP (Bob McGowen Wyse Technology Training) writes:

| How about proposing a new function to be called basename(), obviously
| coded for the environment which the compiler was running under?  It
| would return a pointer to a string which would be the name of the
| program.

  This sounds good to me. It is a low effort procedure to write, making
it unlikely to be opposed by any vendor on the grounds of execssive
cost. It provides a nice standard way to do something which is commonly
useful, and at the calling level it is easily specified in a portable
way. When do we form the C95 committee?

	const char *basename(path)
	const char *path;
	
	basename returns a pointer to a static buffer which holds
	the filename portion of the path pointed to by the path
	argument. This is a pointer to an internal buffer and the data
	must be copied if it is to be preserved beyond the next call to
	basename. 

Please note: I have formalized bob's excelent suggestion this way
because some vendors place the filename in the middle of the path, thus
defeating any effort to point to the filename in the original string.

Example, a typical VMS filename:
	CAOVAX::Dra0:[mimsey.bin.special]zoo.exe;4
                                         ^^^^^^^
                                That's the filename!
	bill davidsen		(davidsen at crdos1.crd.GE.COM)
  {uunet | philabs}!crdgw1!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list