summaryrefslogtreecommitdiffstats
path: root/device/udev_linux
diff options
context:
space:
mode:
authoragoode <agoode@chromium.org>2015-03-17 18:25:27 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-18 01:26:22 +0000
commitdf367dd86b9ad686d314f4664ae66674a1f700f0 (patch)
tree03a03c3014c7a9f216c9f512992406fa2ad25707 /device/udev_linux
parent0c619881fcd09e4d17b70b11c353b3d5e5af144b (diff)
downloadchromium_src-df367dd86b9ad686d314f4664ae66674a1f700f0.zip
chromium_src-df367dd86b9ad686d314f4664ae66674a1f700f0.tar.gz
chromium_src-df367dd86b9ad686d314f4664ae66674a1f700f0.tar.bz2
Introduce UdevDeviceGetSysattrValue, which is the same as
UdevDeviceGetPropertyValue but for sysattrs. Use this in places where NULL is not an appropriate return value (such as assignment to std::string). Review URL: https://codereview.chromium.org/1018593002 Cr-Commit-Position: refs/heads/master@{#321043}
Diffstat (limited to 'device/udev_linux')
-rw-r--r--device/udev_linux/udev.cc16
-rw-r--r--device/udev_linux/udev.h5
2 files changed, 19 insertions, 2 deletions
diff --git a/device/udev_linux/udev.cc b/device/udev_linux/udev.cc
index 65686da..e2b93d2 100644
--- a/device/udev_linux/udev.cc
+++ b/device/udev_linux/udev.cc
@@ -9,6 +9,14 @@
namespace device {
+namespace {
+
+std::string StringOrEmptyIfNull(const char* value) {
+ return value ? value : std::string();
+}
+
+} // namespace
+
const char* udev_device_get_action(udev_device* udev_device) {
return UdevLoader::Get()->udev_device_get_action(udev_device);
}
@@ -149,8 +157,12 @@ void udev_unref(udev* udev) {
std::string UdevDeviceGetPropertyValue(udev_device* udev_device,
const char* key) {
- const char* value = device::udev_device_get_property_value(udev_device, key);
- return value ? value : std::string();
+ return StringOrEmptyIfNull(udev_device_get_property_value(udev_device, key));
+}
+
+std::string UdevDeviceGetSysattrValue(udev_device* udev_device,
+ const char* key) {
+ return StringOrEmptyIfNull(udev_device_get_sysattr_value(udev_device, key));
}
std::string UdevDecodeString(const std::string& encoded) {
diff --git a/device/udev_linux/udev.h b/device/udev_linux/udev.h
index d62db6b..c40603d 100644
--- a/device/udev_linux/udev.h
+++ b/device/udev_linux/udev.h
@@ -79,6 +79,11 @@ void udev_unref(udev* udev);
std::string UdevDeviceGetPropertyValue(udev_device* udev_device,
const char* key);
+// Calls udev_device_get_sysattr_value() and replaces missing values with
+// the empty string.
+std::string UdevDeviceGetSysattrValue(udev_device* udev_device,
+ const char* key);
+
// Decodes udev-encoded string. Useful for decoding "*_ENC" udev properties.
std::string UdevDecodeString(const std::string& encoded);