Brendan Doyle writes:
> Hi,
> 
> Thanks for the responses, but I believe that the argv/argc solution will
> not help  me,  I'm porting a library there is no main() or argv/argc.
> 
> So I guess that basename(getexecname())  will work, but will it work on
> Linux?

It doesn't seem to be present, at least on the systems I checked.

The Linux man pages do have this to say about program_invocation_name
and program_invocation_short_name:

        These variables are GNU extensions, and should not be used in
        programs intended to be portable.

> Actually I'm not even sure that will work, program_invocation_short_name is
> global and set before main is called. So where in the library would I  call
> basename(getexecname()) to extract the string and update a global so that
> all functions in the library can use it?

A common way to deal with this is to have the application provide the
name by which it wants to be known for logging purposes.  As, for
example, openlog(3C).

Another common way to deal with it is to have a common function in the
library return the name for all of the consumers in the library,
rather than relying on a static variable.  That function can use its
own static, and call basename(getexecname()) to fill in the static if
NULL.

Still another way to deal with it would be to file an RFE and change
libc to include this "feature" ...

-- 
James Carlson, Solaris Networking              <james.d.carlson at sun.com>
Sun Microsystems / 35 Network Drive        71.232W   Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757   42.496N   Fax +1 781 442 1677

Reply via email to