Panda3D
Loading...
Searching...
No Matches
copy_stream.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file copy_stream.cxx
10 * @author drose
11 * @date 2009-08-27
12 */
13
14#include "copy_stream.h"
15
16/**
17 * Reads the source stream from its current position to the end of the stream,
18 * and writes that data to the dest stream at its current position. Returns
19 * true on success, false on failure.
20 */
21bool
22copy_stream(std::istream &source, std::ostream &dest) {
23 static const size_t buffer_size = 4096;
24 char buffer[buffer_size];
25
26 source.read(buffer, buffer_size);
27 size_t count = source.gcount();
28 while (count != 0) {
29 dest.write(buffer, count);
30 source.read(buffer, buffer_size);
31 count = source.gcount();
32 }
33
34 return (!source.fail() || source.eof()) && (!dest.fail());
35}
bool copy_stream(std::istream &source, std::ostream &dest)
Reads the source stream from its current position to the end of the stream, and writes that data to t...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.