// Processes a single argument which identifies the library to operate on; passes any remaining arguments to the derived class.
    HRESULT v_ProcessArguments(PCWSTR *ppszArgs, int cArgs)
    {
        PCWSTR pszLibPath = CONSUME_NEXT_ARG(ppszArgs, cArgs);
        HRESULT hr = pszLibPath ? S_OK : E_INVALIDARG;
        if (SUCCEEDED(hr))
        {
            if (_fCreate)
            {
                // When creating a new library, interpret the argument as the file system path to save the library to.
                WCHAR szAbsPath[MAX_PATH];
                hr = SHStrDupW(_wfullpath(szAbsPath, pszLibPath, ARRAYSIZE(szAbsPath)), &_pszSavePath);
            }
            else
            {
                // Check for the 'FOLDERID_' prefix, which indicates that the argument should be interpreted as a KNOWNFOLDERID.
                const WCHAR szPrefix[] = L"FOLDERID_";
                const UINT cchPrefix = ARRAYSIZE(szPrefix) - 1;
                if (StrCmpNCW(pszLibPath, szPrefix, cchPrefix) == 0)
                {
                    IKnownFolderManager *pkfm;
                    hr = CoCreateInstance(CLSID_KnownFolderManager, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pkfm));
                    if (SUCCEEDED(hr))
                    {
                        // KNOWNFOLDERIDs are GUIDs, but they have a corresponding canonical name which is a string.
                        // By convention, the canonical name is the same as the name of the KNOWNFOLDERID #define.
                        // That is, FOLDERID_DocumentsLibrary => "DocumentsLibrary".  So, skip the prefix and pass
                        // the remainder to GetFolderByName to retrieve the known folder.
                        IKnownFolder *pkf;
                        hr = pkfm->GetFolderByName(pszLibPath + cchPrefix, &pkf);
                        if (SUCCEEDED(hr))
                        {
                            hr = pkf->GetShellItem(KF_FLAG_INIT, IID_PPV_ARGS(&_psiLibrary));
                            pkf->Release();
                        }
                        pkfm->Release();
                    }
                }
                else
                {
                    // Default - interpret the argument as a file system path, and create a shell item for it.
                    WCHAR szAbsPath[MAX_PATH];
                    hr = SHCreateItemFromParsingName(_wfullpath(szAbsPath, pszLibPath, ARRAYSIZE(szAbsPath)), NULL, IID_PPV_ARGS(&_psiLibrary));
                }
            }
        }
        else
        {
            ParseError(L"Missing library path argument.\n");
        }

        if (SUCCEEDED(hr))
        {
            // Allow derived command to process any remaining arguments.
            hr = v_ProcessLibArguments(ppszArgs, cArgs);
        }
        return hr;
    }
