Mercurial > retraceit
view src/util_linux.c @ 113:20ec21924338 tip
Added tag 1.4 for changeset 9daf778feaf1
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 08 Dec 2016 15:34:30 +0100 |
parents | 9daf778feaf1 |
children |
line wrap: on
line source
#ifndef _WIN32 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik * Software engineering by Intevation GmbH * * This file is Free Software under the GNU GPL (v>=2) * and comes with ABSOLUTELY NO WARRANTY! * See LICENSE.txt for details. */ /**@file Linux implementation of functions declared in util.h */ #include "util.h" #include "string.h" #include "strhelp.h" #include "unistd.h" #include <sys/types.h> #include <pwd.h> char * get_proc_install_dir(const char *proc) { char *retval = NULL, *procpath = NULL, *p = NULL, buf[MAX_PATH_LINUX]; ssize_t ret; size_t path_len = 0; if (!proc) { return NULL; } xasprintf(&procpath, "/proc/%s/exe", proc); ret = readlink (procpath, buf, MAX_PATH_LINUX); xfree(procpath); procpath = NULL; if (ret <= 0) { return NULL; } buf[ret] = '\0'; /* cut off the filename */ p = strrchr (buf, '/'); if (p == NULL) { return NULL; } *(p + 1) = '\0'; path_len = strlen (buf); retval = xmalloc (path_len + 1); strncpy (retval, buf, path_len); retval[path_len] = '\0'; return retval; } char * get_install_dir() { return get_proc_install_dir("self"); } #endif