diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-10-16 18:49:11 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-16 18:49:11 -0400 |
| commit | 3e74d39f24fdfaa547ce900be177863e2bfe2dea (patch) | |
| tree | 9a5143e6de4caa27b23fc870003011e96129905f /source/core/slang-io.cpp | |
| parent | 204fb3c75b520a2cbb1c25f995a8c424ec2753f3 (diff) | |
Feature/include refactor (#675)
* Refactor of path handling.
* Added PathInfo
* Changed ISlangFileSystem - such that has separate concepts of reading a file, getting a relative path and getting a canonical path
* Added support for getting a canonical path for windows/linux
* Made maps/testing around canonicalPaths
* User output remains around 'foundPath' - which is the same as before
* Small improvements around PathInfo
* Added a type and make constructors to make clear the different 'path' uses
* Fixed bug in findViewRecursively
* Checking and reporting for ignored #pragma once.
* Removed SLANG_PATH_TYPE_NONE as doesn't serve any useful purpose.
* Improve comments in slang.h aroung ISlangFileSystem
* Remove the need for <windows.h> in slang-io.cpp
* Ran premake5.
* Improvements and fixes around PathInfo.
* Fix typo on linix GetCanonical
* Make the ISlangFileSystem the same as before, and ISlangFileSystem contain the new methods.
Internally it always uses the ISlangFileSystemExt, and will wrap a ISlangFileSystem with WrapFileSystem, if it is determined (via queryInterface) that it doesn't implement the full interface.
Diffstat (limited to 'source/core/slang-io.cpp')
| -rw-r--r-- | source/core/slang-io.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 24d5aa412..ab093f577 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -1,13 +1,20 @@ #include "slang-io.h" #include "exception.h" + #ifndef __STDC__ -#define __STDC__ 1 +# define __STDC__ 1 #endif + #include <sys/stat.h> + #ifdef _WIN32 -#include <direct.h> +# include <direct.h> #endif +#include <limits.h> /* PATH_MAX */ +#include <stdio.h> +#include <stdlib.h> + namespace Slang { bool File::Exists(const String & fileName) @@ -125,6 +132,32 @@ namespace Slang #endif } + /* static */SlangResult Path::GetCanonical(const String & path, String & canonicalPathOut) + { +#if defined(_WIN32) + // https://msdn.microsoft.com/en-us/library/506720ff.aspx + wchar_t* absPath = ::_wfullpath(nullptr, path.ToWString(), 0); + if (!absPath) + { + return SLANG_FAIL; + } + + canonicalPathOut = String::FromWString(absPath); + ::free(absPath); + return SLANG_OK; +#else + // http://man7.org/linux/man-pages/man3/realpath.3.html + char* canonicalPath = ::realpath(path.begin(), nullptr); + if (canonicalPath) + { + canonicalPathOut = canonicalPath; + ::free(canonicalPath); + return SLANG_OK; + } + return SLANG_FAIL; +#endif + } + Slang::String File::ReadAllText(const Slang::String & fileName) { StreamReader reader(new FileStream(fileName, FileMode::Open, FileAccess::Read, FileShare::ReadWrite)); @@ -152,4 +185,7 @@ namespace Slang StreamWriter writer(new FileStream(fileName, FileMode::Create)); writer.Write(text); } + + } + |
