summaryrefslogtreecommitdiff
path: root/tools.c
blob: 45d9f1271769b1f8d4b5505e25f99e4e2d6cdc83 (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
/*
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

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

#include "tools.h"

bool cSysFs::Write(const char *path, const char *value)
{
	int fd = open(path, O_RDWR, 0644);
    if (fd >= 0)
    {
    	int ret = write(fd, value, strlen(value));
    	if (ret < 0)
    		ELOG("failed to write %s to %s (-%d)", value, path, errno);
        close(fd);
        return true;
    }
	return false;
}

bool cSysFs::Write(const char *path, int value)
{
    int fd = open(path, O_RDWR, 0644);
    if (fd >= 0)
    {
    	char cmd[64];
    	snprintf(cmd, sizeof(cmd), "%d", value);

    	int ret = write(fd, cmd, strlen(cmd));
    	if (ret < 0)
    		ELOG("failed to write %d to %s (-%d)", value, path, errno);
        close(fd);
        return true;
    }
	return false;
}