diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index e1a805ca1..ccc8bf3ef 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -48,7 +48,7 @@ #include //*********** -//#define FIM_DEBUG 1 +#define FIM_DEBUG 1 // ***********/ FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in,std::string cachedir, std::string pid,const std::string& config_dir) @@ -135,19 +135,10 @@ HashCache::HashCache(const std::string& path) f.getline(buff,max_line_size,'\n') ; //if(sscanf(buff,"%llu",&info.size) != 1) break ; info.size = 0 ; -#ifdef WINDOWS_SYS - sscanf(buff, UINT64FMT, &info.size); -#else - sscanf(buff, "%lu", &info.size); -#endif + sscanf(buff, RsDirUtil::scanf_string_for_uint(sizeof(info.size)), &info.size); -#ifdef WINDOWS_SYS - f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,UINT64FMT,&info.time_stamp) != 1) { std::cerr << "Could not read one entry! Giving up." << std::endl; break ; } - f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,UINT64FMT,&info.modf_stamp) != 1) { std::cerr << "Could not read one entry! Giving up." << std::endl; break ; } -#else - f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,"%lu",&info.time_stamp) != 1) { std::cerr << "Could not read one entry! Giving up." << std::endl; break ; } - f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,"%lu",&info.modf_stamp) != 1) { std::cerr << "Could not read one entry! Giving up." << std::endl; break ; } -#endif + f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,RsDirUtil::scanf_string_for_uint(sizeof(info.time_stamp)),&info.time_stamp) != 1) { std::cerr << "Could not read one entry! Giving up." << std::endl; break ; } + f.getline(buff,max_line_size,'\n') ; if(sscanf(buff,RsDirUtil::scanf_string_for_uint(sizeof(info.modf_stamp)),&info.modf_stamp) != 1) { std::cerr << "Could not read one entry! Giving up." << std::endl; break ; } f.getline(buff,max_line_size,'\n') ; info.hash = std::string(buff) ; if(info.hash.length() != 40) diff --git a/libretroshare/src/util/rsdir.cc b/libretroshare/src/util/rsdir.cc index 73cc56d50..7e910fcf6 100644 --- a/libretroshare/src/util/rsdir.cc +++ b/libretroshare/src/util/rsdir.cc @@ -159,6 +159,23 @@ bool RsDirUtil::crc32File(FILE *fd, uint64_t file_size,uint32_t chunk_size, CRC3 return true ; } +const char *RsDirUtil::scanf_string_for_uint(int bytes) +{ + const char *strgs[3] = { "%u","%lu","%llu" } ; + + std::cerr << "RsDirUtil::scanf_string_for_uint(): returning for bytes=" << bytes << std::endl; + + if(sizeof(unsigned int) == bytes) + return strgs[0] ; + if(sizeof(long unsigned int) == bytes) + return strgs[1] ; + if(sizeof(long long unsigned int) == bytes) + return strgs[2] ; + + std::cerr << "RsDirUtil::scanf_string_for_uint(): no corresponding scan string for "<< bytes << " bytes. This will probably cause inconsistencies." << std::endl; + return strgs[0] ; +} + void RsDirUtil::removeTopDir(const std::string& dir, std::string& path) { path.clear(); diff --git a/libretroshare/src/util/rsdir.h b/libretroshare/src/util/rsdir.h index c99a01ee8..435168f79 100644 --- a/libretroshare/src/util/rsdir.h +++ b/libretroshare/src/util/rsdir.h @@ -79,6 +79,12 @@ uint32_t rs_CRC32(const unsigned char *data,uint32_t len) ; // bool crc32File(FILE *f,uint64_t file_size,uint32_t chunk_size,CRC32Map& map) ; +// Returns %u, %lu, or %llu, depending on the size of unsigned int, unsigned long and unsigned long long on the current system. +// Use as; +// sscanf(string, RsDirUtil::scanf_string_for_uint( sizeof(X) ), &X) ; +// +const char *scanf_string_for_uint(int bytes) ; + int breakupDirList(const std::string& path, std::list &subdirs); bool copyFile(const std::string& source,const std::string& dest);