diff options
Diffstat (limited to 'src/components/utils')
-rw-r--r-- | src/components/utils/src/file_system.cc | 54 |
1 files changed, 6 insertions, 48 deletions
diff --git a/src/components/utils/src/file_system.cc b/src/components/utils/src/file_system.cc index 91ff0c3b07..2e3a815be9 100644 --- a/src/components/utils/src/file_system.cc +++ b/src/components/utils/src/file_system.cc @@ -68,24 +68,14 @@ int64_t file_system::FileSize(const std::string& path) { size_t file_system::DirectorySize(const std::string& path) { size_t size = 0; - int32_t return_code = 0; DIR* directory = NULL; -#ifndef __QNXNTO__ - struct dirent dir_element_; - struct dirent* dir_element = &dir_element_; -#else - char* direntbuffer = new char[offsetof(struct dirent, d_name) + - pathconf(path.c_str(), _PC_NAME_MAX) + 1]; - struct dirent* dir_element = new (direntbuffer) dirent; -#endif struct dirent* result = NULL; struct stat file_info = {0}; directory = opendir(path.c_str()); if (NULL != directory) { - return_code = readdir_r(directory, dir_element, &result); - for (; NULL != result && 0 == return_code; - return_code = readdir_r(directory, dir_element, &result)) { + result = readdir(directory); + for (; NULL != result; result = readdir(directory)) { if (0 == strcmp(result->d_name, "..") || 0 == strcmp(result->d_name, ".")) { continue; @@ -100,9 +90,6 @@ size_t file_system::DirectorySize(const std::string& path) { } } closedir(directory); -#ifdef __QNXNTO__ - delete[] direntbuffer; -#endif return size; } @@ -230,26 +217,15 @@ bool file_system::DeleteFile(const std::string& name) { } void file_system::remove_directory_content(const std::string& directory_name) { - int32_t return_code = 0; DIR* directory = NULL; -#ifndef __QNXNTO__ - struct dirent dir_element_; - struct dirent* dir_element = &dir_element_; -#else - char* direntbuffer = - new char[offsetof(struct dirent, d_name) + - pathconf(directory_name.c_str(), _PC_NAME_MAX) + 1]; - struct dirent* dir_element = new (direntbuffer) dirent; -#endif struct dirent* result = NULL; directory = opendir(directory_name.c_str()); if (NULL != directory) { - return_code = readdir_r(directory, dir_element, &result); + result = readdir(directory); - for (; NULL != result && 0 == return_code; - return_code = readdir_r(directory, dir_element, &result)) { + for (; NULL != result; result = readdir(directory)) { if (0 == strcmp(result->d_name, "..") || 0 == strcmp(result->d_name, ".")) { continue; @@ -267,9 +243,6 @@ void file_system::remove_directory_content(const std::string& directory_name) { } closedir(directory); -#ifdef __QNXNTO__ - delete[] direntbuffer; -#endif } bool file_system::RemoveDirectory(const std::string& directory_name, @@ -303,25 +276,14 @@ std::vector<std::string> file_system::ListFiles( return listFiles; } - int32_t return_code = 0; DIR* directory = NULL; -#ifndef __QNXNTO__ - struct dirent dir_element_; - struct dirent* dir_element = &dir_element_; -#else - char* direntbuffer = - new char[offsetof(struct dirent, d_name) + - pathconf(directory_name.c_str(), _PC_NAME_MAX) + 1]; - struct dirent* dir_element = new (direntbuffer) dirent; -#endif struct dirent* result = NULL; directory = opendir(directory_name.c_str()); if (NULL != directory) { - return_code = readdir_r(directory, dir_element, &result); + result = readdir(directory); - for (; NULL != result && 0 == return_code; - return_code = readdir_r(directory, dir_element, &result)) { + for (; NULL != result; result = readdir(directory)) { if (0 == strcmp(result->d_name, "..") || 0 == strcmp(result->d_name, ".")) { continue; @@ -333,10 +295,6 @@ std::vector<std::string> file_system::ListFiles( closedir(directory); } -#ifdef __QNXNTO__ - delete[] direntbuffer; -#endif - return listFiles; } |