1 // SPDX-License-Identifier: GPL-2.0
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <errno.h>
6 
7 #include "sysfs_utils.h"
8 #include "usbip_common.h"
9 
write_sysfs_attribute(const char * attr_path,const char * new_value,size_t len)10 int write_sysfs_attribute(const char *attr_path, const char *new_value,
11 			  size_t len)
12 {
13 	int fd;
14 	int length;
15 
16 	fd = open(attr_path, O_WRONLY);
17 	if (fd < 0) {
18 		dbg("error opening attribute %s", attr_path);
19 		return -1;
20 	}
21 
22 	length = write(fd, new_value, len);
23 	if (length < 0) {
24 		dbg("error writing to attribute %s", attr_path);
25 		close(fd);
26 		return -1;
27 	}
28 
29 	close(fd);
30 
31 	return 0;
32 }
33