Rev | Line | |
---|
[412] | 1 | //util.c: |
---|
| 2 | |
---|
| 3 | #include <libroarpulse/libroarpulse.h> |
---|
| 4 | |
---|
| 5 | /** Return the binary file name of the current process. This is not |
---|
| 6 | * supported on all architectures, in which case NULL is returned. */ |
---|
| 7 | char *pa_get_binary_name(char *s, size_t l) { |
---|
[414] | 8 | #ifdef __linux__ |
---|
| 9 | int ret; |
---|
| 10 | char path[PATH_MAX]; |
---|
| 11 | |
---|
| 12 | if ( (ret = readlink("/proc/self/exe", path, PATH_MAX-1)) != -1 ) { |
---|
| 13 | path[ret] = 0; |
---|
| 14 | return strncpy(s, pa_path_get_filename(path), l); |
---|
| 15 | } |
---|
| 16 | #endif |
---|
| 17 | |
---|
[412] | 18 | return NULL; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | /** Return a pointer to the filename inside a path (which is the last |
---|
| 22 | * component). */ |
---|
| 23 | const char *pa_path_get_filename(const char *p) { |
---|
[413] | 24 | char * r; |
---|
| 25 | |
---|
| 26 | if ( (r = strrchr(p, '/')) ) { |
---|
| 27 | return (const char *) r+1; |
---|
| 28 | } else { |
---|
| 29 | return p; |
---|
| 30 | } |
---|
| 31 | |
---|
[412] | 32 | } |
---|
| 33 | |
---|
| 34 | //ll |
---|
Note: See
TracBrowser
for help on using the repository browser.