src/platform_unix.c
changeset 1003 a28d30d275e2
parent 1002 001380a457a0
child 1012 f254870dd7dd
equal deleted inserted replaced
1002:001380a457a0 1003:a28d30d275e2
   243      * Try to avoid using argv0 unless forced to. If there's a Linux-like
   243      * Try to avoid using argv0 unless forced to. If there's a Linux-like
   244      *  /proc filesystem, you can get the full path to the current process from
   244      *  /proc filesystem, you can get the full path to the current process from
   245      *  the /proc/self/exe symlink.
   245      *  the /proc/self/exe symlink.
   246      */
   246      */
   247     retval = readSymLink("/proc/self/exe");
   247     retval = readSymLink("/proc/self/exe");
       
   248     if (retval == NULL)
       
   249     {
       
   250         /* older kernels don't have /proc/self ... try PID version... */
       
   251         const unsigned long long pid = (unsigned long long) getpid();
       
   252         char path[64];
       
   253         const int rc = (int) snprintf(path,sizeof(path),"/proc/%llu/exe",pid);
       
   254         if ( (rc > 0) && (rc < sizeof(path)) )
       
   255             retval = readSymLink(path);
       
   256     } /* if */
       
   257 
   248     if (retval != NULL)  /* chop off filename. */
   258     if (retval != NULL)  /* chop off filename. */
   249     {
   259     {
   250         char *ptr = strrchr(retval, '/');
   260         char *ptr = strrchr(retval, '/');
   251         if (ptr != NULL)
   261         if (ptr != NULL)
   252             *ptr = '\0';
   262             *ptr = '\0';