Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc @@ -0,0 +1,51 @@ +// RUN: %clangxx -g %s -o %t && %run %t + +#include +#include + +int main(int argc, char **argv) { + FILE *fp; + int fd; + char buf[BUFSIZ]; + + fp = fopen(argv[0], "r"); + if (!fp) + return 1; + + // file should be good upon opening + if (feof(fp) || ferror(fp)) + return 2; + + // read until EOF + while (fread(buf, 1, sizeof buf, fp) != 0) {} + if (!feof(fp)) + return 3; + + // clear EOF + clearerr(fp); + if (feof(fp) || ferror(fp)) + return 4; + + // get file descriptor + fd = fileno(fp); + if (fd == -1) + return 5; + + // break the file by closing underlying descriptor + if (close(fd) == -1) + return 6; + + // verify that an error is signalled + if (fread(buf, 1, sizeof buf, fp) != 0) + return 7; + if (!ferror(fp)) + return 8; + + // clear error + clearerr(fp); + if (feof(fp) || ferror(fp)) + return 9; + + fclose(fp); + return 0; +} Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc @@ -0,0 +1,23 @@ +// RUN: %clangxx -g %s -o %t && %run %t + +#include + +int main(int argc, char **argv) { + FILE *fp; + + fp = fopen(argv[0], "r"); + if (!fp) + return 1; + + if (fgetc(fp) == EOF) + return 2; + + if (ungetc('X', fp) == EOF) + return 3; + + if (getc(fp) != 'X') + return 4; + + fclose(fp); + return 0; +}