diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/read_file.c	Wed Dec 29 23:28:14 2010 +0100
@@ -0,0 +1,42 @@
+#include <sys/types.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[1024];
+    int         rdsize;
+    char        *trial;
+    size_t      size;
+    int         fd;
+
+    fd = open("/etc/hostname", O_RDONLY);
+    if (fd == -1)
+        err(EXIT_FAILURE, "can't open /etc/hostname");
+
+    size = _lxcst_read_file("/etc/hostname", &trial);
+    if (!trial)
+        err(EXIT_FAILURE, "can't read /etc/hostname");
+
+    rdsize = read(fd, reference, sizeof(reference));
+    if (rdsize == -1)
+        err(EXIT_FAILURE, "can't read /etc/hostname");
+
+    if ((size_t)rdsize != size)
+        errx(EXIT_FAILURE, "sizes are different");
+
+    if (memcmp(reference, trial, size))
+        errx(EXIT_FAILURE, "buffers are different");
+
+    free(trial);
+
+    return (EXIT_SUCCESS);
+}