File: file.c

package info (click to toggle)
criu 4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,500 kB
  • sloc: ansic: 139,280; python: 7,484; sh: 3,824; java: 2,799; makefile: 2,659; asm: 1,137; perl: 206; xml: 117; exp: 45
file content (46 lines) | stat: -rw-r--r-- 703 bytes parent folder | download | duplicates (2)
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
#include <fcntl.h>
#include <unistd.h>
#include "zdtmtst.h"

int write_value(const char *path, const char *value)
{
	int fd, l;

	fd = open(path, O_WRONLY);
	if (fd < 0) {
		pr_perror("open %s", path);
		return -1;
	}

	l = write(fd, value, strlen(value));
	if (l < 0) {
		pr_perror("failed to write %s to %s", value, path);
		close(fd);
		return -1;
	}

	close(fd);
	return 0;
}

int read_value(const char *path, char *value, int size)
{
	int fd, ret;

	fd = open(path, O_RDONLY);
	if (fd < 0) {
		pr_perror("open %s", path);
		return -1;
	}

	ret = read(fd, (void *)value, size);
	if (ret < 0) {
		pr_perror("read %s", path);
		close(fd);
		return -1;
	}

	value[ret] = '\0';
	close(fd);
	return 0;
}