monotone

monotone Mtn Source Tree

Root/botan/pipe_io.cpp

1/*************************************************
2* Pipe I/O Source File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#include <botan/pipe.h>
7#include <iostream>
8
9namespace Botan {
10
11/*************************************************
12* Write data from a pipe into an ostream *
13*************************************************/
14std::ostream& operator<<(std::ostream& stream, Pipe& pipe)
15 {
16 SecureVector<byte> buffer(DEFAULT_BUFFERSIZE);
17 while(stream.good() && pipe.remaining())
18 {
19 u32bit got = pipe.read(buffer, buffer.size());
20 stream.write(reinterpret_cast<const char*>(buffer.begin()), got);
21 }
22 if(!stream.good())
23 throw Stream_IO_Error("Pipe output operator (iostream) has failed");
24 return stream;
25 }
26
27/*************************************************
28* Read data from an istream into a pipe *
29*************************************************/
30std::istream& operator>>(std::istream& stream, Pipe& pipe)
31 {
32 SecureVector<byte> buffer(DEFAULT_BUFFERSIZE);
33 while(stream.good())
34 {
35 stream.read(reinterpret_cast<char*>(buffer.begin()), buffer.size());
36 pipe.write(buffer, stream.gcount());
37 }
38 if(stream.bad() || (stream.fail() && !stream.eof()))
39 throw Stream_IO_Error("Pipe input operator (iostream) has failed");
40 return stream;
41 }
42
43}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status