view src/util_linux.c @ 55:23672cbc3e5f

Write out default values for sortsettings in the ini file.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 19 May 2015 10:13:04 +0200
parents 147b08bc7d64
children 9daf778feaf1
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)