view src/util_linux.c @ 112:9daf778feaf1 1.4

Fix usage of WIN32 macro. With c++11 this is no longer set. _WIN32 is the better macro to use anyway.
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 08 Dec 2016 15:34:07 +0100
parents 147b08bc7d64
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
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)