Mercurial > archived > louis > perso > liblxcstats
view tests/read_big_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 |
line wrap: on
line source
#include <sys/types.h> #include <sys/mman.h> #include <sys/stat.h> #include <err.h> #include <fcntl.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "lxcstats.h" #include "_lxcstats.h" int main(void) { char *reference; struct stat sb; char *trial; size_t size; int fd; fd = open("/etc/services", O_RDONLY); if (fd == -1) err(EXIT_FAILURE, "can't open /etc/services"); size = _lxcst_read_file("/etc/services", &trial); if (!trial) err(EXIT_FAILURE, "can't read /etc/services"); if (fstat(fd, &sb) != 0) err(EXIT_FAILURE, "can't stat /etc/services"); reference = mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (!reference) err(EXIT_FAILURE, "can't map /etc/services"); if ((size_t)sb.st_size != size) errx(EXIT_FAILURE, "sizes are different"); if (memcmp(reference, trial, size)) errx(EXIT_FAILURE, "buffers are different"); free(trial); return (EXIT_SUCCESS); }