mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
cleaned up some code. Fixed a bug where a temporary directory would be deleted even when it was not created
This commit is contained in:
parent
c2c3f6b44d
commit
e0e0f1cd5f
3
oss-internship-2020/sapi_libarchive/.clang-format
Normal file
3
oss-internship-2020/sapi_libarchive/.clang-format
Normal file
|
@ -0,0 +1,3 @@
|
|||
BasedOnStyle: Google
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
|
@ -29,16 +29,6 @@ target_link_libraries(helpers PUBLIC
|
|||
libarchive_sapi
|
||||
)
|
||||
|
||||
add_executable(sapi_example
|
||||
sapi_example.cc
|
||||
)
|
||||
|
||||
target_link_libraries(sapi_example PRIVATE
|
||||
libarchive_sapi
|
||||
sapi::sapi
|
||||
glog::glog
|
||||
)
|
||||
|
||||
add_executable(sapi_minitar
|
||||
sapi_minitar.cc
|
||||
)
|
||||
|
@ -50,29 +40,6 @@ target_link_libraries(sapi_minitar PRIVATE
|
|||
#glog::glog
|
||||
)
|
||||
|
||||
#add_executable(untar
|
||||
# untar.cc
|
||||
#)
|
||||
#
|
||||
#target_link_libraries(untar PRIVATE
|
||||
# archive
|
||||
#)
|
||||
#
|
||||
#
|
||||
#
|
||||
#add_executable(tarfilter
|
||||
# tarfilter.cc
|
||||
#)
|
||||
#
|
||||
#target_link_libraries(tarfilter PRIVATE
|
||||
# archive
|
||||
#)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
add_executable(minitar
|
||||
orig/minitar.cc
|
||||
)
|
||||
|
|
|
@ -15,16 +15,6 @@ std::vector<std::string> MakeAbsolutePathsVec(const char *argv[]) {
|
|||
return arr;
|
||||
}
|
||||
|
||||
// std::string GetErrorString(sapi::v::Ptr *archive, LibarchiveSandbox &sandbox,
|
||||
// LibarchiveApi &api) {
|
||||
// sapi::StatusOr<char *> ret = api.archive_error_string(archive);
|
||||
// CHECK(ret.ok() && ret) << "Could not get error message";
|
||||
|
||||
// sapi::StatusOr<std::string> ret2 =
|
||||
// sandbox.GetCString(sapi::v::RemotePtr(ret.value())); CHECK(ret.ok()) <<
|
||||
// "Could not transfer error message"; return ret2.value();
|
||||
// }
|
||||
|
||||
std::string CheckStatusAndGetString(const sapi::StatusOr<char*>& status,
|
||||
LibarchiveSandbox& sandbox) {
|
||||
CHECK(status.ok() && status.value() != NULL) << "Could not get error message";
|
||||
|
@ -35,23 +25,12 @@ std::string CheckStatusAndGetString(const sapi::StatusOr<char *> &status,
|
|||
return ret.value();
|
||||
}
|
||||
|
||||
// std::string CallFunctionAndGetString(sapi::v::Ptr *archive, LibarchiveSandbox
|
||||
// &sandbox, LibarchiveApi *api, sapi::StatusOr<char *>
|
||||
// (LibarchiveApi::*func)(sapi::v::Ptr *)) {
|
||||
// sapi::StatusOr<char *> ret = (api->*func)(archive);
|
||||
// CHECK(ret.ok() && ret) << "Could not get error message";
|
||||
|
||||
// sapi::StatusOr<std::string> ret2 =
|
||||
// sandbox.GetCString(sapi::v::RemotePtr(ret.value())); CHECK(ret.ok()) <<
|
||||
// "Could not transfer error message"; return ret2.value();
|
||||
// }
|
||||
|
||||
std::string CreateTempDirAtCWD() {
|
||||
std::string cwd = sandbox2::file_util::fileops::GetCWD();
|
||||
CHECK(!cwd.empty()) << "Could not get current working directory";
|
||||
cwd.append("/");
|
||||
|
||||
sapi::StatusOr<std::string> result = sandbox2::CreateTempDir(cwd);
|
||||
CHECK(result.ok()) << "Could not create temporary directory";
|
||||
CHECK(result.ok()) << "Could not create temporary directory at " << cwd;
|
||||
return result.value();
|
||||
}
|
|
@ -9,6 +9,9 @@
|
|||
#include "sandboxed_api/sandbox2/util/path.h"
|
||||
#include "sandboxed_api/sandbox2/util/temp_file.h"
|
||||
|
||||
inline constexpr size_t kBlockSize = 10240;
|
||||
inline constexpr size_t kBuffSize = 16384;
|
||||
|
||||
// Used to convert the paths provided as arguments for the program
|
||||
// (the paths used) to an array of absolute paths. This allows the user
|
||||
// to use either relative or absolute paths
|
||||
|
@ -18,17 +21,15 @@ std::vector<std::string> MakeAbsolutePathsVec(const char *argv[]);
|
|||
// working directory to the relative path
|
||||
std::string MakeAbsolutePathAtCWD(const std::string& path);
|
||||
|
||||
// Calls the archive_error_string and returns the mesage after it was
|
||||
// transferred to the client process. std::string GetErrorString(sapi::v::Ptr
|
||||
// *archive, LibarchiveSandbox &sandbox, LibarchiveApi &api);
|
||||
|
||||
// This function takes a status as argument and after checking the status
|
||||
// it transfers the string. This is used mostly with archive_error_string
|
||||
// and other library functions that return a char *.
|
||||
std::string CheckStatusAndGetString(const sapi::StatusOr<char*>& status,
|
||||
LibarchiveSandbox& sandbox);
|
||||
|
||||
// std::string CallFunctionAndGetString(sapi::v::Ptr *archive, LibarchiveSandbox
|
||||
// &sandbox, LibarchiveApi *api, sapi::StatusOr<char *>
|
||||
// (LibarchiveApi::*func)(sapi::v::Ptr *));
|
||||
|
||||
// Creates a temporary directory in the current working directory and
|
||||
// returns the path. This is used in the extract function where the sandbox
|
||||
// changes the current working directory to this temporary directory.
|
||||
std::string CreateTempDirAtCWD();
|
||||
|
||||
#endif // SAPI_LIBARCHIVE_HELPERS_H
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "libarchive_sapi.sapi.h"
|
||||
|
||||
int main() {
|
||||
std::cout << "WORKS2" << std::endl;
|
||||
|
||||
LibarchiveSandbox sandbox;
|
||||
sandbox.Init().IgnoreError();
|
||||
LibarchiveApi api(&sandbox);
|
||||
|
||||
if (api.archive_write_disk_new().ok()) {
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -49,7 +49,9 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "helpers.h"
|
||||
#include "sandbox.h"
|
||||
|
@ -126,18 +128,15 @@
|
|||
#ifndef NO_CREATE
|
||||
static void create(const char* filename, int compress, const char** argv);
|
||||
#endif
|
||||
static void errmsg(const char *);
|
||||
static void extract(const char* filename, int do_extract, int flags);
|
||||
static int copy_data(sapi::v::RemotePtr* ar, sapi::v::RemotePtr* aw,
|
||||
LibarchiveApi& api, SapiLibarchiveSandboxExtract& sandbox);
|
||||
static void msg(const char *);
|
||||
static void usage(void);
|
||||
|
||||
static int verbose = 0;
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
google::InitGoogleLogging(argv[0]);
|
||||
std::cout << "BEGIN\n";
|
||||
const char* filename = NULL;
|
||||
int compress, flags, mode, opt;
|
||||
|
||||
|
@ -219,11 +218,10 @@ int main(int argc, const char **argv) {
|
|||
break;
|
||||
}
|
||||
|
||||
return (0);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#ifndef NO_CREATE
|
||||
// static char buff[16384];
|
||||
|
||||
static void create(const char* initial_filename, int compress,
|
||||
const char** argv) {
|
||||
|
@ -231,25 +229,12 @@ static void create(const char *initial_filename, int compress,
|
|||
// prepend /output/ so that it will work with the security policy.
|
||||
|
||||
std::string abs_path = MakeAbsolutePathAtCWD(std::string(initial_filename));
|
||||
|
||||
std::cout << "initial_filename = " << initial_filename << std::endl;
|
||||
|
||||
auto [archive_path, filename_tmp] = sandbox2::file::SplitPath(abs_path);
|
||||
|
||||
std::cout << "filename_tmp = " << filename_tmp << std::endl;
|
||||
std::cout << "archive_path_first = " << archive_path << std::endl;
|
||||
|
||||
std::string filename("/output/");
|
||||
filename.append(filename_tmp);
|
||||
std::cout << "filename = " << filename << std::endl;
|
||||
std::cout << "archive_path = " << archive_path << std::endl;
|
||||
|
||||
std::cout << "absolute_paths: " << std::endl;
|
||||
std::vector<std::string> absolute_paths = MakeAbsolutePathsVec(argv);
|
||||
for (const auto &i : absolute_paths) {
|
||||
std::cout << i << std::endl;
|
||||
}
|
||||
std::cout << "=======\n";
|
||||
|
||||
std::vector<std::string> relative_paths;
|
||||
sandbox2::util::CharPtrArrToVecString(const_cast<char* const*>(argv),
|
||||
|
@ -259,9 +244,6 @@ static void create(const char *initial_filename, int compress,
|
|||
CHECK(sandbox.Init().ok()) << "Error during sandbox initialization";
|
||||
LibarchiveApi api(&sandbox);
|
||||
|
||||
ssize_t len;
|
||||
int fd;
|
||||
|
||||
sapi::StatusOr<archive*> ret = api.archive_write_new();
|
||||
CHECK(ret.ok()) << "write_new call failed";
|
||||
CHECK(ret.value() != NULL) << "Failed to create write archive";
|
||||
|
@ -313,6 +295,7 @@ static void create(const char *initial_filename, int compress,
|
|||
if (filename_ptr != NULL && strcmp(filename_ptr, "-") == 0) {
|
||||
filename_ptr = NULL;
|
||||
}
|
||||
|
||||
ret2 = api.archive_write_open_filename(
|
||||
&a, sapi::v::ConstCStr(filename_ptr).PtrBefore());
|
||||
CHECK(ret2.ok()) << "write_open_filename call failed";
|
||||
|
@ -321,9 +304,7 @@ static void create(const char *initial_filename, int compress,
|
|||
|
||||
int file_idx = 0;
|
||||
|
||||
// while (*argv != NULL) {
|
||||
for (int file_idx = 0; file_idx < absolute_paths.size(); ++file_idx) {
|
||||
std::cout << "\n\nhandling file: " << relative_paths[file_idx] << std::endl;
|
||||
ret = api.archive_read_disk_new();
|
||||
CHECK(ret.ok()) << "read_disk_new call failed";
|
||||
CHECK(ret.value() != NULL) << "Failed to create read_disk archive";
|
||||
|
@ -337,13 +318,9 @@ static void create(const char *initial_filename, int compress,
|
|||
<< "Unexpected result from read_disk_set_standard_lookup call";
|
||||
#endif
|
||||
|
||||
// ret2 = api.archive_read_disk_open(&disk,
|
||||
// sapi::v::ConstCStr(*argv).PtrBefore());
|
||||
|
||||
ret2 = api.archive_read_disk_open(
|
||||
&disk,
|
||||
sapi::v::ConstCStr(absolute_paths[file_idx].c_str()).PtrBefore());
|
||||
|
||||
CHECK(ret2.ok()) << "read_disk_open call failed";
|
||||
CHECK(ret2.value() == ARCHIVE_OK)
|
||||
<< CheckStatusAndGetString(api.archive_error_string(&disk), sandbox);
|
||||
|
@ -381,18 +358,13 @@ static void create(const char *initial_filename, int compress,
|
|||
// of it will become /absolute/path/test_files/file1 and we change it to
|
||||
// test_files/file1 so that it is relative.
|
||||
|
||||
// std::cout << "relative = " << relative_paths[file_idx] << std::endl;
|
||||
// std::cout << "absolute = " << absolute_paths[file_idx] << std::endl;
|
||||
std::string path_name =
|
||||
CheckStatusAndGetString(api.archive_entry_pathname(&entry), sandbox);
|
||||
|
||||
std::cout << "path_name initial = " << path_name << std::endl;
|
||||
path_name.replace(path_name.begin(),
|
||||
path_name.begin() + absolute_paths[file_idx].length(),
|
||||
relative_paths[file_idx]);
|
||||
|
||||
// std::cout << "path_name after = " << path_name << std::endl;
|
||||
|
||||
// On top of those changes, we need to remove leading '/' characters
|
||||
// and also remove everything up to the last occurrence of '../'.
|
||||
|
||||
|
@ -401,23 +373,17 @@ static void create(const char *initial_filename, int compress,
|
|||
path_name.erase(path_name.begin(), path_name.begin() + found);
|
||||
}
|
||||
|
||||
std::cout << "path_name 2 = " << path_name << std::endl;
|
||||
|
||||
found = path_name.rfind("../");
|
||||
std::cout << "found = " << found << std::endl;
|
||||
if (found != std::string::npos) {
|
||||
path_name = path_name.substr(found + 3);
|
||||
}
|
||||
|
||||
std::cout << "path_name 3 = " << path_name << std::endl;
|
||||
|
||||
CHECK(api.archive_entry_set_pathname(
|
||||
&entry, sapi::v::ConstCStr(path_name.c_str()).PtrBefore())
|
||||
.ok())
|
||||
<< "Could not set pathname";
|
||||
|
||||
if (verbose) {
|
||||
std::cout << "pathname = ";
|
||||
std::cout << CheckStatusAndGetString(api.archive_entry_pathname(&entry),
|
||||
sandbox);
|
||||
needcr = 1;
|
||||
|
@ -435,45 +401,44 @@ static void create(const char *initial_filename, int compress,
|
|||
<< "Unexpected result from write_header call";
|
||||
|
||||
if (ret2.value() > ARCHIVE_FAILED) {
|
||||
// TODO copy part here
|
||||
int fd = open(CheckStatusAndGetString(
|
||||
api.archive_entry_sourcepath(&entry), sandbox)
|
||||
.c_str(),
|
||||
O_RDONLY);
|
||||
|
||||
// int fd = open(CheckStatusAndGetString(
|
||||
// api.archive_entry_sourcepath(&entry), sandbox)
|
||||
// .c_str(),
|
||||
// O_RDONLY);
|
||||
int fd = open(path_name.c_str(), O_RDONLY);
|
||||
CHECK(fd >= 0) << "Could not open file";
|
||||
|
||||
sapi::v::Fd sapi_fd(fd);
|
||||
sapi::v::Int read_ret;
|
||||
sapi::v::Array<char> buff(16384);
|
||||
sapi::v::UInt ssize(16384);
|
||||
sapi::v::Array<char> buff(kBuffSize);
|
||||
sapi::v::UInt ssize(kBuffSize);
|
||||
|
||||
CHECK(sandbox.Allocate(&buff, true).ok())
|
||||
<< "Could not allocate remote buffer";
|
||||
|
||||
CHECK(sandbox.Allocate(&buff, true).ok()) << "Could not allocate remote buffer";
|
||||
// CHECK(sandbox.Allocate(&buff, true).ok()) << "Could not allocate
|
||||
// buffer";
|
||||
CHECK(sandbox.TransferToSandboxee(&sapi_fd).ok())
|
||||
<< "Could not transfer file descriptor";
|
||||
// sandbox.Call()
|
||||
|
||||
CHECK(sandbox.Call("read", &read_ret, &sapi_fd, buff.PtrNone(), &ssize)
|
||||
.ok())
|
||||
<< "Read call failed";
|
||||
|
||||
while (read_ret.GetValue() > 0) {
|
||||
CHECK(api.archive_write_data(&a, buff.PtrNone(), read_ret.GetValue())
|
||||
.ok())
|
||||
<< "write_data call failed";
|
||||
// CHECK(ret.ok());
|
||||
|
||||
CHECK(
|
||||
sandbox.Call("read", &read_ret, &sapi_fd, buff.PtrNone(), &ssize)
|
||||
.ok())
|
||||
<< "Read call failed";
|
||||
}
|
||||
// TODO close fds
|
||||
// CHECK(sapi_fd.CloseRemoteFd(sandbox.GetRpcChannel()).ok())
|
||||
// << "Could not close remote fd";
|
||||
// sapi_fd.CloseLocalFd();
|
||||
// sapi_fd variable goes out of scope here so both the local and the
|
||||
// remote file descriptors are closed.
|
||||
}
|
||||
|
||||
CHECK(api.archive_entry_free(&entry).ok()) << "entry_free call failed";
|
||||
|
||||
if (needcr) {
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
@ -486,9 +451,6 @@ static void create(const char *initial_filename, int compress,
|
|||
ret2 = api.archive_read_free(&disk);
|
||||
CHECK(ret2.ok()) << "read_free call failed";
|
||||
CHECK(!ret2.value()) << "Unexpected result from read_free call";
|
||||
|
||||
// ++argv;
|
||||
// ++file_idx;
|
||||
}
|
||||
|
||||
ret2 = api.archive_write_close(&a);
|
||||
|
@ -507,39 +469,39 @@ static void extract(const char *filename, int do_extract, int flags) {
|
|||
tmp_dir = CreateTempDirAtCWD();
|
||||
}
|
||||
|
||||
// We can use a struct like this in order to delete the temporary
|
||||
// directory that was created earlier whenever the function ends.
|
||||
struct ExtractTempDirectoryCleanup {
|
||||
~ExtractTempDirectoryCleanup() {
|
||||
sandbox2::file_util::fileops::DeleteRecursively(capture);
|
||||
sandbox2::file_util::fileops::DeleteRecursively(dir);
|
||||
}
|
||||
std::string dir;
|
||||
};
|
||||
|
||||
// We should only delete it if the do_extract flag is true which
|
||||
// means that this struct is instantiated only in that case.
|
||||
std::shared_ptr<ExtractTempDirectoryCleanup> cleanup_ptr;
|
||||
if (do_extract) {
|
||||
cleanup_ptr = std::make_unique<ExtractTempDirectoryCleanup>();
|
||||
cleanup_ptr->dir = tmp_dir;
|
||||
}
|
||||
const std::string capture;
|
||||
} cleanup{tmp_dir};
|
||||
|
||||
std::cout << "extract" << std::endl;
|
||||
std::string filename_absolute = MakeAbsolutePathAtCWD(filename);
|
||||
|
||||
std::cout << "filename = " << filename_absolute << std::endl;
|
||||
|
||||
SapiLibarchiveSandboxExtract sandbox(filename_absolute, do_extract, tmp_dir);
|
||||
CHECK(sandbox.Init().ok()) << "Error during sandbox initialization";
|
||||
|
||||
LibarchiveApi api(&sandbox);
|
||||
|
||||
// struct archive *a;
|
||||
// struct archive *ext;
|
||||
// struct archive_entry *entry;
|
||||
// int r;
|
||||
sapi::StatusOr<archive*> ret = api.archive_read_new();
|
||||
CHECK(ret.ok()) << "archive_read_new call failed";
|
||||
// std::cout << "RET VALUE = " << ret.value() << std::endl;
|
||||
CHECK(ret.value() != NULL) << "Failed to create read archive";
|
||||
// a = ret.value();
|
||||
|
||||
sapi::v::RemotePtr a(ret.value());
|
||||
|
||||
ret = api.archive_write_disk_new();
|
||||
CHECK(ret.ok()) << "write_disk_new call failed";
|
||||
CHECK(ret.value() != NULL) << "Failed to create write disk archive";
|
||||
// ext = ret.value();
|
||||
|
||||
sapi::v::RemotePtr ext(ret.value());
|
||||
|
||||
|
@ -591,29 +553,18 @@ static void extract(const char *filename, int do_extract, int flags) {
|
|||
filename_ptr = NULL;
|
||||
}
|
||||
|
||||
// sapi::v::ConstCStr sapi_filename(filename_absolute.c_str());
|
||||
|
||||
std::cout << "opening filename" << std::endl;
|
||||
|
||||
ret2 = api.archive_read_open_filename(
|
||||
&a, sapi::v::ConstCStr(filename_ptr).PtrBefore(), 10240);
|
||||
&a, sapi::v::ConstCStr(filename_ptr).PtrBefore(), kBlockSize);
|
||||
CHECK(ret2.ok()) << "read_open_filename call failed";
|
||||
// CHECK(!ret2.value()) << GetErrorString(&a_ptr, sandbox, api);
|
||||
CHECK(!ret2.value()) << CheckStatusAndGetString(api.archive_error_string(&a),
|
||||
sandbox);
|
||||
// CHECK(!ret2.value()) << CallFunctionAndGetString(&a_ptr, sandbox, &api,
|
||||
// &api.archive_error_string);
|
||||
|
||||
for (;;) {
|
||||
int needcr = 0;
|
||||
std::cout << "================reading headers==============" << std::endl;
|
||||
sapi::v::IntBase<struct archive_entry*> entry_ptr_tmp(0);
|
||||
|
||||
ret2 = api.archive_read_next_header(&a, entry_ptr_tmp.PtrBoth());
|
||||
// std::cout << "val = " << ret2.value() << std::endl;
|
||||
ret2 = api.archive_read_next_header(&a, entry_ptr_tmp.PtrAfter());
|
||||
CHECK(ret2.ok()) << "read_next_header call failed";
|
||||
// CHECK(ret2.value() != ARCHIVE_OK) << GetErrorString(&a_ptr, sandbox,
|
||||
// api);
|
||||
|
||||
if (ret2.value() == ARCHIVE_EOF) {
|
||||
break;
|
||||
|
@ -635,15 +586,10 @@ static void extract(const char *filename, int do_extract, int flags) {
|
|||
needcr = 1;
|
||||
}
|
||||
|
||||
std::cout << "qqqqq" << std::endl;
|
||||
|
||||
if (do_extract) {
|
||||
std::cout << "EXTRACT HERE" << std::endl;
|
||||
ret2 = api.archive_write_header(&ext, &entry);
|
||||
CHECK(ret2.ok()) << "write_header call failed";
|
||||
|
||||
std::cout << "val = " << ret2.value() << std::endl;
|
||||
|
||||
if (ret2.value() != ARCHIVE_OK) {
|
||||
std::cout << CheckStatusAndGetString(api.archive_error_string(&a),
|
||||
sandbox);
|
||||
|
@ -658,8 +604,6 @@ static void extract(const char *filename, int do_extract, int flags) {
|
|||
}
|
||||
}
|
||||
|
||||
std::cout << "out of loop" << std::endl;
|
||||
|
||||
ret2 = api.archive_read_close(&a);
|
||||
CHECK(ret2.ok()) << "read_close call failed";
|
||||
CHECK(!ret2.value()) << "Unexpected value from read_close call";
|
||||
|
@ -675,16 +619,11 @@ static void extract(const char *filename, int do_extract, int flags) {
|
|||
ret2 = api.archive_write_free(&ext);
|
||||
CHECK(ret2.ok()) << "write_free call failed";
|
||||
CHECK(!ret2.value()) << "Unexpected result from write_free call";
|
||||
|
||||
// if (do_extract) {
|
||||
// sandbox2::file_util::fileops::DeleteRecursively(tmp_dir);
|
||||
// }
|
||||
}
|
||||
|
||||
static int copy_data(sapi::v::RemotePtr* ar, sapi::v::RemotePtr* aw,
|
||||
LibarchiveApi& api,
|
||||
SapiLibarchiveSandboxExtract& sandbox) {
|
||||
std::cout << "CALL COPY_DATA XXXXXXXXXXXX\n";
|
||||
sapi::StatusOr<int> ret;
|
||||
|
||||
sapi::v::IntBase<struct archive_entry*> buff_ptr_tmp(0);
|
||||
|
@ -692,8 +631,8 @@ static int copy_data(sapi::v::RemotePtr *ar, sapi::v::RemotePtr *aw,
|
|||
sapi::v::SLLong offset;
|
||||
|
||||
for (;;) {
|
||||
ret = api.archive_read_data_block(ar, buff_ptr_tmp.PtrBoth(),
|
||||
size.PtrBoth(), offset.PtrBoth());
|
||||
ret = api.archive_read_data_block(ar, buff_ptr_tmp.PtrAfter(),
|
||||
size.PtrAfter(), offset.PtrAfter());
|
||||
CHECK(ret.ok()) << "read_data_block call failed";
|
||||
|
||||
if (ret.value() == ARCHIVE_EOF) {
|
||||
|
@ -720,14 +659,14 @@ static int copy_data(sapi::v::RemotePtr *ar, sapi::v::RemotePtr *aw,
|
|||
}
|
||||
}
|
||||
|
||||
static void msg(const char *m) { write(1, m, strlen(m)); }
|
||||
// static void msg(const char* m) { write(1, m, strlen(m)); }
|
||||
|
||||
static void errmsg(const char *m) {
|
||||
if (m == NULL) {
|
||||
m = "Error: No error description provided.\n";
|
||||
}
|
||||
write(2, m, strlen(m));
|
||||
}
|
||||
// static void errmsg(const char* m) {
|
||||
// if (m == NULL) {
|
||||
// m = "Error: No error description provided.\n";
|
||||
// }
|
||||
// write(2, m, strlen(m));
|
||||
// }
|
||||
|
||||
static void usage(void) {
|
||||
/* Many program options depend on compile options. */
|
||||
|
@ -751,6 +690,6 @@ static void usage(void) {
|
|||
#endif
|
||||
"] [-f file] [file]\n";
|
||||
|
||||
errmsg(m);
|
||||
exit(1);
|
||||
std::cout << m << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user