This is Unofficial EPICS BASE Doxygen Site
osdgetexec.c File Reference
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <osiFileName.h>
+ Include dependency graph for osdgetexec.c:

Go to the source code of this file.

Macros

#define PATH_MAX   100
 

Functions

char * epicsGetExecName (void)
 
char * epicsGetExecDir (void)
 

Macro Definition Documentation

#define PATH_MAX   100

Definition at line 10 of file osdgetexec.c.

Function Documentation

char* epicsGetExecDir ( void  )

Return the absolute path of the directory containing the current executable.

Returns
NULL or the path. Caller must free()

Definition at line 46 of file osdgetexec.c.

47 {
48  char *ret = epicsGetExecName();
49  if(ret) {
50  char *sep = strrchr(ret, '/');
51  if(sep) {
52  /* nil the charactor after the / */
53  sep[1] = '\0';
54  }
55  }
56  return ret;
57 }
char * epicsGetExecName(void)
Definition: osdgetexec.c:9
char* epicsGetExecName ( void  )

Return the absolute path of the current executable.

Returns
NULL or the path. Caller must free()

Definition at line 13 of file osdgetexec.c.

14 {
15  size_t max = PATH_MAX;
16  char *ret = NULL;
17  ssize_t n;
18 
19  while(1) {
20  char *temp = realloc(ret, max);
21  if(!temp) {
22  /* we treat alloc failure as terminal */
23  free(ret);
24  ret = NULL;
25  break;
26  }
27  ret = temp;
28 
29  n = readlink("/proc/self/exe", ret, max);
30  if(n == -1) {
31  free(ret);
32  ret = NULL;
33  break;
34  } else if(n < max) {
35  /* readlink() never adds a nil */
36  ret[n] = '\0';
37  break;
38  }
39 
40  max += 64;
41  }
42 
43  return ret;
44 }
#define max(x, y)
Definition: flexdef.h:81
#define NULL
Definition: catime.c:38
#define PATH_MAX
Definition: osdgetexec.c:10