Mercurial > archived > louis > perso > liblxcstats
comparison tests/read_file.c @ 0:6ce4443e7545
Add the draft of an API to collect statistics on LXC
author | Louis Opter <kalessin@kalessin.fr> |
---|---|
date | Wed, 29 Dec 2010 23:28:14 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:6ce4443e7545 |
---|---|
1 #include <sys/types.h> | |
2 | |
3 #include <err.h> | |
4 #include <fcntl.h> | |
5 #include <stdlib.h> | |
6 #include <string.h> | |
7 #include <unistd.h> | |
8 | |
9 #include "lxcstats.h" | |
10 #include "_lxcstats.h" | |
11 | |
12 int | |
13 main(void) | |
14 { | |
15 char reference[1024]; | |
16 int rdsize; | |
17 char *trial; | |
18 size_t size; | |
19 int fd; | |
20 | |
21 fd = open("/etc/hostname", O_RDONLY); | |
22 if (fd == -1) | |
23 err(EXIT_FAILURE, "can't open /etc/hostname"); | |
24 | |
25 size = _lxcst_read_file("/etc/hostname", &trial); | |
26 if (!trial) | |
27 err(EXIT_FAILURE, "can't read /etc/hostname"); | |
28 | |
29 rdsize = read(fd, reference, sizeof(reference)); | |
30 if (rdsize == -1) | |
31 err(EXIT_FAILURE, "can't read /etc/hostname"); | |
32 | |
33 if ((size_t)rdsize != size) | |
34 errx(EXIT_FAILURE, "sizes are different"); | |
35 | |
36 if (memcmp(reference, trial, size)) | |
37 errx(EXIT_FAILURE, "buffers are different"); | |
38 | |
39 free(trial); | |
40 | |
41 return (EXIT_SUCCESS); | |
42 } |