FreeBASIC  0.91.0
sys_getexepath.c
Go to the documentation of this file.
1 /* get the executable path */
2 
3 #include "../fb.h"
4 
5 char *fb_hGetExePath( char *dst, ssize_t maxlen )
6 {
7  const char *p = strrchr( __fb_ctx.argv[0], '/' );
8  if( p ) {
9  ssize_t len = p - __fb_ctx.argv[0];
10  if( len > maxlen ) {
11  len = maxlen;
12  }
13  else if( len == 0 ) {
14  /* keep the "/" rather than returning "" */
15  len = 1;
16  }
17 
18  memcpy( dst, __fb_ctx.argv[0], len );
19  dst[len] = '\0';
20  } else {
21  *dst = '\0';
22  }
23  return dst;
24 }