- struct sysfs_directory *sysfs_dir;
- char value[SYSFS_VALUE_MAX];
- int len;
- int retval = 0;
-
- sysfs_dir = sysfs_open_directory(path);
- if (sysfs_dir == NULL)
- return -1;
-
- attributes = sysfs_get_dir_attributes(sysfs_dir);
- if (attributes == NULL) {
- retval = -1;
- goto exit;
- }
-
- dlist_for_each_data(attributes, attr, struct sysfs_attribute) {
- if (attr->value != NULL) {
- strncpy(value, attr->value, SYSFS_VALUE_MAX);
- len = strlen(value);
- if (len == 0)
- continue;
-
- /* remove trailing newline */
- if (value[len-1] == '\n') {
- value[len-1] = '\0';
- len--;
- }
+ char value[VALUE_SIZE];
+ size_t len;
+
+ dlist_for_each_data(attr_list, attr, struct sysfs_attribute) {
+ if (attr->value == NULL)
+ continue;
+ len = strlcpy(value, attr->value, sizeof(value));
+ if (len >= sizeof(value)) {
+ dbg("attribute value of '%s' too long, skip", attr->name);
+ continue;
+ }