view common/portpath.c @ 975:b3695a3399de

(issue86) Install into default directories on Linux If the mozilla process is now started as root it will try to write into the default directories for NSS Shared and mozilla / thunderbird profiles. Cinst will now start the mozilla process once as root.
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 29 Aug 2014 12:59:44 +0200
parents 17e1c8f37d72
children faf58e9f518b
line wrap: on
line source
/* 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.
 */
#include "portpath.h"

#include <libgen.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>


char *
port_dirname(char *path)
{
#ifndef _WIN32
  return dirname(path);
#else
  char drive[_MAX_DRIVE];
  char dir[_MAX_DIR];
  _splitpath(path, drive, dir, NULL, NULL);
  size_t dlen = strlen(dir);
  if ((dlen > 0) &&
      ((dir[dlen-1] == '/') || (dir[dlen-1] == '\\')))
    dir[dlen-1] = '\0';
  /* We assume: drive + dir is shorter than
   * drive + dir + fname + ext */
  sprintf(path, "%s%s", drive, dir);
  return path;
#endif
}

bool
port_mkdir(const char *path)
{
#ifndef _WIN32
  return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0;
#else
  /* TODO */
  printf("Should make path: %s\n", path);
  return false;
#endif
}

char *
port_realpath(const char *path)
{
#ifndef _WIN32
  return realpath(path, NULL);
#else
  char *fp = _fullpath(NULL, path, 0);
  if (port_fileexits(fp))
    return fp;
  else
    return NULL;
#endif
}

bool
port_fileexits(char *path)
{
  int ret;
#ifndef _WIN32
  struct stat sb;
  ret = stat(path, &sb);
#else
  struct _stat sb;
  ret = _stat(path, &sb);
#endif

  if (ret == 0)
    return true;
  else
    return false;
}

bool
port_isdir(char *path)
{
  int ret;
#ifndef _WIN32
  struct stat sb;
  ret = stat(path, &sb);
#else
  struct _stat sb;
  ret = _stat(path, &sb);
#endif

  if ((ret == 0) && S_ISDIR(sb.st_mode))
    return true;
  else
    return false;
}

http://wald.intevation.org/projects/trustbridge/