10063-2.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (C) 2000-2022 Free Software Foundation, Inc.
  2. //
  3. // This file is part of the GNU ISO C++ Library. This library is free
  4. // software; you can redistribute it and/or modify it under the
  5. // terms of the GNU General Public License as published by the
  6. // Free Software Foundation; either version 3, or (at your option)
  7. // any later version.
  8. // This library is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // You should have received a copy of the GNU General Public License along
  13. // with this library; see the file COPYING3. If not see
  14. // <http://www.gnu.org/licenses/>.
  15. // The ARM simulator does not provide support for "fstat", which
  16. // causes "sbumpc" to return an incorrect value.
  17. // { dg-do run { xfail arm*-*-elf arm*-*-eabi } }
  18. // { dg-require-fileio "" }
  19. #include <cstdio>
  20. #include <fstream>
  21. #include <ext/stdio_filebuf.h>
  22. #include <testsuite_hooks.h>
  23. void test2()
  24. {
  25. using namespace std;
  26. filebuf fbuf;
  27. fbuf.open("tmp_10063-2", ios_base::out | ios_base::trunc);
  28. fbuf.sputn("01234", 5);
  29. fbuf.close();
  30. FILE* file = fopen("tmp_10063-2", "r");
  31. setbuf(file, 0);
  32. int c = getc(file);
  33. VERIFY(c == '0');
  34. c = getc(file);
  35. VERIFY(c == '1');
  36. {
  37. __gnu_cxx::stdio_filebuf<char> sbuf(file, ios_base::in);
  38. c = sbuf.sbumpc();
  39. VERIFY(c == '2');
  40. c = sbuf.sbumpc();
  41. VERIFY(c == '3');
  42. c = sbuf.sbumpc();
  43. VERIFY(c == '4');
  44. c = sbuf.sgetc();
  45. VERIFY(c == EOF);
  46. }
  47. fclose(file);
  48. }
  49. int main()
  50. {
  51. test2();
  52. return 0;
  53. }