Пример #2
0
/*--------------------------------------------------------------------------*/
char *get_full_path(char *_FullPath, const char *_Path, size_t _SizeInBytes)
{
#if defined(_MSC_VER)
    char *returnedFullPath = NULL;

    wchar_t *wPath = to_wide_string((char *)_Path);
    wchar_t *wFullPath = (wchar_t *) MALLOC(sizeof(wchar_t) * _SizeInBytes);

    _wfullpath(wFullPath, wPath, _SizeInBytes);
    returnedFullPath = wide_string_to_UTF8(wFullPath);
    if (returnedFullPath)
    {
        strcpy(_FullPath, returnedFullPath);
        FREE(returnedFullPath);
        returnedFullPath = NULL;
    }

    if (wPath)
    {
        FREE(wPath);
        wPath = NULL;
    }
    if (wFullPath)
    {
        FREE(wFullPath);
        wFullPath = NULL;
    }

    return _FullPath;
#else
    char *rp = NULL;
    int lenPath = (int)strlen(_Path);

    rp = realpath(_Path, _FullPath);
    int lenFullPath = 0;
    int haveFileSep = ((lenPath > 1) && isDirSeparator(_Path[lenPath - 1]));
    int addFileSep = 0;

    if (!rp)
    {
        strcpy(_FullPath, _Path);
        normalizePath(_FullPath);
    }
    lenFullPath = (int)strlen(_FullPath);
    addFileSep = ((lenFullPath > 1) && (!isDirSeparator(_FullPath[lenFullPath - 1])) && haveFileSep);
    if (addFileSep)
    {
        char *bufTmp = (char *)MALLOC(sizeof(char) * (lenFullPath + strlen(DIR_SEPARATOR) + 1));

        if (bufTmp)
        {
            sprintf(bufTmp, "%s%s", _FullPath, DIR_SEPARATOR);
            strcpy(_FullPath, bufTmp);
            FREE(bufTmp);
            bufTmp = NULL;
        }
    }
    return _FullPath;
#endif
}
Пример #3
0
int have_processed_dir(TCHAR *fn)
{
  dir_table *temp;
  TCHAR *d_name;

  if (my_table == NULL)
    return FALSE;

  d_name = (TCHAR *)malloc(sizeof(TCHAR) * PATH_MAX);
#ifdef _WIN32
  _wfullpath(d_name,fn,PATH_MAX);
#else
  realpath(fn,d_name);
#endif

  temp = my_table;
  while (temp != NULL)
  {
    if (!_tcsncmp(temp->name,d_name,PATH_MAX))
    {
      free(d_name);
      return TRUE;
    }

    temp = temp->next;       
  }

  free(d_name);
  return FALSE;
}
Пример #4
0
//////////////////////////////////////////////////////////////////////////////////////////
// Create a new file.
XsensResultValue Cmt1f::create (const wchar_t* filename)
{
	if (m_isOpen)
		return m_lastResult = XRV_ALREADYOPEN;

#ifdef _WIN32
	//! \test does this work for non-existing files? Or do we need a check and create?
	m_handle = _wfopen(filename, L"w+b");	// open for update (r/w)
	if (m_handle == NULL)
		return m_lastResult = XRV_OUTPUTCANNOTBEOPENED;

	if (_wfullpath(m_filename_w,filename,CMT_MAX_FILENAME_LENGTH) == NULL)
	{
		fclose(m_handle);
		_wremove(filename);
		return m_lastResult = XRV_INVALIDPARAM;
	}
	wcstombs(m_filename,m_filename_w,CMT_MAX_FILENAME_LENGTH);

	m_isOpen = true;
	m_readPos = 0;
	m_writePos = 0;
	m_fileSize = 0;
	m_reading = true;
	m_readOnly = false;
#else
	char tFilename[CMT_MAX_FILENAME_LENGTH*2];
	wcstombs(tFilename, filename, CMT_MAX_FILENAME_LENGTH);
	XsensResultValue res = create(tFilename);
	if (res != XRV_OK)
		return res;
#endif
	m_unicode = true;
	return m_lastResult = XRV_OK;
}
Пример #5
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;
  }
}
Пример #6
0
CString FileSystem::ExpandFileName(const char* filename)
{
#ifdef WIN32
	wchar_t unistr[1024];
	_wfullpath(unistr, UtfPathToWidePath(filename), 1024);
	return WidePathToUtfPath(unistr);
#else
	CString result;
	result.Reserve(1024 - 1);
	if (filename[0] != '\0' && filename[0] != '/')
	{
		char curDir[MAX_PATH + 1];
		getcwd(curDir, sizeof(curDir) - 1); // 1 char reserved for adding backslash
		int offset = 0;
		if (filename[0] == '.' && filename[1] == '/')
		{
			offset += 2;
		}
		result.Format("%s/%s", curDir, filename + offset);
	}
	else
	{
		result = filename;
	}
	return result;
#endif
}
Пример #7
0
 inline char* realpath(const char *filename, char *resolvedname) {
   wchar_t fn[_MAX_PATH] = L"";
   _wfullpath(fn, nall::utf16_t(filename), _MAX_PATH);
   strcpy(resolvedname, nall::utf8_t(fn));
   for(unsigned n = 0; resolvedname[n]; n++) if(resolvedname[n] == '\\') resolvedname[n] = '/';
   return resolvedname;
 }
