5 #include <glog/logging.h>
19 bool CDB::open(fs::path db_path
)
22 auto const db_fn
= db_path
.string();
24 fd_
= ::open(db_fn
.c_str(), O_RDONLY
);
27 auto const msg
= strerror_r(errno
, err
, sizeof(err
));
28 LOG(WARNING
) << "unable to open " << db_fn
<< ": " << msg
;
35 std::optional
<std::string
> CDB::find(std::string_view key
)
40 CHECK_LT(key
.length(), std::numeric_limits
<unsigned int>::max());
41 if (cdb_find(&cdb_
, key
.data(), static_cast<unsigned int>(key
.length())) >
43 auto const vpos
= cdb_datapos(&cdb_
);
44 auto const vlen
= cdb_datalen(&cdb_
);
47 cdb_read(&cdb_
, &val
[0], vlen
, vpos
);
54 // No locale, ASCII only.
55 bool CDB::contains_lc(std::string_view key
)
57 std::string key_lc
{key
.begin(), key
.end()};
58 std::transform(key_lc
.begin(), key_lc
.end(), key_lc
.begin(),
59 [](unsigned char c
) { return std::tolower(c
); });
60 return contains(key_lc
);
63 bool CDB::contains(std::string_view key
)
68 CHECK_LT(key
.length(), std::numeric_limits
<unsigned int>::max());
69 return cdb_find(&cdb_
, key
.data(), static_cast<unsigned int>(key
.length())) >