1 // RUN: %clangxx -g %s -o %t && %run %t
3 // Newer versions of Android have FDSan, and will fail this test as FDSan will
4 // catch the error instead.
5 // UNSUPPORTED: android
11 int main(int argc
, char **argv
) {
12 FILE *fp
= fopen(argv
[0], "r");
15 // file should be good upon opening
16 assert(!feof(fp
) && !ferror(fp
));
20 while (fread(buf
, 1, sizeof buf
, fp
) != 0) {}
25 assert(!feof(fp
) && !ferror(fp
));
27 // get file descriptor
31 // break the file by closing underlying descriptor
32 assert(close(fd
) != -1);
34 // verify that an error is signalled
35 assert(fread(buf
, 1, sizeof buf
, fp
) == 0);
40 assert(!feof(fp
) && !ferror(fp
));
42 // fclose() will return EBADF because of closed fd
43 assert(fclose(fp
) == -1);