28 #if defined( __WINCE__ ) && _WIN32_WCE < 500
30 int remove(
const char *pathname )
32 wchar_t wcBuffer[ _MAX_PATH + 1 ];
34 mbstowcs( wcBuffer, pathname, strlen( pathname ) + 1 );
35 DeleteFile( wcBuffer );
66 #if defined( __WIN32__ )
68 int debugPrintf(
const char *format, ... )
74 va_start( argPtr, format );
76 #if VC_GE_2005( _MSC_VER )
77 length = vsnprintf_s( buffer, 1024, _TRUNCATE, format, argPtr );
79 length = vsprintf( buffer, format, argPtr );
82 OutputDebugString( buffer );
87 #elif defined( __UNIX__ )
91 int debugPrintf(
const char *format, ... )
96 va_start( argPtr, format );
97 length = vfprintf( stderr, format, argPtr );
113 for( i = 0; fileName[ i ] !=
'\0'; i++ )
115 if( fileName[ i ] ==
':' || fileName[ i ] ==
'/' )
118 if( fileName[ i ] ==
'\0' )
121 #if defined( __WIN32__ )
122 GetTempPath( 512, filenameBuffer );
124 strlcpy_s( filenameBuffer, 1024,
"/tmp/" );
127 strlcat_s( filenameBuffer, 1024, fileName );
128 strlcat_s( filenameBuffer, 1024,
".der" );
132 void debugDumpFile(
IN_STRING const char *fileName,
137 char filenameBuffer[ 1024 ];
143 buildFilePath( fileName, filenameBuffer );
144 #ifdef __STDC_LIB_EXT1__
145 if( fopen_s( &filePtr, filenameBuffer,
"wb" ) != 0 )
148 filePtr = fopen( filenameBuffer,
"wb" );
150 assert( filePtr != NULL );
151 if( filePtr == NULL )
155 count = fwrite( data, 1, dataLength, filePtr );
156 assert( count == dataLength );
159 if( dataLength > 0 && count < dataLength )
160 ( void )
remove( filenameBuffer );
164 void debugDumpFileCert(
IN_STRING const char *fileName,
169 BYTE certData[ 2048 ];
170 char filenameBuffer[ 1024 ];
176 buildFilePath( fileName, filenameBuffer );
177 #ifdef __STDC_LIB_EXT1__
178 if( fopen_s( &filePtr, filenameBuffer,
"wb" ) != 0 )
181 filePtr = fopen( filenameBuffer,
"wb" );
183 assert( filePtr != NULL );
184 if( filePtr == NULL )
191 count = fwrite( msgData.data, 1, msgData.
length, filePtr );
192 assert( count == msgData.
length );
196 ( void )
remove( filenameBuffer );
207 void debugDumpHex(
IN_STRING const char *prefixString,
208 IN_BUFFER( dataLength )
const void *data,
211 char dumpBuffer[ 128 ];
214 offset =
sprintf_s( dumpBuffer, 128,
"%3s %4d %04X ", prefixString,
215 dataLength, checksumData( data, dataLength ) );
218 const int innerLen =
min( dataLength - i, 16 );
222 offset =
sprintf_s( dumpBuffer, 128,
"%3s ",
225 for( j = 0; j < innerLen; j++ )
227 offset +=
sprintf_s( dumpBuffer + offset, 128 - offset,
"%02X ",
228 ( (
BYTE * ) data )[ i + j ] );
231 offset +=
sprintf_s( dumpBuffer + offset, 128 - offset,
" " );
232 for( j = 0; j < innerLen; j++ )
236 offset +=
sprintf_s( dumpBuffer + offset, 128 - offset,
"%c",
237 isprint( ch ) ? ch :
'.' );
239 strcpy_s( dumpBuffer + offset, 128 - offset,
"\n" );
243 #if !defined( __WIN32__ ) || defined( __WINCE__ ) || defined( __ECOS__ )
253 void debugDumpData(
IN_BUFFER( dataLength )
const void *data,
256 char dumpBuffer[ 128 ];
261 const int innerLen =
min( dataLength - i, 16 );
263 offset =
sprintf_s( dumpBuffer, 128,
"%04d: ", i );
264 for( j = 0; j < innerLen; j++ )
266 offset +=
sprintf_s( dumpBuffer + offset, 128 - offset,
"%02X ",
267 ( (
BYTE * ) data )[ i + j ] );
270 offset +=
sprintf_s( dumpBuffer + offset, 128 - offset,
" " );
271 for( j = 0; j < innerLen; j++ )
275 offset +=
sprintf_s( dumpBuffer + offset, 128 - offset,
"%c",
276 isprint( ch ) ? ch :
'.' );
278 strcpy_s( dumpBuffer + offset, 128 - offset,
"\n" );
282 #if !defined( __WIN32__ ) || defined( __WINCE__ ) || defined( __ECOS__ )
302 status = sMemGetDataBlockAbs( stream, position, (
void ** ) &dataPtr,
307 debugDumpData( dataPtr, length );
314 int debugGetStreamByte(
INOUT void *streamPtr,
321 status = sMemGetDataBlockAbs( stream, position, (
void ** ) &dataPtr, 1 );