Add ftell

This commit is contained in:
2021-12-31 10:08:00 +08:00
parent ac4fee1977
commit 1f6f0acf05
4 changed files with 24 additions and 0 deletions

View File

@@ -26,6 +26,8 @@ if (WIN32)
else()
check_symbol_exists(fseeko "stdio.h" HAVE_FSEEKO)
check_symbol_exists(fseeko64 "stdio.h" HAVE_FSEEKO64)
check_symbol_exists(ftello "stdio.h" HAVE_FTELLO)
check_symbol_exists(ftello64 "stdio.h" HAVE_FTELLO64)
endif()
check_symbol_exists(strerror_r "string.h" HAVE_STRERROR_R)
if (HAVE_STRERROR_R)

View File

@@ -440,3 +440,17 @@ int fileop::fseek(FILE* f, int64_t offset, int origin) {
bool fileop::mkdir_for_file(std::string path, int mode) {
return mkdirs(dirname(path), mode, true);
}
int64_t fileop::ftell(FILE* f) {
#if _WIN32
return ::_ftelli64(f);
#else
#if HAVE_FTELLO64
return ::ftello64(f);
#elif HAVE_FTELLO
return ::ftello(f);
#else
return ::ftell(f);
#endif
#endif
}

View File

@@ -148,5 +148,11 @@ namespace fileop {
* @return true if file's directory is exists now.
*/
bool mkdir_for_file(std::string path, int mode);
/**
* @brief Gets the current position of a file pointer.
* @param f Target FILE structure.
* @return The current position
*/
int64_t ftell(FILE* f);
}
#endif

View File

@@ -10,3 +10,5 @@
#cmakedefine HAVE_SSCANF_S @HAVE_SSCANF_S@
#cmakedefine HAVE_FSEEKO @HAVE_FSEEKO@
#cmakedefine HAVE_FSEEKO64 @HAVE_FSEEKO64@
#cmakedefine HAVE_FTELLO @HAVE_FTELLO@
#cmakedefine HAVE_FTELLO64 @HAVE_FTELLO64@