Include program counter on action limit notification log
[gnash.git] / libbase / IOChannel.cpp
blob8f6de5adc38cd9c2bbcc26479a0fe69a54a535bd
1 // IOChannel.cpp - a virtual IO channel, for Gnash
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
4 // Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "IOChannel.h"
24 #include <boost/static_assert.hpp>
26 namespace gnash
29 boost::uint32_t
30 IOChannel::read_le32()
32 // read_byte() is boost::uint8_t, so no masks with 0xff are required.
33 boost::uint32_t result = static_cast<boost::uint32_t>(read_byte());
34 result |= static_cast<boost::uint32_t>(read_byte()) << 8;
35 result |= static_cast<boost::uint32_t>(read_byte()) << 16;
36 result |= static_cast<boost::uint32_t>(read_byte()) << 24;
37 return(result);
40 boost::uint16_t
41 IOChannel::read_le16()
43 boost::uint16_t result = static_cast<boost::uint16_t>(read_byte());
44 result |= static_cast<boost::uint16_t>(read_byte()) << 8;
45 return(result);
48 int
49 IOChannel::read_string(char* dst, int max_length)
51 int i = 0;
52 while (i<max_length)
54 dst[i] = read_byte();
55 if (dst[i]=='\0') return i;
56 i++;
59 dst[max_length - 1] = '\0'; // force termination.
61 return -1;
64 float
65 IOChannel::read_float32()
67 union {
68 float f;
69 boost::uint32_t i;
70 } u;
72 BOOST_STATIC_ASSERT(sizeof(u) == sizeof(u.i));
74 u.i = read_le32();
75 return u.f;
78 boost::uint8_t
79 IOChannel::read_byte()
81 boost::uint8_t u;
82 if ( read(&u, 1) == -1 )
84 throw IOException("Could not read a single byte from input");
86 return u;
89 std::streamsize
90 IOChannel::write(const void* /*src*/, std::streamsize /*num*/)
92 throw IOException("This IOChannel implementation doesn't support output");
95 } // namespace gnash