aboutsummaryrefslogtreecommitdiffstats
path: root/util/folder/dirent_win.c
diff options
context:
space:
mode:
authorkaliki <kaliki@yandex-team.ru>2022-02-10 16:48:06 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:06 +0300
commit9741dc538ed4ca44e947c0965a2bbc50305eb996 (patch)
treeb222e5ac2e2e98872661c51ccceee5da0d291e13 /util/folder/dirent_win.c
parenta79404df3a1d90f4b37ac8a1ce0a2bfb5dfd06f1 (diff)
downloadydb-9741dc538ed4ca44e947c0965a2bbc50305eb996.tar.gz
Restoring authorship annotation for <kaliki@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/folder/dirent_win.c')
-rw-r--r--util/folder/dirent_win.c98
1 files changed, 49 insertions, 49 deletions
diff --git a/util/folder/dirent_win.c b/util/folder/dirent_win.c
index 9e426b199a..7e6db74ce5 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_