James Carlson wrote: > 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. > So then there's no avoiding a #ifdef SOLARIS, at least in the short term. > 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. > Yeah I'm aware of that, but I didn't write the lib. I'm just trying to port it and then contribute it back to an Open Source community that currently doesn't support Solaris, and is resistant to any OS specific #defines. > >> 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). > Yeah, but its a lib, I don't know or control what the apps that use the lib do. > 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. >
I guess I may have to do this or something like it, I was trying to avoid adding Solaris specific (I guess to be more correct non GNU specific) stuff to the source though. > Still another way to deal with it would be to file an RFE and change > libc to include this "feature" ... > Will do, but what are the chances of that getting done any time soon? Thanks for the inputs.