diff options
author | kaliki <kaliki@yandex-team.ru> | 2022-02-10 16:48:06 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:06 +0300 |
commit | a79404df3a1d90f4b37ac8a1ce0a2bfb5dfd06f1 (patch) | |
tree | 3302aab790ee7891a6ed0b4b9257ab4dd02ae4c1 /util/folder/dirent_win.c | |
parent | b552921bb1c7ea535f6e0e1706feb311c27d6036 (diff) | |
download | ydb-a79404df3a1d90f4b37ac8a1ce0a2bfb5dfd06f1.tar.gz |
Restoring authorship annotation for <kaliki@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/folder/dirent_win.c')
-rw-r--r-- | util/folder/dirent_win.c | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/util/folder/dirent_win.c b/util/folder/dirent_win.c index 7e6db74ce5..9e426b199a 100644 --- a/util/folder/dirent_win.c +++ b/util/folder/dirent_win.c @@ -1,13 +1,13 @@ #include <util/system/defaults.h> - -#ifdef _win_ - + +#ifdef _win_ + #include <stdio.h> #include "dirent_win.h" - + #if defined(_MSC_VER) && (_MSC_VER < 1900) -void __cdecl _dosmaperr(unsigned long); - +void __cdecl _dosmaperr(unsigned long); + static void SetErrno() { _dosmaperr(GetLastError()); } @@ -29,11 +29,11 @@ struct DIR* opendir(const char* dirname) { dir->file_no = 0; dir->readdir_buf = NULL; - int len = strlen(dirname); - //Remove trailing slashes + int len = strlen(dirname); + //Remove trailing slashes while (len && (dirname[len - 1] == '\\' || dirname[len - 1] == '/')) { --len; - } + } int len_converted = MultiByteToWideChar(CP_UTF8, 0, dirname, len, 0, 0); if (len_converted == 0) { closedir(dir); @@ -53,42 +53,42 @@ struct DIR* opendir(const char* dirname) { SetErrno(); closedir(dir); return NULL; - } - - return dir; -} + } + return dir; +} + int closedir(struct DIR* dir) { if (dir->sh != INVALID_HANDLE_VALUE) FindClose(dir->sh); - free(dir->fff_templ); - free(dir->readdir_buf); - free(dir); - return 0; -} - + free(dir->fff_templ); + free(dir->readdir_buf); + free(dir); + return 0; +} + int readdir_r(struct DIR* dir, struct dirent* entry, struct dirent** result) { if (!FindNextFileW(dir->sh, &dir->wfd)) { - int err = GetLastError(); - *result = 0; - if (err == ERROR_NO_MORE_FILES) { - SetLastError(0); - return 0; - } else { - return err; - } - } - entry->d_fileno = dir->file_no++; - entry->d_reclen = sizeof(struct dirent); + int err = GetLastError(); + *result = 0; + if (err == ERROR_NO_MORE_FILES) { + SetLastError(0); + return 0; + } else { + return err; + } + } + entry->d_fileno = dir->file_no++; + entry->d_reclen = sizeof(struct dirent); if (dir->wfd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && (dir->wfd.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT || dir->wfd.dwReserved0 == IO_REPARSE_TAG_SYMLINK)) { - entry->d_type = DT_LNK; + entry->d_type = DT_LNK; } else if (dir->wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - entry->d_type = DT_DIR; - } else { - entry->d_type = DT_REG; - } + entry->d_type = DT_DIR; + } else { + entry->d_type = DT_REG; + } int len = lstrlenW(dir->wfd.cFileName); int conv_len = WideCharToMultiByte(CP_UTF8, 0, dir->wfd.cFileName, len, 0, 0, 0, 0); if (conv_len == 0) { @@ -101,25 +101,25 @@ int readdir_r(struct DIR* dir, struct dirent* entry, struct dirent** result) { entry->d_namlen = conv_len; WideCharToMultiByte(CP_UTF8, 0, dir->wfd.cFileName, len, entry->d_name, conv_len, 0, 0); entry->d_name[conv_len] = 0; - *result = entry; - return 0; -} - + *result = entry; + return 0; +} + struct dirent* readdir(struct DIR* dir) { struct dirent* res; if (!dir->readdir_buf) { - dir->readdir_buf = (struct dirent*)malloc(sizeof(struct dirent)); + dir->readdir_buf = (struct dirent*)malloc(sizeof(struct dirent)); if (dir->readdir_buf == 0) return 0; } - readdir_r(dir, dir->readdir_buf, &res); - return res; -} - + readdir_r(dir, dir->readdir_buf, &res); + return res; +} + void rewinddir(struct DIR* dir) { - FindClose(dir->sh); + FindClose(dir->sh); dir->sh = FindFirstFileW(dir->fff_templ, &dir->wfd); - dir->file_no = 0; -} - -#endif //_win_ + dir->file_no = 0; +} + +#endif //_win_ |