Skip to content

Commit

Permalink
rtlib: Implemented fb_hGetExePath for Solaris/SunOS
Browse files Browse the repository at this point in the history
  • Loading branch information
thrimbor committed Jul 15, 2015
1 parent 5f8adbf commit 75ef944
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/rtlib/solaris/sys_getexepath.c
@@ -0,0 +1,29 @@
/* get the executable path */

#include "../fb.h"
#include <sys/stat.h>

char *fb_hGetExePath( char *dst, ssize_t maxlen )
{
char *p;
char linkname[1024];
struct stat finfo;
ssize_t len;

sprintf(linkname, "/proc/%lu/path/a.out", getpid());
if ((stat(linkname, &finfo) == 0) && ((len = readlink(linkname, dst, maxlen - 1)) > -1)) {
/* Solaris-like proc fs is available */
dst[len] = '\0';
p = strrchr(dst, '/');
if (p == dst) /* keep the "/" rather than returning "" */
*(p + 1) = '\0';
else if (p)
*p = '\0';
else
dst[0] = '\0';
} else {
p = NULL;
}

return p;
}

0 comments on commit 75ef944

Please sign in to comment.