Panda3D
 All Classes Functions Variables Enumerations
copy_stream.cxx
00001 // Filename: copy_stream.cxx
00002 // Created by:  drose (27Aug09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "copy_stream.h"
00016 
00017 ////////////////////////////////////////////////////////////////////
00018 //     Function: copy_stream
00019 //       Access: Published
00020 //  Description: Reads the source stream from its current position to
00021 //               the end of the stream, and writes that data to the
00022 //               dest stream at its current position.  Returns true on
00023 //               success, false on failure.
00024 ////////////////////////////////////////////////////////////////////
00025 bool
00026 copy_stream(istream &source, ostream &dest) {
00027   static const size_t buffer_size = 4096;
00028   char buffer[buffer_size];
00029 
00030   source.read(buffer, buffer_size);
00031   size_t count = source.gcount();
00032   while (count != 0) {
00033     dest.write(buffer, count);
00034     source.read(buffer, buffer_size);
00035     count = source.gcount();
00036   }
00037   
00038   return (!source.fail() || source.eof()) && (!dest.fail());
00039 }
 All Classes Functions Variables Enumerations