llvm.org GIT mirror llvm / 58604cd
Change default error_code ctor to a 'named ctor' so it's more self-documenting. Unify default construction of error_code uses on this idiom so that users don't feel compelled to make static globals for naming convenience. (unfortunately I couldn't make the original ctor private as some APIs don't return their result, instead using an out parameter (that makes sense to default construct) - which is a bit of a pity. I did, however, find/fix some cases of unnecessary default construction of error_code before I hit the unfixable cases) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150197 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 8 years ago
7 changed file(s) with 59 addition(s) and 60 deletion(s). Raw diff Collapse all Expand all
737737 public:
738738 error_code() : _val_(0), _cat_(&system_category()) {}
739739
740 static error_code success() {
741 return error_code();
742 }
743
740744 error_code(int _val, const error_category& _cat)
741745 : _val_(_val), _cat_(&_cat) {}
742746
6666 if (Filename == "-") {
6767 Fd = 0;
6868 sys::Program::ChangeStdinToBinary();
69 return error_code();
69 return error_code::success();
7070 }
7171
7272 int OpenFlags = O_RDONLY;
7676 Fd = ::open(Filename.c_str(), OpenFlags);
7777 if (Fd == -1)
7878 return error_code(errno, posix_category());
79 return error_code();
79 return error_code::success();
8080 }
8181 };
8282
199199
200200 // Now its safe to mmap the files into memory because both files
201201 // have a non-zero size.
202 error_code ec;
203202 OwningPtr F1;
204203 if (error_code ec = MemoryBuffer::getFile(FileA.c_str(), F1)) {
205204 if (Error)
3535 #include
3636 using namespace llvm;
3737
38 namespace { const llvm::error_code success; }
39
4038 //===----------------------------------------------------------------------===//
4139 // MemoryBuffer implementation itself.
4240 //===----------------------------------------------------------------------===//
305303 RealMapOffset)) {
306304 result.reset(GetNamedBuffer(
307305 StringRef(Pages + Delta, MapSize), Filename, RequiresNullTerminator));
308 return success;
306 return error_code::success();
309307 }
310308 }
311309
343341 }
344342
345343 result.swap(SB);
346 return success;
344 return error_code::success();
347345 }
348346
349347 //===----------------------------------------------------------------------===//
372370 } while (ReadBytes != 0);
373371
374372 result.reset(getMemBufferCopy(Buffer, ""));
375 return success;
376 }
373 return error_code::success();
374 }
3030 const char prefered_separator = '/';
3131 #endif
3232
33 const llvm::error_code success;
34
3533 StringRef find_first_component(StringRef path) {
3634 // Look for this first component in the following order.
3735 // * empty (in this case we return an empty string)
606604
607605 // Already absolute.
608606 if (rootName && rootDirectory)
609 return success;
607 return error_code::success();
610608
611609 // All of the following conditions will need the current directory.
612610 SmallString<128> current_dir;
618616 path::append(current_dir, p);
619617 // Set path to the result.
620618 path.swap(current_dir);
621 return success;
619 return error_code::success();
622620 }
623621
624622 if (!rootName && rootDirectory) {
627625 path::append(curDirRootName, p);
628626 // Set path to the result.
629627 path.swap(curDirRootName);
630 return success;
628 return error_code::success();
631629 }
632630
633631 if (rootName && !rootDirectory) {
639637 SmallString<128> res;
640638 path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
641639 path.swap(res);
642 return success;
640 return error_code::success();
643641 }
644642
645643 llvm_unreachable("All rootName and rootDirectory combinations should have "
678676 if (error_code ec = status(path, st))
679677 return ec;
680678 result = is_directory(st);
681 return success;
679 return error_code::success();
682680 }
683681
684682 bool is_regular_file(file_status status) {
690688 if (error_code ec = status(path, st))
691689 return ec;
692690 result = is_regular_file(st);
693 return success;
691 return error_code::success();
694692 }
695693
696694 bool is_symlink(file_status status) {
702700 if (error_code ec = status(path, st))
703701 return ec;
704702 result = is_symlink(st);
705 return success;
703 return error_code::success();
706704 }
707705
708706 bool is_other(file_status status) {
729727 if (ec == errc::value_too_large) {
730728 // Magic.size() > file_size(Path).
731729 result = false;
732 return success;
730 return error_code::success();
733731 }
734732 return ec;
735733 }
736734
737735 result = Magic == Buffer;
738 return success;
736 return error_code::success();
739737 }
740738
741739 /// @brief Identify the magic in magic.
856854 return ec;
857855
858856 result = identify_magic(Magic);
859 return success;
857 return error_code::success();
860858 }
861859
862860 namespace {
883881 ++count;
884882 }
885883
886 return success;
884 return error_code::success();
887885 }
888886 } // end unnamed namespace
889887
8686 result.clear();
8787 StringRef d(dir);
8888 result.append(d.begin(), d.end());
89 return success;
89 return error_code::success();
9090 }
9191 }
9292
109109 }
110110
111111 result.set_size(strlen(result.data()));
112 return success;
112 return error_code::success();
113113 }
114114
115115 error_code copy_file(const Twine &from, const Twine &to, copy_option copt) {
168168 if (sz_read < 0)
169169 return error_code(errno, system_category());
170170
171 return success;
171 return error_code::success();
172172 }
173173
174174 error_code create_directory(const Twine &path, bool &existed) {
182182 } else
183183 existed = false;
184184
185 return success;
185 return error_code::success();
186186 }
187187
188188 error_code create_hard_link(const Twine &to, const Twine &from) {
195195 if (::link(t.begin(), f.begin()) == -1)
196196 return error_code(errno, system_category());
197197
198 return success;
198 return error_code::success();
199199 }
200200
201201 error_code create_symlink(const Twine &to, const Twine &from) {
208208 if (::symlink(t.begin(), f.begin()) == -1)
209209 return error_code(errno, system_category());
210210
211 return success;
211 return error_code::success();
212212 }
213213
214214 error_code remove(const Twine &path, bool &existed) {
222222 } else
223223 existed = true;
224224
225 return success;
225 return error_code::success();
226226 }
227227
228228 error_code rename(const Twine &from, const Twine &to) {
244244 return error_code(errno, system_category());
245245 }
246246
247 return success;
247 return error_code::success();
248248 }
249249
250250 error_code resize_file(const Twine &path, uint64_t size) {
254254 if (::truncate(p.begin(), size) == -1)
255255 return error_code(errno, system_category());
256256
257 return success;
257 return error_code::success();
258258 }
259259
260260 error_code exists(const Twine &path, bool &result) {
269269 } else
270270 result = true;
271271
272 return success;
272 return error_code::success();
273273 }
274274
275275 bool equivalent(file_status A, file_status B) {
283283 if (error_code ec = status(A, fsA)) return ec;
284284 if (error_code ec = status(B, fsB)) return ec;
285285 result = equivalent(fsA, fsB);
286 return success;
286 return error_code::success();
287287 }
288288
289289 error_code file_size(const Twine &path, uint64_t &result) {
297297 return make_error_code(errc::operation_not_permitted);
298298
299299 result = status.st_size;
300 return success;
300 return error_code::success();
301301 }
302302
303303 error_code status(const Twine &path, file_status &result) {
332332 result.st_dev = status.st_dev;
333333 result.st_ino = status.st_ino;
334334
335 return success;
335 return error_code::success();
336336 }
337337
338338 error_code unique_file(const Twine &model, int &result_fd,
427427 result_path.append(d.begin(), d.end());
428428
429429 result_fd = RandomFD;
430 return success;
430 return error_code::success();
431431 }
432432
433433 error_code detail::directory_iterator_construct(detail::DirIterState &it,
449449 ::closedir(reinterpret_cast(it.IterationHandle));
450450 it.IterationHandle = 0;
451451 it.CurrentEntry = directory_entry();
452 return success;
452 return error_code::success();
453453 }
454454
455455 error_code detail::directory_iterator_increment(detail::DirIterState &it) {
466466 } else
467467 return directory_iterator_destruct(it);
468468
469 return success;
469 return error_code::success();
470470 }
471471
472472 error_code get_magic(const Twine &path, uint32_t len,
497497 }
498498 std::fclose(file);
499499 result.set_size(len);
500 return success;
500 return error_code::success();
501501 }
502502
503503 } // end namespace fs
6161 utf16.push_back(0);
6262 utf16.pop_back();
6363
64 return success;
64 return error_code::success();
6565 }
6666
6767 error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len,
9191 utf8.push_back(0);
9292 utf8.pop_back();
9393
94 return success;
94 return error_code::success();
9595 }
9696
9797 error_code TempDir(SmallVectorImpl &result) {
107107 }
108108
109109 result.set_size(len);
110 return success;
110 return error_code::success();
111111 }
112112
113113 bool is_separator(const wchar_t value) {
166166 if (len == 0)
167167 return windows_error(::GetLastError());
168168
169 return success;
169 return error_code::success();
170170 }
171171
172172 error_code copy_file(const Twine &from, const Twine &to, copy_option copt) {
189189 if (res == 0)
190190 return windows_error(::GetLastError());
191191
192 return success;
192 return error_code::success();
193193 }
194194
195195 error_code create_directory(const Twine &path, bool &existed) {
209209 } else
210210 existed = false;
211211
212 return success;
212 return error_code::success();
213213 }
214214
215215 error_code create_hard_link(const Twine &to, const Twine &from) {
228228 if (!::CreateHardLinkW(wide_from.begin(), wide_to.begin(), NULL))
229229 return windows_error(::GetLastError());
230230
231 return success;
231 return error_code::success();
232232 }
233233
234234 error_code create_symlink(const Twine &to, const Twine &from) {
251251 if (!create_symbolic_link_api(wide_from.begin(), wide_to.begin(), 0))
252252 return windows_error(::GetLastError());
253253
254 return success;
254 return error_code::success();
255255 }
256256
257257 error_code remove(const Twine &path, bool &existed) {
284284 existed = true;
285285 }
286286
287 return success;
287 return error_code::success();
288288 }
289289
290290 error_code rename(const Twine &from, const Twine &to) {
304304 MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING))
305305 return windows_error(::GetLastError());
306306
307 return success;
307 return error_code::success();
308308 }
309309
310310 error_code resize_file(const Twine &path, uint64_t size) {
346346 result = false;
347347 } else
348348 result = true;
349 return success;
349 return error_code::success();
350350 }
351351
352352 bool equivalent(file_status A, file_status B) {
365365 if (error_code ec = status(A, fsA)) return ec;
366366 if (error_code ec = status(B, fsB)) return ec;
367367 result = equivalent(fsA, fsB);
368 return success;
368 return error_code::success();
369369 }
370370
371371 error_code file_size(const Twine &path, uint64_t &result) {
386386 (uint64_t(FileData.nFileSizeHigh) << (sizeof(FileData.nFileSizeLow) * 8))
387387 + FileData.nFileSizeLow;
388388
389 return success;
389 return error_code::success();
390390 }
391391
392392 static bool isReservedName(StringRef path) {
419419 StringRef path8 = path.toStringRef(path_storage);
420420 if (isReservedName(path8)) {
421421 result = file_status(file_type::character_file);
422 return success;
422 return error_code::success();
423423 }
424424
425425 if (error_code ec = UTF8ToUTF16(path8, path_utf16))
469469 result.VolumeSerialNumber = Info.dwVolumeSerialNumber;
470470 }
471471
472 return success;
472 return error_code::success();
473473
474474 handle_status_error:
475475 error_code ec = windows_error(::GetLastError());
483483 return ec;
484484 }
485485
486 return success;
486 return error_code::success();
487487 }
488488
489489 error_code unique_file(const Twine &model, int &result_fd,
610610 }
611611
612612 result_fd = fd;
613 return success;
613 return error_code::success();
614614 }
615615
616616 error_code get_magic(const Twine &path, uint32_t len,
652652 }
653653
654654 result.set_size(len);
655 return success;
655 return error_code::success();
656656 }
657657
658658 error_code detail::directory_iterator_construct(detail::DirIterState &it,
704704 path::append(directory_entry_path, directory_entry_name_utf8.str());
705705 it.CurrentEntry = directory_entry(directory_entry_path.str());
706706
707 return success;
707 return error_code::success();
708708 }
709709
710710 error_code detail::directory_iterator_destruct(detail::DirIterState &it) {
713713 ScopedFindHandle close(HANDLE(it.IterationHandle));
714714 it.IterationHandle = 0;
715715 it.CurrentEntry = directory_entry();
716 return success;
716 return error_code::success();
717717 }
718718
719719 error_code detail::directory_iterator_increment(detail::DirIterState &it) {
739739 return ec;
740740
741741 it.CurrentEntry.replace_filename(Twine(directory_entry_path_utf8));
742 return success;
742 return error_code::success();
743743 }
744744
745745 } // end namespace fs