updated build system
This commit is contained in:
@ -319,9 +319,18 @@ auto file::read(unsigned char *data, std::size_t to_read, std::uint64_t offset,
|
||||
throw std::runtime_error("failed to seek before read");
|
||||
}
|
||||
|
||||
auto bytes_read = fread(data, 1U, to_read, file_.get());
|
||||
if (not feof(file_.get()) && ferror(file_.get())) {
|
||||
throw std::runtime_error("failed to read file bytes");
|
||||
std::size_t bytes_read{0U};
|
||||
while (bytes_read != to_read) {
|
||||
res = fread(&data[bytes_read], 1U, to_read - bytes_read, file_.get());
|
||||
if (not feof(file_.get()) && ferror(file_.get())) {
|
||||
throw std::runtime_error("failed to read file bytes");
|
||||
}
|
||||
|
||||
if (res == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
bytes_read += static_cast<std::size_t>(res);
|
||||
}
|
||||
|
||||
if (total_read != nullptr) {
|
||||
@ -416,10 +425,19 @@ auto file::write(const unsigned char *data, std::size_t to_write,
|
||||
throw std::runtime_error("failed to seek before write");
|
||||
}
|
||||
|
||||
auto bytes_written =
|
||||
fwrite(reinterpret_cast<const char *>(data), 1U, to_write, file_.get());
|
||||
if (not feof(file_.get()) && ferror(file_.get())) {
|
||||
throw std::runtime_error("failed to write file bytes");
|
||||
std::size_t bytes_written{0U};
|
||||
while (bytes_written != to_write) {
|
||||
res = fwrite(reinterpret_cast<const char *>(&data[bytes_written]), 1U,
|
||||
to_write - bytes_written, file_.get());
|
||||
if (not feof(file_.get()) && ferror(file_.get())) {
|
||||
throw std::runtime_error("failed to write file bytes");
|
||||
}
|
||||
|
||||
if (res == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
bytes_written += static_cast<std::size_t>(res);
|
||||
}
|
||||
|
||||
flush();
|
||||
|
@ -178,6 +178,10 @@ auto smb_file::read(unsigned char *data, std::size_t to_read,
|
||||
};
|
||||
|
||||
try {
|
||||
if (total_read != nullptr) {
|
||||
(*total_read) = 0U;
|
||||
}
|
||||
|
||||
if (not fd_.has_value()) {
|
||||
throw std::runtime_error("failed to read file|" + path_ +
|
||||
"|file not open");
|
||||
@ -191,15 +195,25 @@ auto smb_file::read(unsigned char *data, std::size_t to_read,
|
||||
std::to_string(res));
|
||||
}
|
||||
|
||||
res = smb_fread(session_.get(), *fd_, data, to_read);
|
||||
if (res == -1) {
|
||||
throw std::runtime_error("failed to read file|" + path_ + '|' +
|
||||
std::to_string(to_read) + '|' +
|
||||
std::to_string(res));
|
||||
std::size_t bytes_read{0U};
|
||||
while (bytes_read != to_read) {
|
||||
res = smb_fread(session_.get(), *fd_, &data[bytes_read],
|
||||
to_read - bytes_read);
|
||||
if (res == -1) {
|
||||
throw std::runtime_error("failed to read file|" + path_ + '|' +
|
||||
std::to_string(to_read) + '|' +
|
||||
std::to_string(res));
|
||||
}
|
||||
|
||||
if (res == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
bytes_read += static_cast<std::size_t>(res);
|
||||
}
|
||||
|
||||
if (total_read != nullptr) {
|
||||
(*total_read) = static_cast<std::uint64_t>(res);
|
||||
(*total_read) = bytes_read;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -269,6 +283,10 @@ auto smb_file::write(const unsigned char *data, std::size_t to_write,
|
||||
};
|
||||
|
||||
try {
|
||||
if (total_written != nullptr) {
|
||||
(*total_written) = 0U;
|
||||
}
|
||||
|
||||
if (not fd_.has_value()) {
|
||||
throw std::runtime_error("failed to write file|" + path_ +
|
||||
"|file not open");
|
||||
@ -282,16 +300,26 @@ auto smb_file::write(const unsigned char *data, std::size_t to_write,
|
||||
std::to_string(res));
|
||||
}
|
||||
|
||||
res = smb_fwrite(session_.get(), *fd_, const_cast<unsigned char *>(data),
|
||||
to_write);
|
||||
if (res == -1) {
|
||||
throw std::runtime_error("failed to write file|" + path_ + '|' +
|
||||
std::to_string(to_write) + '|' +
|
||||
std::to_string(res));
|
||||
std::size_t bytes_written{0U};
|
||||
while (bytes_written != to_write) {
|
||||
res = smb_fwrite(session_.get(), *fd_,
|
||||
const_cast<unsigned char *>(&data[bytes_written]),
|
||||
to_write - bytes_written);
|
||||
if (res == -1) {
|
||||
throw std::runtime_error("failed to write file|" + path_ + '|' +
|
||||
std::to_string(to_write) + '|' +
|
||||
std::to_string(res));
|
||||
}
|
||||
|
||||
if (res == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
bytes_written += static_cast<std::size_t>(res);
|
||||
}
|
||||
|
||||
if (total_written != nullptr) {
|
||||
(*total_written) = static_cast<std::uint64_t>(res);
|
||||
(*total_written) = bytes_written;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user