summaryrefslogtreecommitdiff
path: root/sysctl.c
blob: da1ad866a0edd569031b21295a691cfd7932e19e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * sysctl - sysctl set/get helpers
 * Subject to the GPL, version 2.
 */

#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>

#include "built_in.h"
#include "sysctl.h"

int sysctl_set_int(const char *file, int value)
{
	char path[PATH_MAX];
	char str[64];
	ssize_t ret;
	int fd;

	strncpy(path, SYSCTL_PROC_PATH, PATH_MAX);
	strncat(path, file, PATH_MAX - sizeof(SYSCTL_PROC_PATH) - 1);

	fd = open(path, O_WRONLY);
	if (unlikely(fd < 0))
		return -1;

	ret = snprintf(str, 63, "%d", value);
	if (ret < 0) {
		close(fd);
		return -1;
	}

	ret = write(fd, str, strlen(str));

	close(fd);
	return ret <= 0 ? -1 : 0;
}

int sysctl_get_int(const char *file, int *value)
{
	char path[PATH_MAX];
	char str[64];
	ssize_t ret;
	int fd;

	strncpy(path, SYSCTL_PROC_PATH, PATH_MAX);
	strncat(path, file, PATH_MAX - sizeof(SYSCTL_PROC_PATH) - 1);

	fd = open(path, O_RDONLY);
	if (fd < 0)
		return -1;

	ret = read(fd, str, sizeof(str));
	if (ret > 0) {
		*value = atoi(str);
		ret = 0;
	} else {
		ret = -1;
	}

	close(fd);
	return ret;
}
ff)parent2b2d3eb41c920b47df2fcedd1489cf748bd09466 (diff)
Merge branch 'sh_eth-E-DMAC-interrupt-mask-cleanups'
Sergei Shtylyov says: ==================== sh_eth: E-DMAC interrupt mask cleanups Here's a set of 3 patches against DaveM's 'net-next.git' repo. The main goal of this set is to stop using the bare numbers for the E-DMAC interrupt masks. [1/3] sh_eth: rename EESIPR bits [2/3] sh_eth: add missing EESIPR bits [3/3] sh_eth: stop using bare numbers for EESIPR values ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'sound/soc/codecs/wm8728.h')