1147191Sjkoshy// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
2147191Sjkoshy// Free Software Foundation
3147191Sjkoshy//
4147191Sjkoshy// This file is part of the GNU ISO C++ Library.  This library is free
5147191Sjkoshy// software; you can redistribute it and/or modify it under the
6147191Sjkoshy// terms of the GNU General Public License as published by the
7147191Sjkoshy// Free Software Foundation; either version 3, or (at your option)
8147191Sjkoshy// any later version.
9147191Sjkoshy
10147191Sjkoshy// This library is distributed in the hope that it will be useful,
11147191Sjkoshy// but WITHOUT ANY WARRANTY; without even the implied warranty of
12147191Sjkoshy// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13147191Sjkoshy// GNU General Public License for more details.
14147191Sjkoshy
15147191Sjkoshy// You should have received a copy of the GNU General Public License along
16147191Sjkoshy// with this library; see the file COPYING3.  If not see
17147191Sjkoshy// <http://www.gnu.org/licenses/>.
18147191Sjkoshy
19147191Sjkoshy// { dg-require-fileio "" }
20147191Sjkoshy
21147191Sjkoshy#include <cstdio>
22147191Sjkoshy#include <fstream>
23147191Sjkoshy#include <cstring>
24147191Sjkoshy#include <ext/stdio_filebuf.h>
25147191Sjkoshy#include <testsuite_hooks.h>
26147191Sjkoshy
27147191Sjkoshyvoid test1()
28147191Sjkoshy{
29147191Sjkoshy  using namespace std;
30147191Sjkoshy  bool test __attribute__((unused)) = true;
31147191Sjkoshy
32196739Sgnn  FILE* file = fopen("tmp_10063-1", "w");
33196739Sgnn  putc('0', file);
34196739Sgnn  putc('1', file);
35196739Sgnn  {
36147191Sjkoshy    __gnu_cxx::stdio_filebuf<char> sbuf(file, ios_base::out);
37196739Sgnn    sbuf.sputc('2');
38196739Sgnn    sbuf.sputc('3');
39196739Sgnn  }
40196739Sgnn  putc('4', file);
41196739Sgnn  fclose(file);
42196739Sgnn
43196739Sgnn  filebuf fbuf;
44196739Sgnn  fbuf.open("tmp_10063-1", ios_base::in);
45185363Sjkoshy  char buf[10];
46147191Sjkoshy  streamsize n = fbuf.sgetn(buf, sizeof(buf));
47147191Sjkoshy  fbuf.close();
48147191Sjkoshy
49147191Sjkoshy  VERIFY(n == 5);
50147191Sjkoshy  VERIFY(!memcmp(buf, "01234", 5));
51147191Sjkoshy}
52147191Sjkoshy
53147191Sjkoshyint main()
54183725Sjkoshy{
55183725Sjkoshy  test1();
56183725Sjkoshy  return 0;
57183725Sjkoshy}
58183725Sjkoshy