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