view common/portpath.c @ 285:f23e0ccd5d14

Fix call to windows process. This now uses the correct parameters, emits the signals correctly as errors and waits for the process to finish instead of relying on NOASYNC which did not work for runas and also made it impossible to get the return code
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 02 Apr 2014 13:45:57 +0000
parents 70d627e9e801
children 17e1c8f37d72
line wrap: on
line source
#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
}

char *
port_realpath(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/