[412] | 1 | //util.c: |
---|
| 2 | |
---|
[706] | 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 5 | * The code (may) include prototypes and comments (and maybe |
---|
| 6 | * other code fragements) from libpulse*. They are mostly copyrighted by: |
---|
| 7 | * Lennart Poettering <poettering@users.sourceforge.net> and |
---|
| 8 | * Pierre Ossman <drzeus@drzeus.cx> |
---|
| 9 | * |
---|
| 10 | * This file is part of libroarpulse a part of RoarAudio, |
---|
| 11 | * a cross-platform sound system for both, home and professional use. |
---|
| 12 | * See README for details. |
---|
| 13 | * |
---|
| 14 | * This file is free software; you can redistribute it and/or modify |
---|
| 15 | * it under the terms of the GNU General Public License version 3 |
---|
| 16 | * as published by the Free Software Foundation. |
---|
| 17 | * |
---|
| 18 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 21 | * GNU General Public License for more details. |
---|
| 22 | * |
---|
| 23 | * You should have received a copy of the GNU General Public License |
---|
| 24 | * along with this software; see the file COPYING. If not, write to |
---|
| 25 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 26 | * |
---|
| 27 | * NOTE for everyone want's to change something and send patches: |
---|
| 28 | * read README and HACKING! There a addition information on |
---|
| 29 | * the license of this document you need to read before you send |
---|
| 30 | * any patches. |
---|
| 31 | * |
---|
| 32 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
| 33 | * or libpulse*: |
---|
| 34 | * The libs libroaresd, libroararts and libroarpulse link this libroar |
---|
| 35 | * and are therefore GPL. Because of this it may be illigal to use |
---|
| 36 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
| 37 | */ |
---|
| 38 | |
---|
[412] | 39 | #include <libroarpulse/libroarpulse.h> |
---|
| 40 | |
---|
| 41 | /** Return the binary file name of the current process. This is not |
---|
| 42 | * supported on all architectures, in which case NULL is returned. */ |
---|
| 43 | char *pa_get_binary_name(char *s, size_t l) { |
---|
[414] | 44 | #ifdef __linux__ |
---|
| 45 | int ret; |
---|
| 46 | char path[PATH_MAX]; |
---|
| 47 | |
---|
| 48 | if ( (ret = readlink("/proc/self/exe", path, PATH_MAX-1)) != -1 ) { |
---|
| 49 | path[ret] = 0; |
---|
| 50 | return strncpy(s, pa_path_get_filename(path), l); |
---|
| 51 | } |
---|
| 52 | #endif |
---|
| 53 | |
---|
[412] | 54 | return NULL; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /** Return a pointer to the filename inside a path (which is the last |
---|
| 58 | * component). */ |
---|
| 59 | const char *pa_path_get_filename(const char *p) { |
---|
[413] | 60 | char * r; |
---|
| 61 | |
---|
| 62 | if ( (r = strrchr(p, '/')) ) { |
---|
| 63 | return (const char *) r+1; |
---|
| 64 | } else { |
---|
| 65 | return p; |
---|
| 66 | } |
---|
| 67 | |
---|
[412] | 68 | } |
---|
| 69 | |
---|
| 70 | //ll |
---|