mirror of
https://github.com/zeek/zeek.git
synced 2025-10-12 03:28:19 +00:00
Move type definitions/aliases from util.h to a separate file
This commit is contained in:
parent
62442058e7
commit
9928403b0b
5 changed files with 146 additions and 112 deletions
62
src/util.cc
62
src/util.cc
|
@ -531,19 +531,6 @@ FILE* open_package(string& path, const string& mode) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void SafePathOp::CheckValid(const char* op_result, const char* path, bool error_aborts) {
|
||||
if ( op_result ) {
|
||||
result = op_result;
|
||||
error = false;
|
||||
}
|
||||
else {
|
||||
if ( error_aborts )
|
||||
reporter->InternalError("Path operation failed on %s: %s", path ? path : "<null>", strerror(errno));
|
||||
else
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("util flatten_script_name") {
|
||||
CHECK(flatten_script_name("script", "some/path") == "some.path.script");
|
||||
#ifndef _MSC_VER
|
||||
|
@ -1647,55 +1634,6 @@ FILE* open_file(const string& path, const string& mode) {
|
|||
return rval;
|
||||
}
|
||||
|
||||
TEST_CASE("util path ops") {
|
||||
#ifdef _MSC_VER
|
||||
// TODO: adapt these tests to Windows paths
|
||||
#else
|
||||
SUBCASE("SafeDirname") {
|
||||
SafeDirname d("/this/is/a/path", false);
|
||||
CHECK(d.result == "/this/is/a");
|
||||
|
||||
SafeDirname d2("invalid", false);
|
||||
CHECK(d2.result == ".");
|
||||
|
||||
SafeDirname d3("./filename", false);
|
||||
CHECK(d2.result == ".");
|
||||
}
|
||||
|
||||
SUBCASE("SafeBasename") {
|
||||
SafeBasename b("/this/is/a/path", false);
|
||||
CHECK(b.result == "path");
|
||||
CHECK(! b.error);
|
||||
|
||||
SafeBasename b2("justafile", false);
|
||||
CHECK(b2.result == "justafile");
|
||||
CHECK(! b2.error);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
SafeDirname::SafeDirname(const char* path, bool error_aborts) : SafePathOp() { DoFunc(path ? path : "", error_aborts); }
|
||||
|
||||
SafeDirname::SafeDirname(const string& path, bool error_aborts) : SafePathOp() { DoFunc(path, error_aborts); }
|
||||
|
||||
void SafeDirname::DoFunc(const string& path, bool error_aborts) {
|
||||
char* tmp = copy_string(path.c_str());
|
||||
CheckValid(dirname(tmp), tmp, error_aborts);
|
||||
delete[] tmp;
|
||||
}
|
||||
|
||||
SafeBasename::SafeBasename(const char* path, bool error_aborts) : SafePathOp() {
|
||||
DoFunc(path ? path : "", error_aborts);
|
||||
}
|
||||
|
||||
SafeBasename::SafeBasename(const string& path, bool error_aborts) : SafePathOp() { DoFunc(path, error_aborts); }
|
||||
|
||||
void SafeBasename::DoFunc(const string& path, bool error_aborts) {
|
||||
char* tmp = copy_string(path.c_str());
|
||||
CheckValid(basename(tmp), tmp, error_aborts);
|
||||
delete[] tmp;
|
||||
}
|
||||
|
||||
TEST_CASE("util implode_string_vector") {
|
||||
std::vector<std::string> v = {"a", "b", "c"};
|
||||
CHECK(implode_string_vector(v, ",") == "a,b,c");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue