Beispiel #1
0
char *realpath(const char *file_name, char *resolved_name, size_t resolv_buffer_length)
{
  long lRet;
  wchar_t szFile[_MAX_PATH + 1];
  wchar_t szRet[_MAX_PATH + 1];
  wchar_t *wresult;
  char *result = NULL;

  if (_plibc_utf8_mode == 1)
  {
    lRet = plibc_conv_to_win_pathwconv(file_name, szFile, _MAX_PATH );
    if (lRet != ERROR_SUCCESS)
    {
      SetErrnoFromWinError(lRet);
      return NULL;
    }
    wresult = _wfullpath(szRet, szFile, MAX_PATH);
    SetErrnoFromWinError(GetLastError());
    if (wresult)
      wchartostr (szRet, &result, CP_UTF8);
    return result;
  }
  else
  {
    lRet = plibc_conv_to_win_path(file_name, (char *) szFile, _MAX_PATH );
    if (lRet != ERROR_SUCCESS)
    {
      SetErrnoFromWinError(lRet);
      return NULL;
    }
    result = _fullpath(resolved_name, (char *) szFile, resolv_buffer_length);
    SetErrnoFromWinError(GetLastError());
    return result;
  }
}
Beispiel #2
0
/**
 * @brief convert a time value to date and time string
 */
char *_win_ctime_r(const time_t *clock, char *buf)
{
  if (_plibc_utf8_mode == 1)
  {
    wchar_t *ret;
    char *retu = NULL;
    int r;
    ret = _wasctime(localtime(clock));
    if (!ret)
      return NULL;
    r = wchartostr (ret, &retu, CP_UTF8);
    free (ret);
    if (r < 0)
      return NULL;
    if (retu)
    {
      strcpy (buf, retu);
      retu = buf;
    }
    return retu;
  }
  else
  {
    char *ret;
    ret = asctime(localtime(clock));
    if (ret != NULL)
    {
      strcpy(buf, ret);
      ret = buf;
    }
    return ret;
  }
}
Beispiel #3
0
/**
 * @brief convert a time value to date and time string
 */
char *_win_ctime(const time_t *clock)
{
  if (_plibc_utf8_mode == 1)
  {
    char *timeu = NULL;
    wchar_t *timew = _wasctime (localtime (clock));
    if (!timew)
      return NULL;
    wchartostr (timew, &timeu, CP_UTF8);
    free (timew);
    /* in case of error timeu stays NULL */
    return timeu;
  }
  else
    return asctime(localtime(clock));
}
Beispiel #4
0
/* Casts libmagic on the file <lpfile> to determine its type and
 * tries to find and run a handler for that type of files.
 */
int runmime (wchar_t *logfile, LPSHELLEXECUTEINFOW einfo, wchar_t *lpfile, wchar_t *lpdirectory)
{
  magic_t magicmimetype = NULL, magicmimeencoding = NULL, magicapple = NULL, magicname = NULL;
  char *mimetype, *mimeencoding, *apple, *name;
  char *argv1 = NULL;
  MimeResults mres;
  int ret = 0;

  logtofilew (logfile, L">runmime\n");

  magicname = load (NULL, MAGIC_NONE);
  magicmimetype = load (NULL, MAGIC_MIME_TYPE);
  magicmimeencoding = load (NULL, MAGIC_MIME_ENCODING);
  magicapple = load (NULL, MAGIC_APPLE);

  logtofilew (logfile, L"magics: %08x, %08x, %08x, %08x\n", magicname, magicmimetype, magicmimeencoding, magicapple);
  wchartostr (lpfile, &argv1, CP_THREAD_ACP);
  logtofilew (logfile, L"file to check is %S\n", argv1);
  
  memset (&mres, 0, sizeof (mres));

  mres.type = (char *) magic_file (magicmimetype, argv1);
  mres.enc = (char *) magic_file (magicmimeencoding, argv1);
  mres.apple = (char *) magic_file (magicapple, argv1);
  mres.name = (char *) magic_file (magicname, argv1);

  logtofilew (logfile, L"magic results: {%S} {%S} {%S} {%S}\n", mres.name, mres.type, mres.enc, mres.apple);
  if (mres.name != NULL)
    mres.name = strdup (mres.name);
  if (mres.type != NULL)
    mres.type = strdup (mres.type);
  if (mres.enc != NULL)
    mres.enc = strdup (mres.enc);
  if (mres.apple != NULL)
    mres.apple = strdup (mres.apple);

  strtowchar (mres.name, &mres.wname, CP_THREAD_ACP);
  strtowchar (mres.type, &mres.wtype, CP_THREAD_ACP);
  strtowchar (mres.enc, &mres.wenc, CP_THREAD_ACP);
  strtowchar (mres.apple, &mres.wapple, CP_THREAD_ACP);

  magic_close (magicmimetype);
  magic_close (magicmimeencoding);
  magic_close (magicapple);
  magic_close (magicname);

  if (argv1 != NULL)
    free (argv1);

  if (mres.type == NULL && mres.apple == NULL && mres.name == NULL)
  {
    logtofilew (logfile, L"Zero results, returning.\n");
    ret = -1;
  }
  else
  {
    ret = handle (logfile, &mres, einfo, lpfile, lpdirectory);
  }

  if (mres.name != NULL)
    free (mres.name);
  if (mres.type != NULL)
    free (mres.type);
  if (mres.enc != NULL)
    free (mres.enc);
  if (mres.apple != NULL)
    free (mres.apple);

  if (mres.wname != NULL)
    free (mres.wname);
  if (mres.wtype != NULL)
    free (mres.wtype);
  if (mres.wenc != NULL)
    free (mres.wenc);
  if (mres.wapple != NULL)
    free (mres.wapple);
  
  logtofilew (logfile, L"<runmime %d\n", ret);
  return ret;
}