andre@112: #ifndef _WIN32 andre@0: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik andre@0: * Software engineering by Intevation GmbH andre@0: * andre@0: * This file is Free Software under the GNU GPL (v>=2) andre@0: * and comes with ABSOLUTELY NO WARRANTY! andre@0: * See LICENSE.txt for details. andre@0: */ andre@0: andre@0: /**@file Linux implementation of functions declared in util.h */ andre@0: andre@0: #include "util.h" andre@0: #include "string.h" andre@0: #include "strhelp.h" andre@0: #include "unistd.h" andre@0: #include andre@0: #include andre@0: andre@0: char * andre@0: get_proc_install_dir(const char *proc) andre@0: { andre@0: char *retval = NULL, andre@0: *procpath = NULL, andre@0: *p = NULL, andre@0: buf[MAX_PATH_LINUX]; andre@0: ssize_t ret; andre@0: size_t path_len = 0; andre@0: andre@0: if (!proc) andre@0: { andre@0: return NULL; andre@0: } andre@0: andre@0: xasprintf(&procpath, "/proc/%s/exe", proc); andre@0: andre@0: ret = readlink (procpath, buf, MAX_PATH_LINUX); andre@0: xfree(procpath); andre@0: procpath = NULL; andre@0: andre@0: if (ret <= 0) andre@0: { andre@0: return NULL; andre@0: } andre@0: andre@0: buf[ret] = '\0'; andre@0: andre@0: /* cut off the filename */ andre@0: p = strrchr (buf, '/'); andre@0: if (p == NULL) andre@0: { andre@0: return NULL; andre@0: } andre@0: *(p + 1) = '\0'; andre@0: andre@0: path_len = strlen (buf); andre@0: retval = xmalloc (path_len + 1); andre@0: strncpy (retval, buf, path_len); andre@0: retval[path_len] = '\0'; andre@0: andre@0: return retval; andre@0: } andre@0: andre@0: char * andre@0: get_install_dir() andre@0: { andre@0: return get_proc_install_dir("self"); andre@0: } andre@0: andre@0: andre@0: #endif