sysfs_utils.c 562 B

123456789101112131415161718192021222324252627282930313233
  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. #include "sysfs_utils.h"
  7. #include "usbip_common.h"
  8. int write_sysfs_attribute(const char *attr_path, const char *new_value,
  9. size_t len)
  10. {
  11. int fd;
  12. int length;
  13. fd = open(attr_path, O_WRONLY);
  14. if (fd < 0) {
  15. dbg("error opening attribute %s", attr_path);
  16. return -1;
  17. }
  18. length = write(fd, new_value, len);
  19. if (length < 0) {
  20. dbg("error writing to attribute %s", attr_path);
  21. close(fd);
  22. return -1;
  23. }
  24. close(fd);
  25. return 0;
  26. }