lkml.org 
[lkml]   [2014]   [Sep]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
Subject[PATCH 01/18] usbip: sysfs_utils: add read_sysfs_attribute
Previous rework of usbip's sysfs access structures called for a
read_sysfs_attribute function to be implemented in sysfs_utils.c

Signed-off-by: Maximilian Eschenbacher <maximilian@eschenbacher.email>
Signed-off-by: Fjodor Schelichow <fjodor.schelichow@hotmail.com>
Signed-off-by: Johannes Stadlinger <johannes.stadlinger@fau.de>
---
tools/usb/usbip/libsrc/sysfs_utils.c | 23 +++++++++++++++++++++++
tools/usb/usbip/libsrc/sysfs_utils.h | 1 +
2 files changed, 24 insertions(+)

diff --git a/tools/usb/usbip/libsrc/sysfs_utils.c b/tools/usb/usbip/libsrc/sysfs_utils.c
index 36ac88e..fc6d9f9 100644
--- a/tools/usb/usbip/libsrc/sysfs_utils.c
+++ b/tools/usb/usbip/libsrc/sysfs_utils.c
@@ -29,3 +29,26 @@ int write_sysfs_attribute(const char *attr_path, const char *new_value,

return 0;
}
+
+int read_sysfs_attribute(const char *attr_path, char *buffer, size_t buffsize)
+{
+ int fd;
+ int length;
+
+ fd = open(attr_path, O_RDONLY);
+ if (fd < 0) {
+ dbg("error opening attribute %s", attr_path);
+ return -1;
+ }
+
+ length = read(fd, buffer, buffsize);
+ if (length < 0) {
+ dbg("error reading from attribute %s", attr_path);
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+
+ return length;
+}
diff --git a/tools/usb/usbip/libsrc/sysfs_utils.h b/tools/usb/usbip/libsrc/sysfs_utils.h
index 32ac1d1..c1f1b79 100644
--- a/tools/usb/usbip/libsrc/sysfs_utils.h
+++ b/tools/usb/usbip/libsrc/sysfs_utils.h
@@ -4,5 +4,6 @@

int write_sysfs_attribute(const char *attr_path, const char *new_value,
size_t len);
+int read_sysfs_attribute(const char *attr_path, char *buffer, size_t buffsize);

#endif
--
2.1.0


\
 
 \ /
  Last update: 2014-09-17 00:41    [W:2.104 / U:0.800 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site