llvm.org GIT mirror llvm / de15d01
Remove dead code. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224029 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
4 changed file(s) with 7 addition(s) and 109 deletion(s). Raw diff Collapse all Expand all
653653 mapped_file_region(mapped_file_region&&);
654654 mapped_file_region &operator =(mapped_file_region&&);
655655
656 /// Construct a mapped_file_region at \a path starting at \a offset of length
657 /// \a length and with access \a mode.
658 ///
659 /// \param path Path to the file to map. If it does not exist it will be
660 /// created.
661 /// \param mode How to map the memory.
662 /// \param length Number of bytes to map in starting at \a offset. If the file
663 /// is shorter than this, it will be extended. If \a length is
664 /// 0, the entire file will be mapped.
665 /// \param offset Byte offset from the beginning of the file where the map
666 /// should begin. Must be a multiple of
667 /// mapped_file_region::alignment().
668 /// \param ec This is set to errc::success if the map was constructed
669 /// successfully. Otherwise it is set to a platform dependent error.
670 mapped_file_region(const Twine &path, mapmode mode, uint64_t length,
671 uint64_t offset, std::error_code &ec);
672
673656 /// \param fd An open file descriptor to map. mapped_file_region takes
674657 /// ownership if closefd is true. It must have been opended in the correct
675658 /// mode.
678661
679662 ~mapped_file_region();
680663
681 mapmode flags() const;
682664 uint64_t size() const;
683665 char *data() const;
684666
469469 return std::error_code();
470470 }
471471
472 mapped_file_region::mapped_file_region(const Twine &path,
473 mapmode mode,
474 uint64_t length,
475 uint64_t offset,
476 std::error_code &ec)
477 : Mode(mode)
478 , Size(length)
479 , Mapping() {
480 // Make sure that the requested size fits within SIZE_T.
481 if (length > std::numeric_limits::max()) {
482 ec = make_error_code(errc::invalid_argument);
483 return;
484 }
485
486 SmallString<128> path_storage;
487 StringRef name = path.toNullTerminatedStringRef(path_storage);
488 int oflags = (mode == readonly) ? O_RDONLY : O_RDWR;
489 int ofd = ::open(name.begin(), oflags);
490 if (ofd == -1) {
491 ec = std::error_code(errno, std::generic_category());
492 return;
493 }
494
495 ec = init(ofd, true, offset);
496 if (ec)
497 Mapping = nullptr;
498 }
499
500472 mapped_file_region::mapped_file_region(int fd,
501473 bool closefd,
502474 mapmode mode,
527499 other.Mapping = nullptr;
528500 }
529501
530 mapped_file_region::mapmode mapped_file_region::flags() const {
531 assert(Mapping && "Mapping failed but used anyway!");
532 return Mode;
533 }
534
535502 uint64_t mapped_file_region::size() const {
536503 assert(Mapping && "Mapping failed but used anyway!");
537504 return Size;
550550 return std::error_code();
551551 }
552552
553 mapped_file_region::mapped_file_region(const Twine &path,
554 mapmode mode,
555 uint64_t length,
556 uint64_t offset,
557 std::error_code &ec)
558 : Mode(mode)
559 , Size(length)
560 , Mapping()
561 , FileDescriptor()
562 , FileHandle(INVALID_HANDLE_VALUE)
563 , FileMappingHandle() {
564 SmallVector path_utf16;
565
566 // Convert path to UTF-16.
567 if ((ec = widenPath(path, path_utf16)))
568 return;
569
570 // Get file handle for creating a file mapping.
571 FileHandle = ::CreateFileW(c_str(path_utf16),
572 Mode == readonly ? GENERIC_READ
573 : GENERIC_READ | GENERIC_WRITE,
574 Mode == readonly ? FILE_SHARE_READ
575 : 0,
576 0,
577 Mode == readonly ? OPEN_EXISTING
578 : OPEN_ALWAYS,
579 Mode == readonly ? FILE_ATTRIBUTE_READONLY
580 : FILE_ATTRIBUTE_NORMAL,
581 0);
582 if (FileHandle == INVALID_HANDLE_VALUE) {
583 ec = windows_error(::GetLastError());
584 return;
585 }
586
587 FileDescriptor = 0;
588 ec = init(FileDescriptor, true, offset);
589 if (ec) {
590 Mapping = FileMappingHandle = 0;
591 FileHandle = INVALID_HANDLE_VALUE;
592 FileDescriptor = 0;
593 }
594 }
595
596553 mapped_file_region::mapped_file_region(int fd,
597554 bool closefd,
598555 mapmode mode,
639596 other.FileDescriptor = 0;
640597 }
641598
642 mapped_file_region::mapmode mapped_file_region::flags() const {
643 assert(Mapping && "Mapping failed but used anyway!");
644 return Mode;
645 }
646
647599 uint64_t mapped_file_region::size() const {
648600 assert(Mapping && "Mapping failed but used anyway!");
649601 return Size;
661661 }
662662
663663 // Map it back in read-only
664 fs::mapped_file_region mfr(Twine(TempPath),
665 fs::mapped_file_region::readonly,
666 0,
667 0,
664 int FD;
665 EC = fs::openFileForRead(Twine(TempPath), FD);
666 ASSERT_NO_ERROR(EC);
667 fs::mapped_file_region mfr(FD, false, fs::mapped_file_region::readonly, 0, 0,
668668 EC);
669669 ASSERT_NO_ERROR(EC);
670670
672672 EXPECT_EQ(StringRef(mfr.const_data()), Val);
673673
674674 // Unmap temp file
675
676 fs::mapped_file_region m(Twine(TempPath),
677 fs::mapped_file_region::readonly,
678 0,
679 0,
680 EC);
675 fs::mapped_file_region m(FD, false, fs::mapped_file_region::readonly, 0, 0,
676 EC);
681677 ASSERT_NO_ERROR(EC);
678 ASSERT_EQ(close(FD), 0);
682679 const char *Data = m.const_data();
683680 fs::mapped_file_region mfrrv(std::move(m));
684681 EXPECT_EQ(mfrrv.const_data(), Data);