From bae02f20b4811692c66f7640af6b7273ba2e47e9 Mon Sep 17 00:00:00 2001
From: "Paul \"Dettorer\" Hervot"
Date: Sun, 29 Nov 2015 08:46:04 +0100
Subject: [PATCH] File_util: Fix signedness and precision warnings
---
src/common/file_util.cpp | 24 ++++++++++++------------
src/common/file_util.h | 2 +-
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 4c7113390..cdc6bbdbc 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -306,7 +306,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
while (!feof(input))
{
// read input
- int rnum = fread(buffer, sizeof(char), BSIZE, input);
+ size_t rnum = fread(buffer, sizeof(char), BSIZE, input);
if (rnum != BSIZE)
{
if (ferror(input) != 0)
@@ -319,7 +319,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
}
// write output
- int wnum = fwrite(buffer, sizeof(char), rnum, output);
+ size_t wnum = fwrite(buffer, sizeof(char), rnum, output);
if (wnum != rnum)
{
LOG_ERROR(Common_Filesystem,
@@ -365,7 +365,7 @@ u64 GetSize(const std::string &filename)
{
LOG_TRACE(Common_Filesystem, "%s: %lld",
filename.c_str(), (long long)buf.st_size);
- return buf.st_size;
+ return static_cast(buf.st_size);
}
LOG_ERROR(Common_Filesystem, "Stat failed %s: %s",
@@ -382,26 +382,26 @@ u64 GetSize(const int fd)
fd, GetLastErrorMsg());
return 0;
}
- return buf.st_size;
+ return static_cast(buf.st_size);
}
// Overloaded GetSize, accepts FILE*
u64 GetSize(FILE *f)
{
// can't use off_t here because it can be 32-bit
- u64 pos = ftello(f);
+ s64 pos = ftello(f);
if (fseeko(f, 0, SEEK_END) != 0) {
LOG_ERROR(Common_Filesystem, "GetSize: seek failed %p: %s",
f, GetLastErrorMsg());
return 0;
}
- u64 size = ftello(f);
+ s64 size = ftello(f);
if ((size != pos) && (fseeko(f, pos, SEEK_SET) != 0)) {
LOG_ERROR(Common_Filesystem, "GetSize: seek failed %p: %s",
f, GetLastErrorMsg());
return 0;
}
- return size;
+ return static_cast(size);
}
// creates an empty file filename, returns true on success
@@ -827,7 +827,7 @@ void SplitFilename83(const std::string& filename, std::array& short_nam
point = filename.rfind('.', point);
// Get short name.
- int j = 0;
+ size_t j = 0;
for (char letter : filename.substr(0, point)) {
if (forbidden_characters.find(letter, 0) != std::string::npos)
continue;
@@ -838,14 +838,14 @@ void SplitFilename83(const std::string& filename, std::array& short_nam
short_name[7] = '1';
break;
}
- short_name[j++] = toupper(letter);
+ short_name[j++] = static_cast(toupper(letter));
}
// Get extension.
if (point != std::string::npos) {
j = 0;
for (char letter : filename.substr(point + 1, 3))
- extension[j++] = toupper(letter);
+ extension[j++] = static_cast(toupper(letter));
}
}
@@ -938,7 +938,7 @@ bool IOFile::Seek(s64 off, int origin)
return m_good;
}
-u64 IOFile::Tell()
+s64 IOFile::Tell()
{
if (IsOpen())
return ftello(m_file);
@@ -963,7 +963,7 @@ bool IOFile::Resize(u64 size)
_chsize_s(_fileno(m_file), size)
#else
// TODO: handle 64bit and growing
- ftruncate(fileno(m_file), size)
+ ftruncate(fileno(m_file), static_cast(size))
#endif
)
m_good = false;
diff --git a/src/common/file_util.h b/src/common/file_util.h
index a85121aa6..ddf30c741 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -248,7 +248,7 @@ public:
void SetHandle(std::FILE* file);
bool Seek(s64 off, int origin);
- u64 Tell();
+ s64 Tell();
u64 GetSize();
bool Resize(u64 size);
bool Flush();