2
fdstream.h C++ Stream From File Descripter
3
Copyright (c) 2005 Kriang Lerdsuwanakij
4
email: lerdsuwa@users.sourceforge.net
6
Adapt from The C++ Standard Library: A Tutorial and Reference
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
#ifndef __K_FDSTREAM_H
24
#define __K_FDSTREAM_H
33
class fdoutbuf : public std::streambuf {
36
fdoutbuf(int _fd) : fd(_fd) {}
38
virtual int_type overflow(int_type c = std::char_traits<char>::eof()) {
41
if (write(fd, &z, 1) != 1)
46
virtual std::streamsize xsputn(const char *s, std::streamsize n) {
47
return write(fd, s, n);
51
class fdostream : private fdoutbuf, public std::ostream {
53
fdostream(int fd) : fdoutbuf(fd), std::ostream(this) {}
57
#endif /* __K_FDSTREAM_H */