Пример #8
0
static void generate_filename(state *s, TCHAR *fn, TCHAR *cwd, TCHAR *input)
{
  if (NULL == fn || NULL == input)
    internal_error("Error calling generate_filename");

  if ((s->mode & mode_relative) || is_absolute_path(input))
    _tcsncpy(fn,input,PATH_MAX);
  else
    {
      // Windows systems don't have symbolic links, so we don't
      // have to worry about carefully preserving the paths
      // they follow. Just use the system command to resolve the paths
#ifdef _WIN32
      _wfullpath(fn,input,PATH_MAX);
#else     
      if (NULL == cwd)
	// If we can't get the current working directory, we're not
	// going to be able to build the relative path to this file anyway.
	// So we just call realpath and make the best of things
	realpath(input,fn);
      else
	snprintf(fn,PATH_MAX,"%s%c%s",cwd,DIR_SEPARATOR,input);
#endif
    }
}
Пример #9
0
/*!	\relates XsFile
	\brief Retrieves the full path for a filename
	\param[in] filename The filename to expand
	\param[out] fullPath The filename with a fully expanded path is returned in this parameter. This parameter must be allocated by the caller.
	\returns XRV_OK if the fullpath could be retrieved, XRV_NULLPTR if fullPath is NULL, XRV_ERROR otherwise
*/
XsResultValue XsFile_fullPath(const struct XsString* filename, struct XsString* fullPath)
{
	XsResultValue result = XRV_OK;
	if (fullPath == NULL)
	{
		result = XRV_NULLPTR;
	}
	else
	{
#ifdef _WIN32
		wchar_t filenamew[XS_MAX_FILENAME_LENGTH];
		wchar_t fullpath[XS_MAX_FILENAME_LENGTH];
		(void)XsString_copyToWCharArray(filename, filenamew, XS_MAX_FILENAME_LENGTH);

		if (_wfullpath(fullpath, filenamew, XS_MAX_FILENAME_LENGTH) == NULL)
			result = XRV_ERROR;
		else
			XsString_assignWCharArray(fullPath, fullpath);
#else
		// based on the assumption that this doesn't concern the serial port, handle
		// it the same way using realpath(). Apparently realpath() doesn't require a
		// maximum length. One would possibly want to write a wrapper for it.
		char fullpath[XS_MAX_FILENAME_LENGTH*2];
		if (realpath(filename->m_data, fullpath) == NULL)
			result = XRV_ERROR;
		else
			XsString_assignCharArray(fullPath, fullpath);
#endif
	}
	return result;
}
Пример #10
0
/*
  The "abpathlen" is the size of the buffer needed by _wfullpath. If the
  "path" is a relative path, it is "the length of the current dir" + "the
  length of the path", if it's "absolute" already, it's the same as
  pathlen which is the length of "path".
 */
