6 :
デフォルトの名無しさん :
02/03/23 02:38 /*FixFile.c*/ #include <stdio.h> #include <stdlib.h> #ifdef DEBUG #define psmDEBUG( x ) (x) #else #define psmDEBUG( x ) #endif fputn( const char* _data, long _size, FILE* _out ); fgetn( char* _data, long _size, FILE* _in ); static char* err_msgs[] = { psmDEBUG( "fopen :: " ) "Cannot open original file.", psmDEBUG( "fseek :: " ) "Failed to move file pointer.", psmDEBUG( "ftell :: " ) "Failed to check file size.", psmDEBUG( "(none) :: " ) "Illegal dust data size.", psmDEBUG( "malloc :: " ) "Failed to get memory allocation.", psmDEBUG( "fgetn :: " ) "Undefined error.", psmDEBUG( "fclose :: " ) "Can't close original File.", psmDEBUG( "fopen :: " ) "Cannot open out file.", psmDEBUG( "fputn :: " ) "Undefined error." };
7 :
デフォルトの名無しさん :02/03/23 02:38
char* binFix( char* _fname, /* original file. */ char* _out, /* fixed file (it will be written by binFix). */ unsigned long _shead, /* size of dust data located header. */ unsigned long _stail /* size of dust data located footer. */ ) { FILE* fp; unsigned m_point = 0; /* as a pointer for [ **err_msgs ]. */ char* _fixed_data; /* as the buffer. */ long org_size; /* size of original file. */ long fixed_size; /* size of fixed file. */
8 :
デフォルトの名無しさん :02/03/23 02:42
return (( fp = fopen( _fname, "rb" ) )? (( ! fseek( fp, 0, SEEK_END ) )? (( ( org_size = ftell( fp ) ) != -1L )? (( ( fixed_size = ( org_size - ( _shead + _stail ) ) < 0 )? (( ! fseek( fp, _shead, SEEK_SET ) )? (( _fixed_data = malloc( sizeof(char) * fixed_size ) )? (( fgetn( _fixed_data, fixed_size, fp ) == fixed_size )? (( fclose(fp) )? (( fp = fopen( _out, "wb" ) )? (( fputn( _fixed_data, fixed_size, _out ) )? (( fclose(fp),free( _fixed_data ), (char*)NULL )) : free( _fixed_data ), fclose(fp), err_msg[9] ) : free( _fixed_data ), fclose(fp), err_msg[8] ) : free( _fixed_data ), err_msg[7] ) : free( _fixed_data ), err_msg[6] ) : free( _fixed_data ), fclose(fp), err_msg[5] ) : fclose(fp), err_msg[4] ) : fclose(fp), err_msg[1] ) : fclose(fp), err_msg[3] ) : fclose(fp), err_msg[2] ) : fclose(fp), err_msg[1] ) : err_msg[0] ); }
9 :
デフォルトの名無しさん :02/03/23 02:42
int fputn( const char* _data, long _size, FILE* _out ){ if( _size < 1 ) return 0; do{ if( fputc( *(_data++), _out ) ) return 0; }while( --size > 0 ); return 1; } long fgetn( char* _data, long _size, FILE* _in ){ long ct = 0; int ch; if( _size < 1 ) return 1; while( (ch = fgetc(_in)) != EOF ) { *(_data++) = ch; ct++; if( --_size < 1 ) break; } return ct; }