Skip to content

Commit

Permalink
xrCore: remove cast from (const char*) to (char*) for convert_path_se…
Browse files Browse the repository at this point in the history
…parators()
  • Loading branch information
eagleivg committed Nov 8, 2018
1 parent a7116e8 commit 156b282
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 30 deletions.
34 changes: 19 additions & 15 deletions src/xrCore/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ XRCORE_API void dump_file_mappings()
// Tools
//////////////////////////////////////////////////////////////////////
//---------------------------------------------------
void VerifyPath(LPCSTR path)
void VerifyPath(pcstr path)
{
string1024 tmp;
for (int i = 0; path[i]; i++)
Expand All @@ -88,12 +88,10 @@ void VerifyPath(LPCSTR path)
tmp[i] = 0;
_mkdir(tmp);
}

convert_path_separators((char *)path);
}

#ifdef _EDITOR
bool file_handle_internal(LPCSTR file_name, u32& size, int& hFile)
bool file_handle_internal(pcstr file_name, u32& size, int& hFile)
{
hFile = _open(file_name, O_RDONLY | O_BINARY | O_SEQUENTIAL);
if (hFile <= 0)
Expand All @@ -108,19 +106,21 @@ bool file_handle_internal(LPCSTR file_name, u32& size, int& hFile)
return (true);
}
#else // EDITOR
static int open_internal(LPCSTR fn, int& handle)
static int open_internal(pcstr fn, int& handle)
{
convert_path_separators((char *)fn);
#if defined(WINDOWS)
return (_sopen_s(&handle, fn, _O_RDONLY | _O_BINARY, _SH_DENYNO, _S_IREAD));
#elif defined(LINUX)
handle = open(fn, _O_RDONLY);
pstr conv_fn = xr_strdup(fn);
convert_path_separators(conv_fn);
handle = open(conv_fn, _O_RDONLY);
xr_free(conv_fn);

return (handle == -1);
#endif
}

