brintos

brintos / llvm-project-archived public Read only

0
0
Text · 605 B · 5bdf227 Raw
29 lines · c
1#include <sys/types.h>2#include <sys/stat.h>3#include <unistd.h>4#include <errno.h>5#include <stdio.h>6 7int8main (int argc, char const **argv)9{10    struct stat buf;11    int i, rv = 0; // Set breakpoint here.12 13    // Make sure stdin/stdout/stderr exist.14    for (i = 0; i <= 2; ++i) {15        if (fstat(i, &buf) != 0)16            return 1;17    }18 19    // Make sure no other file descriptors are open.20    for (i = 3; i <= 256; ++i) {21        if (fstat(i, &buf) == 0 || errno != EBADF) {22            fprintf(stderr, "File descriptor %d is open.\n", i);23            rv = 2;24        }25    }26 27    return rv;28}29