Le lundi 8 novembre 2010 23:09:47, Bruce Korb a écrit : > On 11/08/10 13:29, Ralf Wildenhues wrote: > >> [...] "a.out" format: > >> char *program_name; > >> > >> this on a line by itself was both a declaration and a definition. > > > > On OS X that may just be the case because libtool forces -fno-common > > (for some good reason, but I tend to forget what it was), which disables > > common sections. > > I didn't think my memory was getting that bad..... > > Then what is the solution? It would not feel right to require programs > that are asking for "libposix" to also call a non-posix function just > because it is convenient for the error POSIX module. If it is only OS X, > then I would think that this would work: > > char * program_name; > #ifdef OSX //whatever > #pragma weak program_invocation_name // program_name not being > program_name. #endif > > requiring a call to set_program_name just seems so wrong for a posix lib. For weak section under macosx see : - http://developer.apple.com/library/mac/#technotes/tn2002/tn2064.html - http://stackoverflow.com/questions/274753/how-to-make-weak-linking-work-with-gcc
BTW it is not possible to replace program_invocation_name by a call to a function like errno/__errno_location and thus use a dynamic buffer allocated on the first run of the function and call sysctl to get argv[0] on self It will also allow to use the pstat command under hpux (http://docs.hp.com/en/B2355-90682/pstat.2.html) pst_ucomm field is the name of the program. Bastien