forked from quick-lint/quick-lint-js
/
file-handle.h
71 lines (54 loc) · 1.78 KB
/
file-handle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// quick-lint-js finds bugs in JavaScript programs.
// Copyright (C) 2020 Matthew Glazar
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <optional>
#include <quick-lint-js/have.h>
#include <string>
#if QLJS_HAVE_WINDOWS_H
#include <Windows.h>
#endif
namespace quick_lint_js {
#if QLJS_HAVE_WINDOWS_H
std::string windows_error_message(DWORD error);
#endif
#if QLJS_HAVE_WINDOWS_H
class windows_handle_file {
public:
explicit windows_handle_file(HANDLE) noexcept;
windows_handle_file(const windows_handle_file &) = delete;
windows_handle_file &operator=(const windows_handle_file &) = delete;
~windows_handle_file();
HANDLE get() noexcept;
std::optional<int> read(void *buffer, int buffer_size) noexcept;
static std::string get_last_error_message();
private:
HANDLE handle_;
};
#endif
#if QLJS_HAVE_UNISTD_H
class posix_fd_file {
public:
explicit posix_fd_file(int fd) noexcept;
posix_fd_file(const posix_fd_file &) = delete;
posix_fd_file &operator=(const posix_fd_file &) = delete;
~posix_fd_file();
int get() noexcept;
std::optional<int> read(void *buffer, int buffer_size) noexcept;
static std::string get_last_error_message();
private:
int fd_;
};
#endif
}