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 #include <windows.h>
5 
6 char *fb_hGetExePath( char *dst, ssize_t maxlen )
7 {
8  GetModuleFileName( GetModuleHandle( NULL ), dst, maxlen );
9 
10  char *p = strrchr( dst, '\\' );
11  if( p != NULL )
12  *p = '\0';
13  else
14  dst[0] = '\0';
15 
16  /* just a drive letter? make sure \ follows to prevent using relative path */
17  if( maxlen > 3 && dst[2] == '\0' && dst[1] == ':' )
18  {
19  if( (dst[0] & ~32) >= 'A' && (dst[0] & ~32) <= 'Z' )
20  {
21  dst[2] = '\\';
22  dst[3] = '\0';
23  }
24  }
25 
26  return p;
27 }