Files
RedBear-OS/tests/stdio/popen.c
T
Tibor Nagy d1a424c002 tests: Replace returns with exits in the main functions
This will allow us to redefine the exit function.

For example:
```
#define exit(code) { \
    fprintf(stderr, "%s:%d: exit(%s) in function ‘%s’\n",
        __FILE__, __LINE__, #code, __func__); \
    _exit(code); \
}
```
2019-02-21 12:15:06 +01:00

29 lines
475 B
C

#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE *fp;
int status;
char path[256];
fp = popen("ls -1 example_dir", "r");
if (fp == NULL) {
perror("popen");
exit(EXIT_FAILURE);
}
while (fgets(path, 256, fp) != NULL) {
printf("%s", path);
}
status = pclose(fp);
if (status == -1) {
perror("pclose");
exit(EXIT_FAILURE);
} else {
printf("status %x\n", status);
}
}