/usr/include/zipios++/zipheadio.h is in libzipios++-dev 0.1.5.9+cvs.2007.04.28-10.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | #ifndef ZIPHEADIO_H
#define ZIPHEADIO_H
#include "zipios++/zipios-config.h"
#include "zipios++/meta-iostreams.h"
#include <string>
#include <vector>
#include "zipios++/ziphead.h"
#include "zipios++/zipios_defs.h"
namespace zipios {
// byte order conversion functions.
// ztohs (zip-to-host-short)
#ifdef MY_BIG_ENDIAN
inline uint16 ztohs ( unsigned char *buf ) {
uint16 out ;
// *( reinterpret_cast<unsigned char *>( &out ) ) = *( buf + 1 );
// *( reinterpret_cast<unsigned char *>( &out ) + 1 ) = *( buf );
out = ( static_cast< uint16 >( buf[ 0 ] ) << 8 ) +
( static_cast< uint16 >( buf[ 1 ] ) ) ;
return out;
}
// ztohl (zip-to-host-long)
inline uint32 ztohl ( unsigned char *buf ) {
uint32 out;
out = ( static_cast< uint32 >( buf[ 0 ] ) << 24 ) +
( static_cast< uint32 >( buf[ 1 ] ) << 16 ) +
( static_cast< uint32 >( buf[ 2 ] ) << 8 ) +
( static_cast< uint32 >( buf[ 3 ] ) ) ;
return out;
}
#else
inline uint16 ztohs ( unsigned char *buf ) {
uint16 out ;
out = ( static_cast< uint16 >( buf[ 1 ] ) << 8 ) +
( static_cast< uint16 >( buf[ 0 ] ) ) ;
return out;
}
// ztohl (zip-to-host-long)
inline uint32 ztohl ( unsigned char *buf ) {
uint32 out;
out = ( static_cast< uint32 >( buf[ 3 ] ) << 24 ) +
( static_cast< uint32 >( buf[ 2 ] ) << 16 ) +
( static_cast< uint32 >( buf[ 1 ] ) << 8 ) +
( static_cast< uint32 >( buf[ 0 ] ) ) ;
// cerr << "buf : " << static_cast< int >( buf[ 0 ] ) ;
// cerr << " " << static_cast< int >( buf[ 1 ] ) ;
// cerr << " " << static_cast< int >( buf[ 2 ] ) ;
// cerr << " " << static_cast< int >( buf[ 3 ] ) << endl ;
// cerr << "uint32 " << out << endl ;
return out;
}
#endif
// htozl (host-to-zip-long)
inline uint32 htozl ( unsigned char *buf ) {
return ztohl( buf ) ;
}
// htozs (host-to-zip-short)
inline uint16 htozs ( unsigned char *buf ) {
return ztohs( buf ) ;
}
inline uint32 readUint32 ( istream &is ) {
static const int buf_len = sizeof ( uint32 ) ;
unsigned char buf [ buf_len ] ;
int rsf = 0 ;
while ( rsf < buf_len ) {
is.read ( reinterpret_cast< char * >( buf ) + rsf, buf_len - rsf ) ;
rsf += is.gcount () ;
}
return ztohl ( buf ) ;
}
inline void writeUint32 ( uint32 host_val, ostream &os ) {
uint32 val = htozl( reinterpret_cast< unsigned char * >( &host_val ) ) ;
os.write( reinterpret_cast< char * >( &val ), sizeof( uint32 ) ) ;
}
inline uint16 readUint16 ( istream &is ) {
static const int buf_len = sizeof ( uint16 ) ;
unsigned char buf [ buf_len ] ;
int rsf = 0 ;
while ( rsf < buf_len ) {
is.read ( reinterpret_cast< char * >( buf ) + rsf, buf_len - rsf ) ;
rsf += is.gcount () ;
}
return ztohs ( buf ) ;
}
inline void writeUint16 ( uint16 host_val, ostream &os ) {
uint16 val = htozl( reinterpret_cast< unsigned char * >( &host_val ) ) ;
os.write( reinterpret_cast< char * >( &val ), sizeof( uint16 ) ) ;
}
inline void readByteSeq ( istream &is, string &con, int count ) {
char *buf = new char [ count + 1 ] ;
int rsf = 0 ;
while ( rsf < count && is ) {
is.read ( buf + rsf, count - rsf ) ;
rsf += is.gcount() ;
}
buf [ count ] = '\0' ;
con = buf ;
delete [] buf ;
}
inline void writeByteSeq( ostream &os, const string &con ) {
os << con ;
}
inline void readByteSeq ( istream &is, unsigned char *buf, int count ) {
int rsf = 0 ;
while ( rsf < count && is ) {
is.read ( reinterpret_cast< char * >( buf ) + rsf, count - rsf ) ;
rsf += is.gcount() ;
}
}
inline void writeByteSeq ( ostream &os, const unsigned char *buf, int count ) {
os.rdbuf()->sputn( reinterpret_cast< const char * >( buf ), count ) ;
}
inline void readByteSeq ( istream &is, vector < unsigned char > &vec, int count ) {
unsigned char *buf = new unsigned char [ count ] ;
int rsf = 0 ;
while ( rsf < count && is ) {
is.read ( reinterpret_cast< char * >( buf ) + rsf, count - rsf ) ;
rsf += is.gcount() ;
}
vec.insert ( vec.end (), buf, buf + count ) ;
delete [] buf ;
}
inline void writeByteSeq ( ostream &os, const vector < unsigned char > &vec ) {
os.rdbuf()->sputn( reinterpret_cast< const char * >( &( vec[ 0 ] ) ), vec.size() ) ;
}
istream& operator>> ( istream &is, ZipLocalEntry &zlh ) ;
istream& operator>> ( istream &is, DataDescriptor &dd ) ;
istream& operator>> ( istream &is, ZipCDirEntry &zcdh ) ;
// istream& operator>> ( istream &is, EndOfCentralDirectory &eocd ) ;
ostream &operator<< ( ostream &os, const ZipLocalEntry &zlh ) ;
ostream &operator<< ( ostream &os, const ZipCDirEntry &zcdh ) ;
ostream &operator<< ( ostream &os, const EndOfCentralDirectory &eocd ) ;
} // namespace
#endif
/** \file
Header file that defines I/O functions for the header structures
defined in ziphead.h.
*/
/*
Zipios++ - a small C++ library that provides easy access to .zip files.
Copyright (C) 2000 Thomas Søndergaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
|