81751.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (C) 2017-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. // { dg-require-fileio "" }
  16. #include <ext/stdio_filebuf.h>
  17. #include <cstdio>
  18. #include <cerrno>
  19. #include <testsuite_hooks.h>
  20. void
  21. test01()
  22. {
  23. FILE* out = std::fopen("81751.txt", "w");
  24. std::fwrite("Some words.", 1, 10, out);
  25. FILE* in1 = std::fopen("81751.txt", "r");
  26. __gnu_cxx::stdio_filebuf<char> buf1(in1, std::ios::in, BUFSIZ);
  27. int c = buf1.sgetc();
  28. VERIFY( c == std::char_traits<char>::eof() ); // PR libstdc++/81751
  29. std::fflush(out);
  30. FILE* in2 = std::fopen("81751.txt", "r");
  31. __gnu_cxx::stdio_filebuf<char> buf2(in2, std::ios::in, BUFSIZ);
  32. c = buf2.sgetc();
  33. VERIFY( c == 'S' );
  34. buf1.close();
  35. buf2.close();
  36. std::fclose(in1);
  37. std::fclose(in2);
  38. std::fclose(out);
  39. }
  40. int
  41. main()
  42. {
  43. test01();
  44. }