blob: cf40fab3ff724a50f8bc5ab9c84d35e39f51965a (
plain) (
blame)
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
47
48
49
50
51
|
/* vim: set sw=4 ts=4 sts=4 et: */
#undef NDEBUG
#define _POSIX_C_SOURCE 200809L
#include <l4array.h>
#include <l4file.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
int main () {
int p[2];
assert (pipe (p) >= 0);
pid_t pid = fork ();
if (pid < 0) {
return 1;
} else if (pid > 0){
FILE* fp = fopen ("test-file.c", "rb");
assert (fp != NULL);
FILE* fw = fdopen (p[1], "wb");
assert (fw != NULL);
close (p[0]);
LbsArray* line;
while ((line = lbs_file_read_file_line (fp)) != NULL && !feof (fp)) {
fputs (lbs_array_get_data (line), fw);
putc ('\n', fw);
lbs_array_unref (line);
}
lbs_array_unref (line);
fclose (fp);
fclose (fw);
} else {
close (p[1]);
assert (dup2 (p[0], 0) >= 0);
execlp ("cmp", "cmp", "test-file.c", "-", LBS_COMMON_NULL_PTR);
assert (0);
}
int status;
wait (&status);
assert (WIFEXITED (status) && WEXITSTATUS (status) == 0);
puts ("test-file => PASS!");
return 0;
}
|