source: roaraudio/libroarpulse/util.c @ 414:882ca9b959e6

Last change on this file since 414:882ca9b959e6 was 414:882ca9b959e6, checked in by phi, 16 years ago

added code for pa_get_binary_name

File size: 696 bytes
Line 
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. */
7char *pa_get_binary_name(char *s, size_t l) {
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
18 return NULL;
19}
20
21/** Return a pointer to the filename inside a path (which is the last
22 * component). */
23const char *pa_path_get_filename(const char *p) {
24 char * r;
25
26 if ( (r = strrchr(p, '/')) ) {
27  return (const char *) r+1;
28 } else {
29  return p;
30 }
31
32}
33
34//ll
Note: See TracBrowser for help on using the repository browser.