MCPcopy Create free account
hub / github.com/Kitware/CMake / AddData

Method AddData

Source/cmArchiveWrite.cxx:541–576  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

539}
540
541bool cmArchiveWrite::AddData(char const* file, size_t size)
542{
543 cmsys::ifstream fin(file, std::ios::in | std::ios::binary);
544 if (!fin) {
545 this->Error = cmStrCat("Error opening \"", file,
546 "\": ", cmSystemTools::GetLastSystemError());
547 return false;
548 }
549
550 char buffer[16384];
551 size_t nleft = size;
552 while (nleft > 0) {
553 using ssize_type = std::streamsize;
554 size_t const nnext = nleft > sizeof(buffer) ? sizeof(buffer) : nleft;
555 ssize_type const nnext_s = static_cast<ssize_type>(nnext);
556 fin.read(buffer, nnext_s);
557 // Some stream libraries (older HPUX) return failure at end of
558 // file on the last read even if some data were read. Check
559 // gcount instead of trusting the stream error status.
560 if (static_cast<size_t>(fin.gcount()) != nnext) {
561 break;
562 }
563 if (archive_write_data(this->Archive, buffer, nnext) != nnext_s) {
564 this->Error = cmStrCat("archive_write_data: ",
565 cm_archive_error_string(this->Archive));
566 return false;
567 }
568 nleft -= nnext;
569 }
570 if (nleft > 0) {
571 this->Error = cmStrCat("Error reading \"", file,
572 "\": ", cmSystemTools::GetLastSystemError());
573 return false;
574 }
575 return true;
576}

Callers 1

AddFileMethod · 0.95

Calls 4

archive_write_dataFunction · 0.85
cm_archive_error_stringFunction · 0.85
cmStrCatFunction · 0.70
readMethod · 0.45

Tested by

no test coverage detected