xref: /kernel/linux/linux-5.10/tools/usb/usbip/libsrc/sysfs_utils.c
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /kernel/linux/linux-5.10/tools/usb/usbip/libsrc/
18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include <sys/types.h>
38c2ecf20Sopenharmony_ci#include <sys/stat.h>
48c2ecf20Sopenharmony_ci#include <fcntl.h>
58c2ecf20Sopenharmony_ci#include <errno.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include "sysfs_utils.h"
88c2ecf20Sopenharmony_ci#include "usbip_common.h"
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciint write_sysfs_attribute(const char *attr_path, const char *new_value,
118c2ecf20Sopenharmony_ci			  size_t len)
128c2ecf20Sopenharmony_ci{
138c2ecf20Sopenharmony_ci	int fd;
148c2ecf20Sopenharmony_ci	int length;
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci	fd = open(attr_path, O_WRONLY);
178c2ecf20Sopenharmony_ci	if (fd < 0) {
188c2ecf20Sopenharmony_ci		dbg("error opening attribute %s", attr_path);
198c2ecf20Sopenharmony_ci		return -1;
208c2ecf20Sopenharmony_ci	}
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci	length = write(fd, new_value, len);
238c2ecf20Sopenharmony_ci	if (length < 0) {
248c2ecf20Sopenharmony_ci		dbg("error writing to attribute %s", attr_path);
258c2ecf20Sopenharmony_ci		close(fd);
268c2ecf20Sopenharmony_ci		return -1;
278c2ecf20Sopenharmony_ci	}
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	close(fd);
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci	return 0;
328c2ecf20Sopenharmony_ci}
33

Indexes created Thu Nov 07 10:32:03 CST 2024