LibreOffice Module onlineupdate (master) 1
win_dirent.cxx
Go to the documentation of this file.
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/. */
6
7#ifdef _WIN32
8#include "win_dirent.h"
9#include <errno.h>
10#include <string.h>
11
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.
15
16static dirent gDirEnt;
17
18DIR::DIR(const WCHAR* path)
19 : findHandle(INVALID_HANDLE_VALUE)
20{
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);
24}
25
26DIR::~DIR()
27{
28 if (findHandle != INVALID_HANDLE_VALUE)
29 {
30 FindClose(findHandle);
31 }
32}
33
34dirent::dirent()
35{
36 d_name[0] = L'\0';
37}
38
39DIR*
40opendir(const WCHAR* path)
41{
42 return new DIR(path);
43}
44
45int
46closedir(DIR* dir)
47{
48 delete dir;
49 return 0;
50}
51
52dirent* readdir(DIR* dir)
53{
54 WIN32_FIND_DATAW data;
55 if (dir->findHandle != INVALID_HANDLE_VALUE)
56 {
57 BOOL result = FindNextFileW(dir->findHandle, &data);
58 if (!result)
59 {
60 if (GetLastError() != ERROR_FILE_NOT_FOUND)
61 {
62 errno = ENOENT;
63 }
64 return 0;
65 }
66 }
67 else
68 {
69 // Reading the first directory entry
70 dir->findHandle = FindFirstFileW(dir->name, &data);
71 if (dir->findHandle == INVALID_HANDLE_VALUE)
72 {
73 if (GetLastError() == ERROR_FILE_NOT_FOUND)
74 {
75 errno = ENOENT;
76 }
77 else
78 {
79 errno = EBADF;
80 }
81 return 0;
82 }
83 }
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;
88}
89#endif
const wchar_t *typedef BOOL
Any result