nss: upgrade to release 3.73
[LibreOffice.git] / onlineupdate / source / update / updater / win_dirent.cxx
blob2368613ee42bbe8d51bd21250ad5fa9c7ade2a5a
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifdef _WIN32
8 #include "win_dirent.h"
9 #include <errno.h>
10 #include <string.h>
12 // This file implements the minimum set of dirent APIs used by updater.cpp on
13 // Windows. If updater.cpp is modified to use more of this API, we need to
14 // implement those parts here too.
16 static dirent gDirEnt;
18 DIR::DIR(const WCHAR* path)
19 : findHandle(INVALID_HANDLE_VALUE)
21 memset(name, 0, sizeof(name));
22 wcsncpy(name, path, sizeof(name)/sizeof(name[0]));
23 wcsncat(name, L"\\*", sizeof(name)/sizeof(name[0]) - wcslen(name) - 1);
26 DIR::~DIR()
28 if (findHandle != INVALID_HANDLE_VALUE)
30 FindClose(findHandle);
34 dirent::dirent()
36 d_name[0] = L'\0';
39 DIR*
40 opendir(const WCHAR* path)
42 return new DIR(path);
45 int
46 closedir(DIR* dir)
48 delete dir;
49 return 0;
52 dirent* readdir(DIR* dir)
54 WIN32_FIND_DATAW data;
55 if (dir->findHandle != INVALID_HANDLE_VALUE)
57 BOOL result = FindNextFileW(dir->findHandle, &data);
58 if (!result)
60 if (GetLastError() != ERROR_FILE_NOT_FOUND)
62 errno = ENOENT;
64 return 0;
67 else
69 // Reading the first directory entry
70 dir->findHandle = FindFirstFileW(dir->name, &data);
71 if (dir->findHandle == INVALID_HANDLE_VALUE)
73 if (GetLastError() == ERROR_FILE_NOT_FOUND)
75 errno = ENOENT;
77 else
79 errno = EBADF;
81 return 0;
84 memset(gDirEnt.d_name, 0, sizeof(gDirEnt.d_name));
85 wcsncpy(gDirEnt.d_name, data.cFileName,
86 sizeof(gDirEnt.d_name)/sizeof(gDirEnt.d_name[0]));
87 return &gDirEnt;
89 #endif