bool file_handle_internal(LPCSTR file_name, u32& size, int& file_handle)
bool file_handle_internal(pcstr file_name, u32& size, int& file_handle)
{
if (open_internal(file_name, file_handle))
{
Expand Down Expand Up @@ -494,7 +494,7 @@ CPackReader::~CPackReader()
};
//---------------------------------------------------
// file stream
CFileReader::CFileReader(const char* name)
CFileReader::CFileReader(pcstr name)
{
data = (char*)FileDownload(name, (u32*)&Size);
Pos = 0;
Expand All @@ -508,9 +508,8 @@ CCompressedReader::CCompressedReader(const char* name, const char* sign)
Pos = 0;
}
CCompressedReader::~CCompressedReader() { xr_free(data); };
CVirtualFileRW::CVirtualFileRW(const char* cFileName)
CVirtualFileRW::CVirtualFileRW(pcstr cFileName)
{
convert_path_separators((char *)cFileName);
#if defined(WINDOWS)
// Open the file
hSrcFile = CreateFile(cFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
Expand All @@ -524,7 +523,10 @@ CVirtualFileRW::CVirtualFileRW(const char* cFileName)
data = (char*)MapViewOfFile(hSrcMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
R_ASSERT3(data, cFileName, xrDebug::ErrorToString(GetLastError()));
#elif defined(LINUX)
hSrcFile = ::open(cFileName, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет
pstr conv_path = xr_strdup(cFileName);
convert_path_separators(conv_path);
hSrcFile = ::open(conv_path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет
xr_free(conv_path);
R_ASSERT3(hSrcFile != -1, cFileName, xrDebug::ErrorToString(GetLastError()));
struct stat file_info;
::fstat(hSrcFile, &file_info);
Expand Down Expand Up @@ -553,9 +555,8 @@ CVirtualFileRW::~CVirtualFileRW()
#endif
}

CVirtualFileReader::CVirtualFileReader(const char* cFileName)
CVirtualFileReader::CVirtualFileReader(pcstr cFileName)
{
convert_path_separators((char *)cFileName);
#if defined(WINDOWS)
// Open the file
hSrcFile = CreateFile(cFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
Expand All @@ -568,7 +569,10 @@ CVirtualFileReader::CVirtualFileReader(const char* cFileName)

data = (char*)MapViewOfFile(hSrcMap, FILE_MAP_READ, 0, 0, 0);
#elif defined(LINUX)
hSrcFile = ::open(cFileName, O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет
pstr conv_path = xr_strdup(cFileName);
convert_path_separators(conv_path);
hSrcFile = ::open(conv_path, O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет
xr_free(conv_path);
R_ASSERT3(hSrcFile != -1, cFileName, xrDebug::ErrorToString(GetLastError()));
struct stat file_info;
::fstat(hSrcFile, &file_info);
Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define CFS_CompressMark (1ul << 31ul)
#define CFS_HeaderChunkID (666)

XRCORE_API void VerifyPath(LPCSTR path);
XRCORE_API void VerifyPath(pcstr path);

//#define FS_DEBUG

Expand Down Expand Up @@ -416,7 +416,7 @@ class XRCORE_API CVirtualFileRW : public IReader
#endif

public:
CVirtualFileRW(const char* cFileName);
CVirtualFileRW(pcstr cFileName);
virtual ~CVirtualFileRW();
};

Expand Down
4 changes: 2 additions & 2 deletions src/xrCore/FS_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class CPackReader : public IReader
class XRCORE_API CFileReader : public IReader
{
public:
CFileReader(const char* name);
CFileReader(pcstr name);
virtual ~CFileReader();
};
class CCompressedReader : public IReader
Expand All @@ -131,7 +131,7 @@ class CVirtualFileReader : public IReader
#endif

public:
CVirtualFileReader(const char* cFileName);
CVirtualFileReader(pcstr cFileName);
virtual ~CVirtualFileReader();
};

Expand Down
21 changes: 14 additions & 7 deletions src/xrCore/LocatorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ void CLocatorAPI::LoadArchive(archive& A, pcstr entrypoint)

void CLocatorAPI::archive::open()
{
convert_path_separators((char *)*path);
#if defined(WINDOWS)
// Open the file
if (hSrcFile && hSrcMap)
Expand All @@ -458,7 +457,10 @@ void CLocatorAPI::archive::open()
if (hSrcFile)
return;

hSrcFile = ::open(*path, O_RDONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
pstr conv_path = xr_strdup(path.c_str());
convert_path_separators(conv_path);
hSrcFile = ::open(conv_path, O_RDONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
xr_free(conv_path);
R_ASSERT(hSrcFile != -1);
struct stat file_info;
::fstat(hSrcFile, &file_info);
Expand Down Expand Up @@ -616,9 +618,8 @@ bool ignore_name(const char* _name)
// because Unicode file names can
// be interpolated by FindNextFile()

bool ignore_path(const char* _path)
bool ignore_path(pcstr _path)
{
convert_path_separators((char *)_path);
#if defined(WINDOWS)
HANDLE h = CreateFile(_path, 0, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY | FILE_FLAG_NO_BUFFERING, nullptr);

Expand All @@ -630,7 +631,10 @@ bool ignore_path(const char* _path)
else
return true;
#elif defined(LINUX)
int h = ::open(_path, O_RDONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
pstr conv_path = xr_strdup(_path);
convert_path_separators(conv_path);
int h = ::open(conv_path, O_RDONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
xr_free(conv_path);
if (h != -1)
{
::close(h);
Expand Down Expand Up @@ -1694,8 +1698,11 @@ void CLocatorAPI::file_rename(pcstr src, pcstr dest, bool overwrite)
m_files.insert(new_desc);

// physically rename file
VerifyPath(dest);
rename(src, dest);
pstr conv_dest = xr_strdup(dest);
convert_path_separators(conv_dest);
VerifyPath(conv_dest);
rename(src, conv_dest);
xr_free(conv_dest);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/xrCore/LocatorAPI_defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ FS_Path::FS_Path(LPCSTR _Root, LPCSTR _Add, LPCSTR _DefExt, LPCSTR _FilterCaptio
m_Flags.assign(flags);
#ifdef _EDITOR
// Editor(s)/User(s) wants pathes already created in "real" file system :)
convert_path_separators(m_Path);
VerifyPath(m_Path);
#endif
}
Expand Down
8 changes: 4 additions & 4 deletions src/xrCore/file_stream_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ void CFileStreamReader::construct(LPCSTR file_name, const u32& window_size)

inherited::construct(file_mapping_handle, 0, file_size, file_size, window_size);
#elif defined(LINUX)
char path[PATH_MAX] = { 0 };
strcpy(path, file_name);
convert_path_separators(path);
m_file_handle = ::open(path, O_RDONLY);
pstr conv_fn = xr_strdup(file_name);
convert_path_separators(conv_fn);
m_file_handle = ::open(conv_fn, O_RDONLY);
xr_free(conv_fn);
VERIFY(m_file_handle != -1);
struct stat file_info;
::fstat(m_file_handle, &file_info);
Expand Down

0 comments on commit 156b282

Please sign in to comment.