BpfMap/Utils - fix const-ness of key & value
When accessing maps keys are always const/read-only.
Similarly for the value when it is being stored in the map.
This eliminates four const_casts.
Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Icc57b46a8e9e81b5b06264260bfbf34a4ba9105d
diff --git a/libbpf_android/include/bpf/BpfMap.h b/libbpf_android/include/bpf/BpfMap.h
index a894b57..80ae62b 100644
--- a/libbpf_android/include/bpf/BpfMap.h
+++ b/libbpf_android/include/bpf/BpfMap.h
@@ -79,7 +79,7 @@
netdutils::StatusOr<Key> getNextKey(const Key& key) const {
Key nextKey;
- if (getNextMapKey(mMapFd, const_cast<Key*>(&key), &nextKey)) {
+ if (getNextMapKey(mMapFd, &key, &nextKey)) {
return netdutils::statusFromErrno(
errno, base::StringPrintf("Get next key of map %d failed", mMapFd.get()));
}
@@ -87,7 +87,7 @@
}
netdutils::Status writeValue(const Key& key, const Value& value, uint64_t flags) {
- if (writeToMapEntry(mMapFd, const_cast<Key*>(&key), const_cast<Value*>(&value), flags)) {
+ if (writeToMapEntry(mMapFd, &key, &value, flags)) {
return netdutils::statusFromErrno(
errno, base::StringPrintf("write to map %d failed", mMapFd.get()));
}
@@ -96,7 +96,7 @@
netdutils::StatusOr<Value> readValue(const Key key) const {
Value value;
- if (findMapEntry(mMapFd, const_cast<Key*>(&key), &value)) {
+ if (findMapEntry(mMapFd, &key, &value)) {
return netdutils::statusFromErrno(
errno, base::StringPrintf("read value of map %d failed", mMapFd.get()));
}
@@ -104,7 +104,7 @@
}
netdutils::Status deleteValue(const Key& key) {
- if (deleteMapEntry(mMapFd, const_cast<Key*>(&key))) {
+ if (deleteMapEntry(mMapFd, &key)) {
return netdutils::statusFromErrno(
errno, base::StringPrintf("delete entry from map %d failed", mMapFd.get()));
}