sysfs_utils.c 526 B

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