Skip to content

Commit 156b282

Browse files
committed
xrCore: remove cast from (const char*) to (char*) for convert_path_separators()
1 parent a7116e8 commit 156b282

File tree

6 files changed

+42
-30
lines changed

6 files changed

+42
-30
lines changed

src/xrCore/FS.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ XRCORE_API void dump_file_mappings()
7777
// Tools
7878
//////////////////////////////////////////////////////////////////////
7979
//---------------------------------------------------
80-
void VerifyPath(LPCSTR path)
80+
void VerifyPath(pcstr path)
8181
{
8282
string1024 tmp;
8383
for (int i = 0; path[i]; i++)
@@ -88,12 +88,10 @@ void VerifyPath(LPCSTR path)
8888
tmp[i] = 0;
8989
_mkdir(tmp);
9090
}
91-
92-
convert_path_separators((char *)path);
9391
}
9492

9593
#ifdef _EDITOR
96-
bool file_handle_internal(LPCSTR file_name, u32& size, int& hFile)
94+
bool file_handle_internal(pcstr file_name, u32& size, int& hFile)
9795
{
9896
hFile = _open(file_name, O_RDONLY | O_BINARY | O_SEQUENTIAL);
9997
if (hFile <= 0)
@@ -108,19 +106,21 @@ bool file_handle_internal(LPCSTR file_name, u32& size, int& hFile)
108106
return (true);
109107
}
110108
#else // EDITOR
111-
static int open_internal(LPCSTR fn, int& handle)
109+
static int open_internal(pcstr fn, int& handle)
112110
{
113-
convert_path_separators((char *)fn);
114111
#if defined(WINDOWS)
115112
return (_sopen_s(&handle, fn, _O_RDONLY | _O_BINARY, _SH_DENYNO, _S_IREAD));
116113
#elif defined(LINUX)
117-
handle = open(fn, _O_RDONLY);
114+
pstr conv_fn = xr_strdup(fn);
115+
convert_path_separators(conv_fn);
116+
handle = open(conv_fn, _O_RDONLY);
117+
xr_free(conv_fn);
118118

119119
return (handle == -1);
120120
#endif
121121
}
122122

