void close()
    {
        if (header_.is_directory())
            return;

        if (pos_ != header_.compressed_size)
            throw BOOST_IOSTREAMS_FAILURE("LZH entry size mismatch");

        if (!header_.crc16_checksum)
            throw BOOST_IOSTREAMS_FAILURE("LZH CRC is not set");

        pos_ = 0;
    }
inline BOOST_IOSTREAMS_FAILURE system_failure(const char* msg)
{
    std::string result;
#ifdef BOOST_IOSTREAMS_WINDOWS
    DWORD err;
    LPVOID lpMsgBuf;
    if ( (err = ::GetLastError()) != NO_ERROR &&
         ::FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER |
                           FORMAT_MESSAGE_FROM_SYSTEM,
                           NULL,
                           err,
                           MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                           (LPSTR) &lpMsgBuf,
                           0,
                           NULL ) != 0 )
    {
        result.reserve(std::strlen(msg) + 2 + std::strlen((LPSTR)lpMsgBuf));
        result.append(msg);
        result.append(": ");
        result.append((LPSTR) lpMsgBuf);
        ::LocalFree(lpMsgBuf);
    } else {
        result += msg;
    }
#else
    const char* system_msg = errno ? strerror(errno) : "";
    result.reserve(std::strlen(msg) + 2 + std::strlen(system_msg));
    result.append(msg);
    result.append(": ");
    result.append(system_msg);
#endif
    return BOOST_IOSTREAMS_FAILURE(result);
}
Example #3
0
    std::streamsize write(const char* s, std::streamsize n)
    {
        int error;
        if (::pa_simple_write(handle_, s, n, &error) < 0)
            throw BOOST_IOSTREAMS_FAILURE("pa_simple_write() failed");

        return n;
    }
void file_descriptor::close_impl(impl& i)
{
#ifdef BOOST_IOSTREAMS_WINDOWS
    if (i.flags_ & impl::has_handle) {
        if (!::CloseHandle(i.handle_))
            throw BOOST_IOSTREAMS_FAILURE("bad close");
        i.fd_ = -1;
        i.flags_ = 0;
        return;
    }
#endif
    if (i.fd_ != -1) {
        if (BOOST_RTL(close)(i.fd_) == -1)
            throw BOOST_IOSTREAMS_FAILURE("bad close");
        i.fd_ = -1;
        i.flags_ = 0;
    }
}
Example #5
0
void skip(Filter& flt, Device& dev, stream_offset off, mpl::false_)
{ 
    typedef typename char_type_of<Device>::type char_type;
    char_type c;
    for (stream_offset z = 0; z < off; ) {
        std::streamsize amt;
        if ((amt = iostreams::read(flt, dev, &c, 1)) == -1)
            throw BOOST_IOSTREAMS_FAILURE("bad skip offset");
        if (amt == 1)
            ++z;
    }
}
Example #6
0
void skip(Device& dev, stream_offset off, mpl::false_)
{   // gcc 2.95 needs namespace qualification for char_traits.
    typedef typename char_type_of<Device>::type  char_type;
    typedef iostreams::char_traits<char_type>    traits_type;
    for (stream_offset z = 0; z < off; ) {
        typename traits_type::int_type c;
        if (traits_type::is_eof(c = iostreams::get(dev)))
            throw BOOST_IOSTREAMS_FAILURE("bad skip offset");
        if (!traits_type::would_block(c))
            ++z;
    }
}
 std::streamsize read(char* s, std::streamsize n)
 {
     std::streamsize amt = raw_.read(s, n);
     if (head_.format == cpio::svr4_chksum)
     {
         if (amt == n)
             sum16_.process_bytes(s, amt);
         else if (sum16_.checksum() != *head_.checksum)
             throw BOOST_IOSTREAMS_FAILURE("cpio checksum missmatch");
     }
     return amt;
 }
    cpio::header read_header()
    {
        cpio::header head;
        std::size_t name_size = 0;

        char magic[6];
        iostreams::blocking_read(src_, magic);

        if (std::memcmp(magic, "070707", sizeof(magic)) == 0)
        {
            char buf[hamigaki::struct_size<cpio::raw_header>::value];
            std::memcpy(buf, magic, sizeof(magic));
            iostreams::blocking_read(
                src_, buf+sizeof(magic), sizeof(buf)-sizeof(magic));

            cpio::raw_header raw;
            hamigaki::binary_read(buf, raw);
            name_size = read_cpio_header(head, raw);
        }
        else if (
            (std::memcmp(magic, "070701", sizeof(magic)) == 0) ||
            (std::memcmp(magic, "070702", sizeof(magic)) == 0) )
        {
            char buf[hamigaki::struct_size<cpio::svr4_header>::value];
            std::memcpy(buf, magic, sizeof(magic));
            iostreams::blocking_read(
                src_, buf+sizeof(magic), sizeof(buf)-sizeof(magic));

            cpio::svr4_header raw;
            hamigaki::binary_read(buf, raw);
            name_size = read_cpio_header(head, raw);
        }
        else if (hamigaki::decode_int<native,2>(magic) == 070707)
        {
            char buf[hamigaki::struct_size<cpio::binary_header>::value];
            std::memcpy(buf, magic, sizeof(magic));
            iostreams::blocking_read(
                src_, buf+sizeof(magic), sizeof(buf)-sizeof(magic));

            cpio::binary_header bin;
            hamigaki::binary_read(buf, bin);
            name_size = read_cpio_header(head, bin);
        }
        else
            throw BOOST_IOSTREAMS_FAILURE("unknown cpio header format");

        boost::scoped_array<char> buf(new char[name_size]);
        iostreams::blocking_read(src_, buf.get(), name_size);
        head.path = buf.get();

        return head;
    }
