summaryrefslogtreecommitdiff
path: root/configfs.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-05-27 00:01:08 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-06-01 09:48:21 +0300
commit6df2b6e22e0720173cec23669ecf3f99ee9f21eb (patch)
tree7a633a5f2116cece0ab5edc628ec3e8ca7a7f9fa /configfs.c
parent571e148aaec20c26c308d6611cdb1f34ec81ff1e (diff)
configfs: Restructure attribute read to support binary attributes
Modify the attribute_read() function to not add a terminating 0 to the buffer, and to return the number of bytes read, in order to support binary attributes. The attribute_read_uint() and attribute_read_str() functions are modified accordingly to use the new attribute_read() semantics. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'configfs.c')
-rw-r--r--configfs.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/configfs.c b/configfs.c
index 38954d5..4c83dca 100644
--- a/configfs.c
+++ b/configfs.c
@@ -53,7 +53,7 @@ static char *path_glob_first_match(const char *g)
* Attribute handling
*/
-static int attribute_read(const char *path, const char *file, char *buf,
+static int attribute_read(const char *path, const char *file, void *buf,
unsigned int len)
{
char *f;
@@ -72,7 +72,7 @@ static int attribute_read(const char *path, const char *file, char *buf,
return -ENOENT;
}
- ret = read(fd, buf, len - 1);
+ ret = read(fd, buf, len);
close(fd);
if (ret < 0) {
@@ -81,9 +81,7 @@ static int attribute_read(const char *path, const char *file, char *buf,
return -ENODATA;
}
- buf[ret] = '\0';
-
- return 0;
+ return len;
}
static int attribute_read_uint(const char *path, const char *file,
@@ -94,10 +92,12 @@ static int attribute_read_uint(const char *path, const char *file,
char *endptr;
int ret;
- ret = attribute_read(path, file, buf, sizeof(buf));
- if (ret)
+ ret = attribute_read(path, file, buf, sizeof(buf) - 1);
+ if (ret < 0)
return ret;
+ buf[ret] = '\0';
+
errno = 0;
/* base 0: Autodetect hex, octal, decimal. */
@@ -117,10 +117,12 @@ static char *attribute_read_str(const char *path, const char *file)
char *p;
int ret;
- ret = attribute_read(path, file, buf, sizeof(buf));
- if (ret)
+ ret = attribute_read(path, file, buf, sizeof(buf) - 1);
+ if (ret < 0)
return NULL;
+ buf[ret] = '\0';
+
p = strrchr(buf, '\n');
if (p != buf)
*p = '\0';