diff --git a/CMakeLists.txt b/CMakeLists.txt index 694adb9..76e4a93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/fileop.cpp b/fileop.cpp index 9dbb362..1a99a0f 100644 --- a/fileop.cpp +++ b/fileop.cpp @@ -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 +} diff --git a/fileop.h b/fileop.h index cec6f0f..32ebf55 100644 --- a/fileop.h +++ b/fileop.h @@ -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 diff --git a/utils_config.h.in b/utils_config.h.in index 3a2f00c..27af2be 100644 --- a/utils_config.h.in +++ b/utils_config.h.in @@ -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@