blob: 5db6ec68b123275ed2132ab05682d63374361153 (
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
|
#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);
}
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);
return 0;
}
|