Example #9
0
    impl(const char* app, const char* name, const pcm_format& fmt) : fmt_(fmt)
    {
        pa_sample_spec ss = {};
        ss.format = type_to_format(fmt.type);
        ss.rate = fmt.rate;
        ss.channels = fmt.channels;

        int error;
        handle_ = ::pa_simple_new(
            0, app, PA_STREAM_PLAYBACK, 0, name, &ss, 0, 0, &error);
        if (handle_ == 0)
            throw BOOST_IOSTREAMS_FAILURE("pa_simple_new() failed");
    }
Example #10
0
void skip_impl(
    Device& dev, boost::iostreams::stream_offset off, boost::mpl::false_)
{
    char buf[256];

    while (off > 0)
    {
        std::streamsize size = static_cast<std::streamsize>(sizeof(buf));
        size = auto_min(size, off);

        std::streamsize amt = boost::iostreams::read(dev, buf, size);
        if (amt == -1)
            throw BOOST_IOSTREAMS_FAILURE("bad skip offset");
        off -= amt;
    }
}
Example #11
0
 void open(const Device& dev, int buffer_size)
 {
     if (flags_ & f_open)
         throw BOOST_IOSTREAMS_FAILURE("already open");
     if (buffer_size == -1)
         buffer_size = default_filter_buffer_size;
     int max_length = cvt_.get().max_length();
     buffer_size = (std::max)(buffer_size, 2 * max_length);
     if (can_read::value) {
         buf_.first().resize(buffer_size);
         buf_.first().set(0, 0);
     }
     if (can_write::value && !is_double::value) {
         buf_.second().resize(buffer_size);
         buf_.second().set(0, 0);
     }
     dev_.reset(concept_adapter<policy_type>(dev));
     flags_ |= f_open;
 }
Example #12
0
void CompressionType::push(io::filtering_stream<io::input>& fs) const
{
	switch (m_Type) {
	case NONE:
		break;
#ifdef HAVE_LIBZ
	case ZLIB:
		fs.push(io::zlib_decompressor(io::zlib_params(9, io::zlib::deflated, 15, 8, io::zlib::default_strategy, true)));
		break;
#endif
#ifdef HAVE_LIBBZ2
	case BZIP2:
		fs.push(io::bzip2_decompressor());
		break;
#endif
	case XOR:
		fs.push(io::xor_filter('2'));
		break;
#ifdef HAVE_LIBLZO2
	case LZO:
		fs.push(io::lzo_decompressor());
		break;
#endif
#ifdef HAVE_LIBLZMA
	case LZMA:
		fs.push(io::lzma_decompressor());
		break;
#endif
	default:
	{
		// If input file is using unsopported version
		// throw an exception and FuseCompress will
		// process such file as uncompressed.

		throw BOOST_IOSTREAMS_FAILURE("unsupported compression type");
		break;
	}
	}
}
Example #13
0
 static std::streampos
 seek(T&, stream_offset, BOOST_IOS::seekdir, BOOST_IOS::openmode)
 {
     throw BOOST_IOSTREAMS_FAILURE("cannot seek");
     BOOST_UNREACHABLE_RETURN(std::streampos(std::streamoff(-1)))
 }
Example #14
0
 void close()
 {
     int error;
     if (::pa_simple_drain(handle_, &error) < 0)
         throw BOOST_IOSTREAMS_FAILURE("pa_simple_write() failed");
 }
