#include "camtypes.h"
#include "zstream.h"
#include <errno.h>
Go to the source code of this file.
Defines | |
#define | new CAM_DEBUG_NEW |
#define | CHAR_EOF ((char)EOF) |
Functions | |
DECLARE_SOURCE ("$Revision: 1607 $") | |
CC_IMPLEMENT_DYNAMIC (CCFile, CCObject) | |
CC_IMPLEMENT_DYNAMIC (CCLexFile, CCFile) | |
CC_IMPLEMENT_DYNAMIC (CCStreamFile, CCLexFile) | |
CC_IMPLEMENT_DYNAMIC (CCDiskFile, CCStreamFile) | |
CC_IMPLEMENT_DYNAMIC (CCMemFile, CCLexFile) | |
CC_IMPLEMENT_DYNAMIC (CCMemTextFile, CCMemFile) | |
UINT_PTR | fake_filedesc (iostream &io) |
Creates a fake 'file-descriptor' that can be passed to C libraries, such as the Accusoft filter library, that allow the caller to redirect I/O. | |
iostream * | unfake_filedesc (UINT_PTR nFileDesc) |
Complementary function to fake_filedesc. | |
INT32 ACCUAPI_IO | stream_read (INT32 nFileDesc, char *pchBuffer, unsigned nBufSize) |
Adapts functions that call C-style I/O routines so that they can use C++ streams instead. This function substitutes for the standard C read() function. Instead of nFileDesc being a file-descriptor, it is expected to be an INT32 returned by fake_filedesc. Using this function we can persuade old code, such as the Accusoft library, to read and write from structured storage. | |
INT32 ACCUAPI_IO | stream_write (INT32 nFileDesc, char *pchBuffer, unsigned nBufSize) |
Adapts functions that call C-style I/O routines so that they can use C++ streams instead. This function substitutes for the standard C write() function. Instead of nFileDesc being a file-descriptor, it is expected to be an INT32 returned by fake_filedesc. Using this function we can persuade old code, such as the Accusoft library, to read and write from structured storage. | |
INT32 ACCUAPI_IO | stream_seek (INT32 nFileDesc, INT32 nOffset, unsigned fSeekType) |
Adapts functions that call C-style I/O routines so that they can use C++ streams instead. This function substitutes for the standard C seek() function. Instead of nFileDesc being a file-descriptor, it is expected to be an INT32 returned by fake_filedesc. Using this function we can persuade old code, such as the Accusoft library, to read and write from structured storage. Note that the function assumes that the stream has only one combined seek pointer, just like fstream and costream. If moving the input seek pointer doesn't also move the output seek pointer, as may be the case for some exotic iostream derivatives, then the function won't work properly. | |
Variables | |
const INT32 | TokenBufSize = 256 |
|
Definition at line 137 of file ccfile.cpp. |
|
Definition at line 135 of file ccfile.cpp. |
|
|
|
|
|
|
|
|
|
|
|
|
|
CCFile.cpp - Contains the function declarations of the Kernel CCFile derived classes. These include: CCDiskFile, CCMemFile and CCMemTextFile. |
|
Creates a fake 'file-descriptor' that can be passed to C libraries, such as the Accusoft filter library, that allow the caller to redirect I/O.
Definition at line 6063 of file ccfile.cpp. 06064 { 06065 // Make sure this dirty trick is possible. 06066 ERROR3IF(sizeof(INT32) < sizeof(void*), 06067 "type 'INT32' too small for type 'istream*' in fake_filedesc"); 06068 06069 // Return a "magic number" file-descriptor which is really a pointer to an iostream. 06070 return ~UINT32( (UINT_PTR)(&io) ); 06071 }
|
|
Adapts functions that call C-style I/O routines so that they can use C++ streams instead. This function substitutes for the standard C read() function. Instead of nFileDesc being a file-descriptor, it is expected to be an INT32 returned by fake_filedesc. Using this function we can persuade old code, such as the Accusoft library, to read and write from structured storage.
Definition at line 6124 of file ccfile.cpp. 06125 { 06126 // Extract the input stream object associated with this request. 06127 iostream* ps = unfake_filedesc(nFileDesc); 06128 if (ps == 0 || ps->bad()) return -1; 06129 06130 // Make sure the buffer isn't too big for a signed integer. 06131 if (nBufSize > INT_MAX) 06132 { 06133 ERROR3("Buffer too large for type 'signed INT32' in stream_read"); 06134 nBufSize = INT_MAX; 06135 } 06136 06137 // If we're already at the end of the file then indicate this. 06138 if (ps->eof()) return 0; 06139 06140 // Try to read the data into the given buffer. 06141 if (!ps->read(pchBuffer, (INT32) nBufSize) && !ps->eof()) return -1; 06142 06143 // Return the number of bytes actually read. 06144 return ps->gcount(); 06145 }
|
|
Adapts functions that call C-style I/O routines so that they can use C++ streams instead. This function substitutes for the standard C seek() function. Instead of nFileDesc being a file-descriptor, it is expected to be an INT32 returned by fake_filedesc. Using this function we can persuade old code, such as the Accusoft library, to read and write from structured storage. Note that the function assumes that the stream has only one combined seek pointer, just like fstream and costream. If moving the input seek pointer doesn't also move the output seek pointer, as may be the case for some exotic iostream derivatives, then the function won't work properly.
Definition at line 6219 of file ccfile.cpp. 06220 { 06221 // Extract the stream object associated with this request. Note that in disk-based 06222 // streams (including the costream), the get and put seek positions are tied, so 06223 // moving one moves the other. Hence we can use a plain istream here. 06224 iostream* ps = unfake_filedesc(nFileDesc); 06225 if (ps == 0 || ps->bad()) return -1; 06226 06227 // Convert the standard C flags for fSeekType into the iostream equivalents. 06228 // NB. make sure the flags as passed by Accusoft are the same as those used by 06229 // the Microsoft run-time library! 06230 ios::seekdir dir; 06231 switch (fSeekType) 06232 { 06233 case SEEK_SET: dir = ios::beg; break; 06234 case SEEK_CUR: dir = ios::cur; break; 06235 case SEEK_END: dir = ios::end; break; 06236 default: ERROR3("Bad seek direction in stream_seek"); return -1; 06237 } 06238 06239 // Try to seek to the new position. 06240 if( !ps->seekg( (streampos)nOffset, ios_base::seekdir(dir) ) ) 06241 return -1; 06242 06243 // Check if the iostream has similar semantics to fstream. 06244 ERROR3IF(ps->tellp() != ps->tellg(), 06245 "Put and get seek pointers aren't tied in stream_seek"); 06246 06247 // Return the new seek position. 06248 return (INT32) ps->tellg(); 06249 }
|
|
Adapts functions that call C-style I/O routines so that they can use C++ streams instead. This function substitutes for the standard C write() function. Instead of nFileDesc being a file-descriptor, it is expected to be an INT32 returned by fake_filedesc. Using this function we can persuade old code, such as the Accusoft library, to read and write from structured storage.
Definition at line 6170 of file ccfile.cpp. 06171 { 06172 // Extract the output stream object associated with this request. 06173 iostream* ps = unfake_filedesc(nFileDesc); 06174 if (ps == 0 || ps->bad()) return -1; 06175 06176 // Make sure the buffer isn't too big for a signed integer. 06177 if (nBufSize > INT_MAX) 06178 { 06179 ERROR3("Buffer too large for type 'signed INT32' in stream_write"); 06180 nBufSize = INT_MAX; 06181 } 06182 06183 // Try to write the data from the given buffer. 06184 if (!ps->write(pchBuffer, (INT32) nBufSize)) return -1; 06185 06186 // Return the number of bytes actually written, which is always all or none. 06187 return (INT32) nBufSize; 06188 }
|
|
Complementary function to fake_filedesc.
Definition at line 6088 of file ccfile.cpp. 06089 { 06090 // Make sure this dirty trick is possible. 06091 ERROR3IF(sizeof(INT32) < sizeof(void*), 06092 "type 'INT32' too small for type 'istream*' in unfake_filedesc"); 06093 06094 // Convert this magic number back into a pointer to an iostream. 06095 iostream* ps = (iostream*) (void*) ~nFileDesc; 06096 ERROR3IF(ps == 0, "Null 'file-descriptor' in unfake_filedesc"); 06097 return ps; 06098 }
|
|
Definition at line 840 of file ccfile.cpp. |