3 #include <glog/logging.h>
17 bool CDB::open(fs::path db_path
)
20 auto const db_fn
= db_path
.string();
22 fd_
= ::open(db_fn
.c_str(), O_RDONLY
);
25 auto const msg
= strerror_r(errno
, err
, sizeof(err
));
26 LOG(WARNING
) << "unable to open " << db_fn
<< ": " << msg
;
33 std::optional
<std::string
> CDB::find(std::string_view key
)
38 CHECK_LT(key
.length(), std::numeric_limits
<unsigned int>::max());
39 if (cdb_find(&cdb_
, key
.data(), static_cast<unsigned int>(key
.length())) >
41 auto const vpos
= cdb_datapos(&cdb_
);
42 auto const vlen
= cdb_datalen(&cdb_
);
45 cdb_read(&cdb_
, &val
[0], vlen
, vpos
);
52 bool CDB::contains(std::string_view key
)
57 CHECK_LT(key
.length(), std::numeric_limits
<unsigned int>::max());
58 return cdb_find(&cdb_
, key
.data(), static_cast<unsigned int>(key
.length())) >