FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
sys_getexepath.c
Go to the documentation of this file.
1
/* get the executable path */
2
3
#include "../fb.h"
4
#include <sys/stat.h>
5
6
char
*
fb_hGetExePath
(
char
*dst, ssize_t maxlen )
7
{
8
char
*
p
;
9
char
linkname[1024];
10
struct
stat finfo;
11
ssize_t len;
12
13
sprintf(linkname,
"/proc/%d/exe"
, getpid());
14
if
((stat(linkname, &finfo) == 0) && ((len = readlink(linkname, dst, maxlen - 1)) > -1)) {
15
/* Linux-like proc fs is available */
16
dst[len] =
'\0'
;
17
p = strrchr(dst,
'/'
);
18
if
(p == dst)
/* keep the "/" rather than returning "" */
19
*(p + 1) =
'\0'
;
20
else
if
(p)
21
*p =
'\0'
;
22
else
23
dst[0] =
'\0'
;
24
}
else
{
25
p =
NULL
;
26
}
27
28
return
p
;
29
}
rtlib
linux
sys_getexepath.c
Generated on Thu Jan 23 2014 19:40:10 for FreeBASIC by
1.8.4