This is Unofficial EPICS BASE Doxygen Site
osdgetexec.c
Go to the documentation of this file.
1 
2 #include <string.h>
3 #include <stdlib.h>
4 
5 #include <mach-o/dyld.h>
6 
7 #include <osiFileName.h>
8 
9 char *epicsGetExecName(void)
10 {
11  uint32_t max = 64u;
12  char *ret = NULL;
13 
14  while(1) {
15  char *temp = realloc(ret, max);
16  if(!temp) {
17  /* we treat alloc failure as terminal */
18  free(ret);
19  ret = NULL;
20  break;
21  }
22  ret = temp;
23 
24  /* cf. "man 3 dyld" */
25  if(_NSGetExecutablePath(ret, &max)==0) {
26  /* max left unchanged */
27  ret[max-1] = '\0';
28  break;
29  }
30  /* max has been updated with required size */
31  }
32 
33  /* TODO: _NSGetExecutablePath() doesn't follow symlinks */
34 
35  return ret;
36 }
37 
38 char *epicsGetExecDir(void)
39 {
40  char *ret = epicsGetExecName();
41  if(ret) {
42  char *sep = strrchr(ret, '/');
43  if(sep) {
44  /* nil the charactor after the / */
45  sep[1] = '\0';
46  }
47  }
48  return ret;
49 }
#define max(x, y)
Definition: flexdef.h:81
#define NULL
Definition: catime.c:38
char * epicsGetExecName(void)
Definition: osdgetexec.c:9
char * epicsGetExecDir(void)
Definition: osdgetexec.c:38