[go: up one dir, main page]

File: test-popen.c

package info (click to toggle)
fakechroot 2.19-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,148 kB
  • sloc: ansic: 6,893; sh: 5,995; makefile: 349; perl: 169; java: 5
file content (36 lines) | stat: -rw-r--r-- 563 bytes parent folder | download | duplicates (6)
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
#define _BSD_SOURCE
#define _DEFAULT_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>

#include <errno.h>

#ifndef PATH_MAX
#define PATH_MAX 2048
#endif


int main (int argc, char *argv[]) {
    FILE *fp;
    char path[PATH_MAX];

    if (argc != 2) {
        fprintf(stderr, "Usage: %s cmd\n", argv[0]);
        exit(2);
    }

    fp = popen(argv[1], "r");
    if (fp == NULL) {
        perror("popen");
        exit(1);
    }

    while (fgets(path, PATH_MAX, fp) != NULL) {
        printf("%s", path);
    }

    pclose(fp);

    return 0;
}