Example #15
0
inline BOOST_IOSTREAMS_FAILURE bad_seek() 
{ return BOOST_IOSTREAMS_FAILURE("bad seek"); }
Example #16
0
inline BOOST_IOSTREAMS_FAILURE write_area_exhausted() 
{ return BOOST_IOSTREAMS_FAILURE("write area exhausted"); }
Example #17
0
inline BOOST_IOSTREAMS_FAILURE bad_write() 
{ return BOOST_IOSTREAMS_FAILURE("bad write"); }
Example #18
0
inline BOOST_IOSTREAMS_FAILURE bad_putback() 
{ return BOOST_IOSTREAMS_FAILURE("putback buffer full"); }
Example #19
0
inline BOOST_IOSTREAMS_FAILURE bad_read() 
{ return BOOST_IOSTREAMS_FAILURE("bad read"); }
Example #20
0
inline BOOST_IOSTREAMS_FAILURE cant_seek() 
{ return BOOST_IOSTREAMS_FAILURE("no random access"); }
Example #21
0
inline BOOST_IOSTREAMS_FAILURE cant_write() 
{ return BOOST_IOSTREAMS_FAILURE("no write access"); }
Example #22
0
inline BOOST_IOSTREAMS_FAILURE cant_read() 
{ return BOOST_IOSTREAMS_FAILURE("no read access"); }
Example #23
0
    bool filter(const char_type*& src_begin, const char_type* src_end,
		char_type*& dest_begin, char_type* dest_end,
		bool flush)
    {
      if (! ucnv_from && ! ucnv_to) {
	// no converter... simply copy!
	
	const size_t copy_size = std::min(src_end - src_begin, dest_end - dest_begin);
	
	std::copy(src_begin, src_begin + copy_size, dest_begin);
	
	src_begin += copy_size;
	dest_begin += copy_size;
	
	return false;
      }

      UChar* pivot_end = pivot_start + boost::iostreams::default_device_buffer_size;
      
      UErrorCode status = U_ZERO_ERROR;
      
      if (pivot_target != pivot_end) {
	const char_type* src_begin_prev = src_begin;
	UChar* pivot_target_prev = pivot_target;
	
	status = U_ZERO_ERROR;
	ucnv_toUnicode(ucnv_from, &pivot_target, pivot_end, &src_begin, src_end, 0, flush, &status);
	
	offset_from += src_begin - src_begin_prev;
	offset_pivot_target += pivot_target - pivot_target_prev;
	
	if (status != U_BUFFER_OVERFLOW_ERROR && U_FAILURE(status)) {
	  UErrorCode status_getname = U_ZERO_ERROR;
	  const char* encoding = ucnv_getName(ucnv_from, &status_getname);
	  
	  std::ostringstream offset_stream;
	  offset_stream << offset_from;

	  std::ostringstream offset_stream_unicode;
	  offset_stream_unicode << offset_pivot_target;
	  
	  message_from = (std::string("ucnv_toUnicode(): ") + u_errorName(status)
			  + " from " + encoding
			  + " offset: " + offset_stream.str()
			  + " unicode offset: " + offset_stream_unicode.str());
	  throw BOOST_IOSTREAMS_FAILURE(message_from);
	}
      }
      
      char_type*   dest_begin_prev = dest_begin;
      const UChar* pivot_source_prev = pivot_source;
      
      status = U_ZERO_ERROR;
      ucnv_fromUnicode(ucnv_to, &dest_begin, dest_end, &pivot_source, pivot_target, 0, flush, &status);
      
      offset_to += dest_begin - dest_begin_prev;
      offset_pivot_source += pivot_source - pivot_source_prev;
      
      if (status != U_BUFFER_OVERFLOW_ERROR && U_FAILURE(status)) {
	UErrorCode status_getname = U_ZERO_ERROR;
	const char* encoding = ucnv_getName(ucnv_to, &status_getname);
	
	std::ostringstream offset_stream;
	offset_stream << offset_to;
	
	std::ostringstream offset_stream_unicode;
	offset_stream_unicode << offset_pivot_source;
	
	message_to = (std::string("ucnv_fromUnicode(): ") + u_errorName(status) 
		      + " to " + encoding
		      + " offset: " + offset_stream.str()
		      + " unicode offset: " + offset_stream_unicode.str());
	throw BOOST_IOSTREAMS_FAILURE(message_to);
      }
      
      if (pivot_source == pivot_target) {
	pivot_source = pivot_start;
	pivot_target = pivot_start;
      }
      
      return status == U_BUFFER_OVERFLOW_ERROR;
    }