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? 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? Brendan > James Carlson wrote: >> Brendan Doyle SMI European Software Centre writes: >>> Well for one 'program_invocation_short_name' I know there are >>> alternatives to >>> this, but I'm trying to avoid solaris specific #defines in the source. >> >> Filing an RFE is probably the better alternative for something simple >> like that. >> >> Of course, if this were my code, I'd do something like this instead: >> >> if ((cp = strrchr(argv[0], '/')) == NULL) >> cp = argv[0]; >> else >> cp++; >> >> That should work on any system, and doesn't require reaching for a >> non-portable construct like 'program_invocation_short_name'. >> >> As for the #defines issue, well, writing portable code can sometimes >> be hard, but I think it beats trying to coerce all systems to look the >> same. > > In this particular case, I think basename(getexecname()) is probably > preferable for OpenSolaris, and BSD has getprogname(). > > argv[0] behaviour varies from OS to OS; on some it's left NULL or blank. > > Cheers,