Re: [AD] alternate entry point for allegro programs

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> Apart from providing a bit of djgpp emulation,

Could you be more specific? Are the __crt0_argc and __crt0_argv variables 
used for anything else?

> But there are other ways to 
> implement get_executable_name(), for example, looking up /proc/self/exe 
> on Linux.

Yes, the following code seems to be a proper way to get the executable 
filename using the proc fs:

char *get_executable_name(void)
{
   char linkname[1024];
   char *filename;
   struct stat buf;
   pid_t pid;
   int len;
   
   /* Get symlink to current executable */
   pid = getpid();
   snprintf(linkname, sizeof(linkname), "/proc/%d/exe", pid);
   stat(linkname, &buf);
   
   filename = malloc(sizeof(linkname));
   if (filename && realpath(linkname, filename))
      return filename;
   
   free(filename);
   return "";
}

Considering that using argv[0] can be unreliable at any rate, using this if 
proc fs is available may not be a bad idea anyway (this can be done using 
a configure check at compile time, I guess...).
I think I'll go ahead and prepare a patch for that regardless.

The question arises what to do when proc fs is not available though. 
Generally, programs in a UNIX environment should not care from where they 
are executed. Considering that there is no portable reliable way to get 
the name of the executable, I'd vote to leave the return value blank for 
such systems, or return the current working directory instead.

I've found numerous discussions on this topic on the internet, and all seem 
to come to the conclusion that you either need to grab argv[0] and do what 
Allegro currently does, use proc fs if it's there, or just give up and 
accept that this can't be done in a platform-independent way. Some links:

http://mail.gnome.org/archives/gtk-devel-list/2004-April/msg00080.html
http://lists.trolltech.com/qt-interest/2001-04/thread00514-0.html
http://lists.trolltech.com/qt-interest/2002-10/msg00900.html
http://www.linuxquestions.org/questions/archive/9/2002/02/3/14510

Oh, and if we can get of END_OF_MAIN, then yes, by all means, let's do it!

Evert





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/