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/. */
8 #include "win_dirent.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);
28 if (findHandle
!= INVALID_HANDLE_VALUE
)
30 FindClose(findHandle
);
40 opendir(const WCHAR
* path
)
52 dirent
* readdir(DIR* dir
)
54 WIN32_FIND_DATAW data
;
55 if (dir
->findHandle
!= INVALID_HANDLE_VALUE
)
57 BOOL result
= FindNextFileW(dir
->findHandle
, &data
);
60 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
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
)
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]));