2 * sysctl - sysctl set/get helpers
3 * Subject to the GPL, version 2.
11 #include <linux/limits.h>
15 #define SYS_PATH "/proc/sys/"
17 int sysctl_set_int(const char *file
, int value
)
24 strncpy(path
, SYS_PATH
, PATH_MAX
);
25 strncat(path
, file
, PATH_MAX
- sizeof(SYS_PATH
) - 1);
27 fd
= open(path
, O_WRONLY
);
31 ret
= snprintf(str
, 63, "%d", value
);
37 ret
= write(fd
, str
, strlen(str
));
40 return ret
<= 0 ? -1 : 0;
43 int sysctl_get_int(const char *file
, int *value
)
50 strncpy(path
, SYS_PATH
, PATH_MAX
);
51 strncat(path
, file
, PATH_MAX
- sizeof(SYS_PATH
) - 1);
53 fd
= open(path
, O_RDONLY
);
57 ret
= read(fd
, str
, sizeof(str
));