fix popen, improve tests
This commit is contained in:
@@ -917,9 +917,15 @@ pub unsafe extern "C" fn popen(command: *const c_char, mode: *const c_char) -> *
|
||||
//TODO: dup errors are ignored, should they be?
|
||||
{
|
||||
if write {
|
||||
unistd::dup2(0, pipes[0]);
|
||||
match unistd::dup2(pipes[0], 0) {
|
||||
0 => {}
|
||||
e => stdlib::exit(127),
|
||||
}
|
||||
} else {
|
||||
unistd::dup2(1, pipes[1]);
|
||||
match unistd::dup2(pipes[1], 1) {
|
||||
1 => {}
|
||||
e => stdlib::exit(127),
|
||||
}
|
||||
}
|
||||
|
||||
unistd::close(pipes[0]);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
1-never-gonna-give-you-up
|
||||
2-never-gonna-let-you-down
|
||||
3-never-gonna-run-around
|
||||
4-and-desert-you
|
||||
5-never-gonna-make-you-cry
|
||||
6-never-gonna-say-goodbye
|
||||
7-never-gonna-tell-a-lie
|
||||
8-and-hurt-you
|
||||
Line 1: 1-never-gonna-give-you-up
|
||||
Line 2: 2-never-gonna-let-you-down
|
||||
Line 3: 3-never-gonna-run-around
|
||||
Line 4: 4-and-desert-you
|
||||
Line 5: 5-never-gonna-make-you-cry
|
||||
Line 6: 6-never-gonna-say-goodbye
|
||||
Line 7: 7-never-gonna-tell-a-lie
|
||||
Line 8: 8-and-hurt-you
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Binaries that should generate the same output every time
|
||||
EXPECT_NAMES=(\
|
||||
|
||||
+3
-1
@@ -7,9 +7,11 @@ int main(void) {
|
||||
FILE *fp = popen("ls -1 example_dir", "r");
|
||||
ERROR_IF(popen, fp, == NULL);
|
||||
|
||||
int lineno = 0;
|
||||
char path[256] = { 0 };
|
||||
while (fgets(path, 256, fp) != NULL) {
|
||||
printf("%s", path);
|
||||
lineno++;
|
||||
printf("Line %d: %s", lineno, path);
|
||||
}
|
||||
|
||||
int status = pclose(fp);
|
||||
|
||||
+5
-2
@@ -27,7 +27,8 @@ int main(void) {
|
||||
ERROR_IF(close, c2, == -1);
|
||||
UNEXP_IF(close, c2, != 0);
|
||||
|
||||
int fd3 = open("dup.out", 0x0002, 0x1000);
|
||||
int fd3 = open("dup.out", O_RDWR);
|
||||
|
||||
ERROR_IF(open, fd3, == -1);
|
||||
UNEXP_IF(open, fd3, < 0);
|
||||
|
||||
@@ -35,7 +36,9 @@ int main(void) {
|
||||
ERROR_IF(dup2, fd4, == -1);
|
||||
UNEXP_IF(dup2, fd4, < 0);
|
||||
|
||||
printf("hello fd %d", fd3);
|
||||
int p = printf("hello fd %d", fd3);
|
||||
ERROR_IF(printf, p, == -1);
|
||||
UNEXP_IF(printf, p, < 0);
|
||||
|
||||
int c3 = close(fd3);
|
||||
ERROR_IF(close, c3, == -1);
|
||||
|
||||
Reference in New Issue
Block a user