mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-26 15:39:03 +08:00
better support for file size in 64 bits
This commit is contained in:
parent
730f0e02a6
commit
74aede0c66
@ -100,9 +100,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (!_fd)
|
if (!_fd)
|
||||||
throw spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename));
|
throw spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename));
|
||||||
|
return os::filesize(_fd);
|
||||||
return os::filesize(_fd);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const filename_t& filename() const
|
const filename_t& filename() const
|
||||||
|
@ -186,43 +186,41 @@ inline bool file_exists(const filename_t& filename)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Return file size according to open FILE* object
|
//Return file size according to open FILE* object
|
||||||
inline size_t filesize(FILE *f)
|
inline size_t filesize(FILE *f)
|
||||||
{
|
{
|
||||||
|
if (f == nullptr)
|
||||||
|
throw spdlog_ex("Failed getting file size. fd is null");
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#if _WIN64 //64 bits
|
|
||||||
int fd = _fileno(f);
|
int fd = _fileno(f);
|
||||||
|
#if _WIN64 //64 bits
|
||||||
struct _stat64 st;
|
struct _stat64 st;
|
||||||
if (_fstat64(fd, &st) == 0)
|
if (_fstat64(fd, &st) == 0)
|
||||||
return st.st_size;
|
return st.st_size;
|
||||||
else
|
|
||||||
throw spdlog_ex("Failed getting file size from fd", errno);
|
#else //windows 32 bits
|
||||||
#else //windows 32 bits
|
|
||||||
int fd = _fileno(f);
|
|
||||||
struct _stat st;
|
struct _stat st;
|
||||||
if (_fstat(fd, &st) == 0)
|
if (_fstat(fd, &st) == 0)
|
||||||
return st.st_size;
|
return st.st_size;
|
||||||
else
|
|
||||||
throw spdlog_ex("Failed getting file size from fd", errno);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else// common unix
|
#else // unix
|
||||||
#if __x86_64__ || __ppc64__ //64 bits
|
int fd = fileno(f);
|
||||||
int fd = fileno(f)
|
//64 bits(but not in osx, where fstat64 is deprecated)
|
||||||
|
#if !defined(__APPLE__) && (defined(__x86_64__) || defined(__ppc64__))
|
||||||
struct stat64 st;
|
struct stat64 st;
|
||||||
if (fstat64(fd, &st) == 0)
|
if (fstat64(fd, &st) == 0)
|
||||||
return st.st_size;
|
return st.st_size;
|
||||||
else
|
#else // unix 32 bits or osx
|
||||||
throw spdlog_ex("Failed getting file size from fd", errno);
|
struct stat st;
|
||||||
#else //unix 32 bits
|
|
||||||
int fd = fileno(f)
|
|
||||||
struct stat st;
|
|
||||||
if (fstat(fd, &st) == 0)
|
if (fstat(fd, &st) == 0)
|
||||||
return st.st_size;
|
return st.st_size;
|
||||||
else
|
|
||||||
throw spdlog_ex("Failed getting file size from fd", errno);
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
throw spdlog_ex("Failed getting file size from fd", errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user