@@ -38,7 +38,7 @@ class OnDiskBuffer : public FileOutputBuffer {
38
38
std::unique_ptr<fs::mapped_file_region> Buf)
39
39
: FileOutputBuffer(Path), Buffer(std::move(Buf)), TempPath(TempPath) {}
40
40
41
- static ErrorOr <std::unique_ptr<OnDiskBuffer>>
41
+ static Expected <std::unique_ptr<OnDiskBuffer>>
42
42
create (StringRef Path, size_t Size, unsigned Mode);
43
43
44
44
uint8_t *getBufferStart () const override { return (uint8_t *)Buffer->data (); }
@@ -78,13 +78,13 @@ class InMemoryBuffer : public FileOutputBuffer {
78
78
InMemoryBuffer (StringRef Path, MemoryBlock Buf, unsigned Mode)
79
79
: FileOutputBuffer(Path), Buffer(Buf), Mode(Mode) {}
80
80
81
- static ErrorOr <std::unique_ptr<InMemoryBuffer>>
81
+ static Expected <std::unique_ptr<InMemoryBuffer>>
82
82
create (StringRef Path, size_t Size, unsigned Mode) {
83
83
std::error_code EC;
84
84
MemoryBlock MB = Memory::allocateMappedMemory (
85
85
Size, nullptr , sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC);
86
86
if (EC)
87
- return EC ;
87
+ return errorCodeToError (EC) ;
88
88
return llvm::make_unique<InMemoryBuffer>(Path, MB, Mode);
89
89
}
90
90
@@ -111,13 +111,13 @@ class InMemoryBuffer : public FileOutputBuffer {
111
111
unsigned Mode;
112
112
};
113
113
114
- ErrorOr <std::unique_ptr<OnDiskBuffer>>
114
+ Expected <std::unique_ptr<OnDiskBuffer>>
115
115
OnDiskBuffer::create (StringRef Path, size_t Size, unsigned Mode) {
116
116
// Create new file in same directory but with random name.
117
117
SmallString<128 > TempPath;
118
118
int FD;
119
119
if (auto EC = fs::createUniqueFile (Path + " .tmp%%%%%%%" , FD, TempPath, Mode))
120
- return EC ;
120
+ return errorCodeToError (EC) ;
121
121
122
122
sys::RemoveFileOnSignal (TempPath);
123
123
@@ -128,7 +128,7 @@ OnDiskBuffer::create(StringRef Path, size_t Size, unsigned Mode) {
128
128
// pretty slow just like it writes specified amount of bytes,
129
129
// so we should avoid calling that function.
130
130
if (auto EC = fs::resize_file (FD, Size))
131
- return EC ;
131
+ return errorCodeToError (EC) ;
132
132
#endif
133
133
134
134
// Mmap it.
@@ -137,12 +137,12 @@ OnDiskBuffer::create(StringRef Path, size_t Size, unsigned Mode) {
137
137
FD, fs::mapped_file_region::readwrite, Size, 0 , EC);
138
138
close (FD);
139
139
if (EC)
140
- return EC ;
140
+ return errorCodeToError (EC) ;
141
141
return llvm::make_unique<OnDiskBuffer>(Path, TempPath, std::move (MappedFile));
142
142
}
143
143
144
144
// Create an instance of FileOutputBuffer.
145
- ErrorOr <std::unique_ptr<FileOutputBuffer>>
145
+ Expected <std::unique_ptr<FileOutputBuffer>>
146
146
FileOutputBuffer::create (StringRef Path, size_t Size, unsigned Flags) {
147
147
unsigned Mode = fs::all_read | fs::all_write;
148
148
if (Flags & F_executable)
@@ -161,7 +161,7 @@ FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags) {
161
161
// destination file and write to it on commit().
162
162
switch (Stat.type ()) {
163
163
case fs::file_type::directory_file:
164
- return errc::is_a_directory;
164
+ return errorCodeToError ( errc::is_a_directory) ;
165
165
case fs::file_type::regular_file:
166
166
case fs::file_type::file_not_found:
167
167
case fs::file_type::status_error:
0 commit comments