WCHAR* prefixAbpath(const WCHAR* path, int pathlen, int abpathlen) {
    WCHAR* pathbuf = NULL;
    WCHAR* abpath = NULL;

    abpathlen += 10;  //padding
    abpath = (WCHAR*)malloc(abpathlen * sizeof(WCHAR));
    if (abpath) {
        /* Collapse instances of "foo\.." and ensure absoluteness before
           going down to prefixing.
        */
        if (_wfullpath(abpath, path, abpathlen)) {
            pathbuf = getPrefixed(abpath, abpathlen);
        } else {
            /* _wfullpath fails if the pathlength exceeds 32k wchar.
               Instead of doing more fancy things we simply copy the
               ps into the return buffer, the subsequent win32 API will
               probably fail with FileNotFoundException, which is expected
            */
            pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
            if (pathbuf != 0) {
                wcscpy(pathbuf, path);
            }
        }
        free(abpath);
    }
    return pathbuf;
}
Пример #11
0
static void	svc_get_fullpath(const char *path, wchar_t *fullpath, size_t max_fullpath)
{
	wchar_t	*wpath;

	wpath = zbx_acp_to_unicode(path);
	_wfullpath(fullpath, wpath, max_fullpath);
	zbx_free(wpath);
}
Пример #12
0
string realpath(const string &name) {
  string result;
  #ifdef _WIN32
  wchar_t path[PATH_MAX] = L"";
  if(_wfullpath(path, utf16_t(name), PATH_MAX)) result = (const char*)utf8_t(path);
  result.transform("\\", "/");
  #else
  char path[PATH_MAX] = "";
  if(::realpath(name, path)) result = path;
  #endif
  return result;
}
Пример #13
0
int done_processing_dir(TCHAR *fn)
{
  dir_table *last, *temp;
  TCHAR *d_name = (TCHAR *)malloc(sizeof(TCHAR) * PATH_MAX);

#ifdef _WIN32
  _wfullpath(d_name,fn,PATH_MAX);
#else
  realpath(fn,d_name);
#endif

  if (my_table == NULL)
  {
    internal_error("Table is NULL in done_processing_dir");

    // This code never gets executed... 
    free(d_name);
    return FALSE;
  }

  temp = my_table;

  if (!_tcsncmp(d_name,temp->name,PATH_MAX))
  {
    my_table = my_table->next;
    free(temp->name);
    free(temp);
    free(d_name);
    return TRUE;
  }

  while (temp->next != NULL)
  {
    last = temp;
    temp = temp->next;
    if (!_tcsncmp(d_name,temp->name,PATH_MAX))
    {
      last->next = temp->next;
      free(temp->name);
      free(temp);
      free(d_name);
      return TRUE;
    }
  }

  internal_error("%s: Directory %s not found in done_processing_dir",
		 __progname, d_name);

  // This code never gets executed... 
  //  free (d_name);
  return FALSE;
}
Пример #14
0
string realpath(const string& name) {
  string result;
  #if defined(PLATFORM_WINDOWS)
  wchar_t path[PATH_MAX] = L"";
  if(_wfullpath(path, utf16_t(name), PATH_MAX)) result = (const char*)utf8_t(path);
  result.transform("\\", "/");
  #else
  char path[PATH_MAX] = "";
  if(::realpath(name, path)) result = path;
  #endif
  if(result.empty()) result = {activepath(), name};
  return result;
}
Пример #15
0
void ConfigParser::ParseConfig(HANDLE hmod, CmdLineArgsParser &parser)
{
#if defined(ENABLE_DEBUG_CONFIG_OPTIONS) && CONFIG_PARSE_CONFIG_FILE
    Assert(!_hasReadConfig);
    _hasReadConfig = true;

    char16 configBuffer[MaxTokenSize];
    int err = 0;
    char16 modulename[_MAX_PATH];
    char16 filename[_MAX_PATH];

    GetModuleFileName((HMODULE)hmod, modulename, _MAX_PATH);
    char16 drive[_MAX_DRIVE];
    char16 dir[_MAX_DIR];

    _wsplitpath_s(modulename, drive, _MAX_DRIVE, dir, _MAX_DIR, nullptr, 0, nullptr, 0);
    _wmakepath_s(filename, drive, dir, _configFileName, _u(".config"));

    FILE* configFile;
    if (_wfopen_s(&configFile, filename, _u("r, ccs=UNICODE")) != 0 || configFile == nullptr)
    {
        WCHAR configFileFullName[MAX_PATH];

        StringCchPrintf(configFileFullName, MAX_PATH, _u("%s.config"), _configFileName);

        // try the one in the current working directory (Desktop)
        if (_wfullpath(filename, configFileFullName, _MAX_PATH) == nullptr)
        {
            return;
        }
        if (_wfopen_s(&configFile, filename, _u("r, ccs=UNICODE")) != 0 || configFile == nullptr)
        {
            return;
        }
    }

    while (fwscanf_s(configFile, _u("%s"), configBuffer, MaxTokenSize) != FINISHED)
    {
        if ((err = parser.Parse(configBuffer)) != 0)
        {
            break;
        }
    }
    fclose(configFile);

    if (err !=0)
    {
        return;
    }
#endif
}
Пример #16
0
/*! \brief Create an empty file
	\param filename The desired (path+)name of the file
	\returns XRV_OK if the file was created successfully
*/
XsResultValue IoInterfaceFile::create(const XsString& filename)
{
	if (m_handle) return m_lastResult = XRV_ALREADYOPEN;

//! \test does this work for non-existing files? Or do we need a check and
//! create?
#ifdef _WIN32
	m_handle = _wfopen(
		filename.toStdWString().c_str(), L"w+b");  // open for update (r/w)
#else
	m_handle = fopen(filename.c_str(), "w+b");  // open for update (r/w)
#endif
	if (m_handle == nullptr) return m_lastResult = XRV_OUTPUTCANNOTBEOPENED;

	bool fail = false;
#ifdef _WIN32
	wchar_t fullpath[XS_MAX_FILENAME_LENGTH];
	if (_wfullpath(
			fullpath, filename.toStdWString().c_str(),
			XS_MAX_FILENAME_LENGTH) == nullptr)
		fail = true;
#else
	// based on the assumption that this doesn't concern the serial port, handle
	// it the same way using realpath(). Apparently realpath() doesn't require a
	// maximum length. One would possibly want to write a wrapper for it.
	char fullpath[XS_MAX_FILENAME_LENGTH * 2];
	if (realpath(filename.c_str(), fullpath) == nullptr) fail = true;
#endif
	m_filename = XsString(fullpath);

	if (fail)
	{
		fclose(m_handle);
#ifdef _WIN32
		_wunlink(m_filename.toStdWString().c_str());
#else
		unlink(m_filename.c_str());
#endif
		m_handle = 0;
		return m_lastResult = XRV_INVALIDPARAM;
	}

	m_readPos = 0;
	m_writePos = 0;
	m_fileSize = 0;
	m_reading = true;
	m_readOnly = false;
	return m_lastResult = XRV_OK;
}
Пример #17
0
//////////////////////////////////////////////////////////////////////////////////////////
// Open a file.
XsensResultValue Cmt1f::open(const wchar_t* filename, const bool create, const bool readOnly)
{
	if (m_isOpen)
		return m_lastResult = XRV_ALREADYOPEN;

#ifdef _WIN32
	//! \test does this work for non-existing files? Or do we need a check and create?
	m_readOnly = readOnly;
	if (readOnly)
		m_handle = _wfopen(filename, L"rb");	// open for read only (r)
	else
		m_handle = _wfopen(filename, L"r+b");	// open for update (r/w)
	if (m_handle == NULL)
	{
		if (create)
			m_handle = _wfopen(filename, L"w+b");	// create for update (r/w)
		else
		{
			m_handle = _wfopen(filename, L"rb");	// open for read only (r)
			m_readOnly = true;
		}
	}
	if (m_handle == NULL)
		return m_lastResult = XRV_INPUTCANNOTBEOPENED;

	if (_wfullpath(m_filename_w,filename,CMT_MAX_FILENAME_LENGTH) == NULL)
	{
		fclose(m_handle);
		return m_lastResult = XRV_INVALIDPARAM;
	}
	wcstombs(m_filename,m_filename_w,CMT_MAX_FILENAME_LENGTH);

	m_isOpen = true;
	m_readPos = 0;
	m_writePos = 0;
	m_reading = true;
	FSEEK_R(0);
	m_fileSize = FTELL();
	FSEEK(0);
#else
	char tFilename[CMT_MAX_FILENAME_LENGTH*2];
	wcstombs(tFilename,filename,CMT_MAX_FILENAME_LENGTH*2);
	XsensResultValue res = open(tFilename,create,readOnly);
	if (res != XRV_OK)
		return res;
#endif
	m_unicode = true;
	return m_lastResult = XRV_OK;
}
Пример #18
0
HRESULT GetPropertyStore(PCWSTR pszFilename, GETPROPERTYSTOREFLAGS gpsFlags, IPropertyStore** ppps)
{
    WCHAR szExpanded[MAX_PATH];
    HRESULT hr = ExpandEnvironmentStrings(pszFilename, szExpanded, ARRAYSIZE(szExpanded)) ? S_OK : HRESULT_FROM_WIN32(GetLastError());
    if (SUCCEEDED(hr))
    {
        WCHAR szAbsPath[MAX_PATH];
        hr = _wfullpath(szAbsPath, szExpanded, ARRAYSIZE(szAbsPath)) ? S_OK : E_FAIL;
        if (SUCCEEDED(hr))
        {
            hr = SHGetPropertyStoreFromParsingName(szAbsPath, NULL, gpsFlags, IID_PPV_ARGS(ppps));
        }
    }
    return hr;
}
Пример #19
0
/*--------------------------------------------------------------------------*/
wchar_t *get_full_pathW(wchar_t * _wcFullPath, const wchar_t * _wcPath, size_t _SizeInBytes)
{
    wchar_t *wcResult = NULL;

#if defined(_MSC_VER)
    if (_wcPath)
    {
        wcResult = (wchar_t *) MALLOC(sizeof(wchar_t) * _SizeInBytes);
        if (wcResult)
        {
            _wfullpath(wcResult, _wcPath, _SizeInBytes);
            wcscpy(_wcFullPath, wcResult);
        }
    }
#else
    if (_wcPath)
    {
        char *_Path = wide_string_to_UTF8(_wcPath);

        if (_Path)
        {
            char *_FullPath = (char *)MALLOC(sizeof(char) * (_SizeInBytes));

            if (_FullPath)
            {
                char *rp = NULL;

                rp = realpath(_Path, _FullPath);
                if (!rp)
                {
                    strcpy(_FullPath, _Path);
                    normalizePath(_FullPath);
                }
                wcResult = to_wide_string(_FullPath);
                if (wcResult)
                {
                    wcscpy(_wcFullPath, wcResult);
                }
                FREE(_FullPath);
                _FullPath = NULL;
            }
            FREE(_Path);
            _Path = NULL;
        }
    }
#endif
    return wcResult;
}
Пример #20
0
BOOL MapAndLoadW(LPWSTR imgPath, PLOADED_IMAGE lpImg)
{
	wchar_t lpImgPathW[MAX_PATH+1] = L"";
	char lpImgPathA[MAX_PATH+1] = "",
	lpImgNameA[MAX_PATH+1] = "",
	lpImgDirA[MAX_PATH+1] = "";
	size_t szDllPathW;

	if(_wfullpath(lpImgPathW, (LPCWSTR)imgPath, MAX_PATH) == NULL) return FALSE;
	if((szDllPathW = wcslen(lpImgPathW)) == 0) return FALSE;
	if(wcstombs(lpImgPathA, (LPCWSTR)lpImgPathW, szDllPathW) == -1) return FALSE;
	strcpy(lpImgNameA ,(LPCSTR)(strrchr(lpImgPathA, '\\') + 1));
	*(strrchr(lpImgPathA, '\\')) = '\0';
	strcpy(lpImgDirA, (LPCSTR)lpImgPathA);
	return MapAndLoad(lpImgNameA, lpImgDirA, lpImg, FALSE, TRUE);
}
Пример #21
0
void BasicPathName<TChar>::internalCanonicalizePath(const wchar_t* srcPath, BasicPathName<wchar_t>* outPath) const
{
	wchar_t tmpPath[LN_MAX_PATH + 1] = { 0 };
	wchar_t* canonPath;
#ifdef _WIN32
	canonPath = _wfullpath(tmpPath, srcPath, LN_MAX_PATH);
#else
	canonPath = realpath(mPath.c_str(), pathbuf);
#endif
	if (canonPath == NULL) {	// 変換失敗
		*outPath = BasicPathName<wchar_t>();
	}
	else {
		*outPath = BasicPathName<wchar_t>(tmpPath);
	}
}
Пример #22
0
void BasicPathName<TChar>::internalCanonicalizePath(BasicPathName<TChar>* outPath) const
{
	wchar_t tmpPath[LN_MAX_PATH];
	wchar_t* canonPath;
#ifdef _WIN32
	canonPath = _wfullpath(tmpPath, mPath.c_str(), LN_MAX_PATH);
#else
	canonPath = realpath(mPath.c_str(), pathbuf);
#endif
	if (canonPath == NULL) {
		*outPath = PathName();
	}
	else {
		*outPath = PathName(tmpPath);
	}
}
Пример #23
0
int processing_dir(TCHAR *fn)
{
  dir_table *new_dir, *temp;
  TCHAR *d_name = (TCHAR *)malloc(sizeof(TCHAR) * PATH_MAX);

#ifdef _WIN32
  _wfullpath(d_name,fn,PATH_MAX);
#else
  realpath(fn,d_name);
#endif

  if (my_table == NULL)
  {
    my_table = (dir_table*)malloc(sizeof(dir_table));
    my_table->name = _tcsdup(d_name);
    my_table->next = NULL;

    free(d_name);
    return TRUE;
  }
 
  temp = my_table;

  while (temp->next != NULL)
  {
    /* We should never be adding a directory that is already here */
    if (!_tcsncmp(temp->name,d_name,PATH_MAX))
    {
      internal_error("%s: Attempt to add existing %s in processing_dir",
		     __progname, d_name);
      // Does not execute
      free(d_name);
      return FALSE;
    }
    temp = temp->next;       
  }

  new_dir = (dir_table*)malloc(sizeof(dir_table));
  new_dir->name = _tcsdup(d_name);
  new_dir->next = NULL;  
  temp->next = new_dir;

  free(d_name);
  return TRUE;
}
Пример #24
0
static nsresult GetRealPath(const char* appDataFile, char* *aResult)
{
#ifdef XP_WIN
  wchar_t wAppDataFile[MAX_PATH];
  wchar_t wIniPath[MAX_PATH];
  MultiByteToWideChar(CP_UTF8, 0, appDataFile, -1, wAppDataFile, MAX_PATH);
  _wfullpath(wIniPath, wAppDataFile, MAX_PATH);
  WideCharToMultiByte(CP_UTF8, 0, wIniPath, -1, *aResult, MAX_PATH, 0, 0);
#else
  struct stat fileStat;
  if (!realpath(appDataFile, *aResult) || stat(*aResult, &fileStat))
    return NS_ERROR_FAILURE;
#endif
  if (!*aResult || !**aResult)
    return NS_ERROR_FAILURE;

  return NS_OK;
}
Пример #25
0
size_t os_get_abs_path(const char *path, char *abspath, size_t size)
{
	wchar_t wpath[512];
	wchar_t wabspath[512];
	size_t out_len = 0;
	size_t len;

	if (!abspath)
		return 0;

	len = os_utf8_to_wcs(path, 0, wpath, 512);
	if (!len)
		return 0;

	if (_wfullpath(wabspath, wpath, 512) != NULL)
		out_len = os_wcs_to_utf8(wabspath, 0, abspath, size);
	return out_len;
}
Пример #26
0
////////////////////////////////////////////////////////////////////////////////
// initApplication()
////////////////////////////////////////////////////////////////////////////////
bool initApplication(NvGsaApplication *app, const wchar_t *exePath)
{
	wchar_t fullExePath[_MAX_PATH];
	wchar_t drive[_MAX_DRIVE];
	wchar_t dir[_MAX_DIR];
	wchar_t exe[_MAX_FNAME];
	wchar_t ext[_MAX_EXT];
	wchar_t fullExeDir[_MAX_PATH];
	wchar_t fullExeName[_MAX_PATH];

	// Get the full executable path.
	if (_wfullpath(fullExePath, exePath, _MAX_PATH) == NULL) {
		return false;
	}

	// Split the executable path
	_wsplitpath_s(
		fullExePath,
		drive, _MAX_DRIVE,
		dir, _MAX_DIR,
		exe, _MAX_FNAME,
		ext, _MAX_EXT);

	// Get the executable directory
	if (0 > swprintf_s(fullExeDir, _MAX_PATH, L"%s%s", drive, dir)) {
		return false;
	}

	// Get the executable name with extension
	if (0 > swprintf_s(fullExeName, _MAX_PATH, L"%s%s", exe, ext)) {
		return false;
	}

	// Setup the application fields
	app->displayName = _wcsdup(L"GsaSimpleApp");
	app->versionName = _wcsdup(L"1.0.0.0");
	app->installPath = _wcsdup(fullExeDir);
	app->configPath = _wcsdup(fullExeDir);
	app->executable = _wcsdup(exe);
	app->execCmd = _wcsdup(fullExeName);

	return true;
}
Пример #27
0
wchar *VMPI_realpath16(wchar const *path)
{
    /* note:
       if the path does not exists the path will still resolve
       and does not set errno to ENOENT "No such file or directory"
    */
    wchar* full = NULL;
    wchar* result = NULL;
    
    if( VMPI_access16(path, F_OK) ) {
        errno = ENOENT;
        return NULL;
    }
    
    result = _wfullpath( full, path, PATH_MAX );
    
    if( result != NULL ) {
        return result;
    }
    
    return NULL; 
}
Пример #28
0
io::path CFileSystem::getAbsolutePath(const io::path& filename) const
{
	fschar_t *p=0;

#if defined(_IRR_WINDOWS_CE_PLATFORM_)
	return filename;
#elif defined(_IRR_WINDOWS_API_)

	#if defined(_IRR_WCHAR_FILESYSTEM )
		c16 fpath[_MAX_PATH];
		p = _wfullpath(fpath, filename.c_str(), _MAX_PATH);
	#else
		c8 fpath[_MAX_PATH];
		p = _fullpath(fpath, filename.c_str(), _MAX_PATH);
	#endif

#elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_))
	c8 fpath[4096];
	fpath[0]=0;
	p = realpath(filename.c_str(), fpath);
	if (!p)
	{
		// content in fpath is undefined at this point
		if (!fpath[0]) // seems like fpath wasn't altered
		{
			// at least remove a ./ prefix
			if ('.'==filename[0] && '/'==filename[1])
				return filename.subString(2, filename.size()-2);
			else
				return filename;
		}
		else
			return io::path(fpath);
	}

#endif

	return io::path(p);
}
Пример #29
0
// TODO move to platform
static void openrct2_set_exe_path()
{
#ifdef _WIN32
	wchar_t exePath[MAX_PATH];
	wchar_t tempPath[MAX_PATH];
	wchar_t *exeDelimiter;
	int exeDelimiterIndex;

	GetModuleFileNameW(NULL, exePath, MAX_PATH);
	exeDelimiter = wcsrchr(exePath, platform_get_path_separator());
	exeDelimiterIndex = (int)(exeDelimiter - exePath);
	lstrcpynW(tempPath, exePath, exeDelimiterIndex + 1);
	tempPath[exeDelimiterIndex] = L'\0';
	_wfullpath(exePath, tempPath, MAX_PATH);
	WideCharToMultiByte(CP_UTF8, 0, exePath, countof(exePath), gExePath, countof(gExePath), NULL, NULL);
#else
	char exePath[MAX_PATH];
	ssize_t bytesRead;
	bytesRead = readlink("/proc/self/exe", exePath, MAX_PATH);
	if (bytesRead == -1) {
		log_fatal("failed to read /proc/self/exe");
	}
	exePath[bytesRead] = '\0';
	log_verbose("######################################## Setting exe path to %s", exePath);
	char *exeDelimiter = strrchr(exePath, platform_get_path_separator());
	if (exeDelimiter == NULL)
	{
		log_error("should never happen here");
		gExePath[0] = '\0';
		return;
	}
	int exeDelimiterIndex = (int)(exeDelimiter - exePath);

	safe_strncpy(gExePath, exePath, exeDelimiterIndex + 1);
	gExePath[exeDelimiterIndex] = '\0';
#endif // _WIN32
}
Пример #30
0
wchar_t* fullpath(wchar_t * out, const wchar_t * in, std::size_t size)
{
	return _wfullpath(out, in, size);
}