123-
bool file_handle_internal(LPCSTR file_name, u32& size, int& file_handle)
123+
bool file_handle_internal(pcstr file_name, u32& size, int& file_handle)
124124
{
125125
if (open_internal(file_name, file_handle))
126126
{
@@ -494,7 +494,7 @@ CPackReader::~CPackReader()
494494
};
495495
//---------------------------------------------------
496496
// file stream
497-
CFileReader::CFileReader(const char* name)
497+
CFileReader::CFileReader(pcstr name)
498498
{
499499
data = (char*)FileDownload(name, (u32*)&Size);
500500
Pos = 0;
@@ -508,9 +508,8 @@ CCompressedReader::CCompressedReader(const char* name, const char* sign)
508508
Pos = 0;
509509
}
510510
CCompressedReader::~CCompressedReader() { xr_free(data); };
511-
CVirtualFileRW::CVirtualFileRW(const char* cFileName)
511+
CVirtualFileRW::CVirtualFileRW(pcstr cFileName)
512512
{
513-
convert_path_separators((char *)cFileName);
514513
#if defined(WINDOWS)
515514
// Open the file
516515
hSrcFile = CreateFile(cFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
@@ -524,7 +523,10 @@ CVirtualFileRW::CVirtualFileRW(const char* cFileName)
524523
data = (char*)MapViewOfFile(hSrcMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
525524
R_ASSERT3(data, cFileName, xrDebug::ErrorToString(GetLastError()));
526525
#elif defined(LINUX)
527-
hSrcFile = ::open(cFileName, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет
526+
pstr conv_path = xr_strdup(cFileName);
527+
convert_path_separators(conv_path);
528+
hSrcFile = ::open(conv_path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет
529+
xr_free(conv_path);
528530
R_ASSERT3(hSrcFile != -1, cFileName, xrDebug::ErrorToString(GetLastError()));
529531
struct stat file_info;
530532
::fstat(hSrcFile, &file_info);
@@ -553,9 +555,8 @@ CVirtualFileRW::~CVirtualFileRW()
553555
#endif
554556
}
555557

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

569570
data = (char*)MapViewOfFile(hSrcMap, FILE_MAP_READ, 0, 0, 0);
570571
#elif defined(LINUX)
571-
hSrcFile = ::open(cFileName, O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет
572+
pstr conv_path = xr_strdup(cFileName);
573+
convert_path_separators(conv_path);
574+
hSrcFile = ::open(conv_path, O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет
575+
xr_free(conv_path);
572576
R_ASSERT3(hSrcFile != -1, cFileName, xrDebug::ErrorToString(GetLastError()));
573577
struct stat file_info;
574578
::fstat(hSrcFile, &file_info);

src/xrCore/FS.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define CFS_CompressMark (1ul << 31ul)
1919
#define CFS_HeaderChunkID (666)
2020

21-
XRCORE_API void VerifyPath(LPCSTR path);
21+
XRCORE_API void VerifyPath(pcstr path);
2222

2323
//#define FS_DEBUG
2424

@@ -416,7 +416,7 @@ class XRCORE_API CVirtualFileRW : public IReader
416416
#endif
417417

418418
public:
419-
CVirtualFileRW(const char* cFileName);
419+
CVirtualFileRW(pcstr cFileName);
420420
virtual ~CVirtualFileRW();
421421
};
422422

src/xrCore/FS_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class CPackReader : public IReader
112112
class XRCORE_API CFileReader : public IReader
113113
{
114114
public:
115-
CFileReader(const char* name);
115+
CFileReader(pcstr name);
116116
virtual ~CFileReader();
117117
};
118118
class CCompressedReader : public IReader
@@ -131,7 +131,7 @@ class CVirtualFileReader : public IReader
131131
#endif
132132

133133
public:
134-
CVirtualFileReader(const char* cFileName);
134+
CVirtualFileReader(pcstr cFileName);
135135
virtual ~CVirtualFileReader();
136136
};
137137

src/xrCore/LocatorAPI.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ void CLocatorAPI::LoadArchive(archive& A, pcstr entrypoint)
442442

443443
void CLocatorAPI::archive::open()
444444
{
445-
convert_path_separators((char *)*path);
446445
#if defined(WINDOWS)
447446
// Open the file
448447
if (hSrcFile && hSrcMap)
@@ -458,7 +457,10 @@ void CLocatorAPI::archive::open()
458457
if (hSrcFile)
459458
return;
460459

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

619-
bool ignore_path(const char* _path)
621+
bool ignore_path(pcstr _path)
620622
{
621-
convert_path_separators((char *)_path);
622623
#if defined(WINDOWS)
623624
HANDLE h = CreateFile(_path, 0, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY | FILE_FLAG_NO_BUFFERING, nullptr);
624625

@@ -630,7 +631,10 @@ bool ignore_path(const char* _path)
630631
else
631632
return true;
632633
#elif defined(LINUX)
633-
int h = ::open(_path, O_RDONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
634+
pstr conv_path = xr_strdup(_path);
635+
convert_path_separators(conv_path);
636+
int h = ::open(conv_path, O_RDONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
637+
xr_free(conv_path);
634638
if (h != -1)
635639
{
636640
::close(h);
@@ -1694,8 +1698,11 @@ void CLocatorAPI::file_rename(pcstr src, pcstr dest, bool overwrite)
16941698
m_files.insert(new_desc);
16951699

16961700
// physically rename file
1697-
VerifyPath(dest);
1698-
rename(src, dest);
1701+
pstr conv_dest = xr_strdup(dest);
1702+
convert_path_separators(conv_dest);
1703+
VerifyPath(conv_dest);
1704+
rename(src, conv_dest);
1705+
xr_free(conv_dest);
16991706
}
17001707
}
17011708

src/xrCore/LocatorAPI_defs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ FS_Path::FS_Path(LPCSTR _Root, LPCSTR _Add, LPCSTR _DefExt, LPCSTR _FilterCaptio
5151
m_Flags.assign(flags);
5252
#ifdef _EDITOR
5353
// Editor(s)/User(s) wants pathes already created in "real" file system :)
54+
convert_path_separators(m_Path);
5455
VerifyPath(m_Path);
5556
#endif
5657
}

src/xrCore/file_stream_reader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ void CFileStreamReader::construct(LPCSTR file_name, const u32& window_size)
1717

1818
inherited::construct(file_mapping_handle, 0, file_size, file_size, window_size);
1919
#elif defined(LINUX)
20-
char path[PATH_MAX] = { 0 };
21-
strcpy(path, file_name);
22-
convert_path_separators(path);
23-
m_file_handle = ::open(path, O_RDONLY);
20+
pstr conv_fn = xr_strdup(file_name);
21+
convert_path_separators(conv_fn);
22+
m_file_handle = ::open(conv_fn, O_RDONLY);
23+
xr_free(conv_fn);
2424
VERIFY(m_file_handle != -1);
2525
struct stat file_info;
2626
::fstat(m_file_handle, &file_info);

0 commit comments

Comments
 (0)