Add stub for prop_du.c
[eleutheria.git] / proplib / prop_du.c
blob27584182434d9b5cbf14106c6c9f19dd506250cc
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/wait.h> /* for waitpid() macros */
5 #define MAX_STR 100
7 int main(void)
9 char str[MAX_STR];
10 int ret;
11 FILE *fp;
13 /* Initiate pipe stream to ``du'' */
14 fp = popen("du", "r");
15 if (fp == NULL) {
16 perror("popen()");
17 exit(EXIT_FAILURE);
20 /* Read from stream */
21 while (fgets(str, MAX_STR, fp) != NULL) {
22 printf("%s", str);
25 /* Close pipe stream */
26 ret = pclose(fp);
27 if (ret == -1) {
28 perror("pclose()");
29 exit(EXIT_FAILURE);
31 else {
33 * Use macros described under wait() to inspect the return value
34 * of pclose() in order to determine success/failure of command
35 * executed by popen().
38 if (WIFEXITED(ret)) {
39 printf("Child exited, ret = %d\n", WEXITSTATUS(ret));
40 } else if (WIFSIGNALED(ret)) {
41 printf("Child killed, signal %d\n", WTERMSIG(ret));
42 } else if (WIFSTOPPED(ret)) {
43 printf("Child stopped, signal %d\n", WSTOPSIG(ret));
45 /* Not all implementations support this */
46 #ifdef WIFCONTINUED
47 else if (WIFCONTINUED(ret)) {
48 printf("Child continued\n");
50 #endif
51 /* Non standard case -- may never happen */
52 else {
53 printf("Unexpected return value, ret = 0x%x\n", ret);
57 return EXIT_SUCCESS;