summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cpp
blob: f895cf194ce7c7258464c895a9fa861770daca3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// RUN: %clangxx -g %s -o %t && %run %t

#include <assert.h>
#include <stdio.h>

int main(int argc, char **argv) {
  FILE *fp = fopen(argv[0], "r");
  assert(fp);

  // the file should be at least one character long, always
  assert(fgetc(fp) != EOF);
  // POSIX guarantees being able to ungetc() at least one character
  assert(ungetc('X', fp) != EOF);
  // check whether ungetc() worked
  assert(getc(fp) == 'X');

  assert(!fclose(fp));
  return 0;
}
OpenPOWER on IntegriCloud