Listing 4: smallio.c Replacement C runtime library functions
#pragma comment(linker, "/nodefaultlib") #include <windows.h> #include "smallio.h" size_t __cdecl strlen(const char* s) { const char* p = s; while ( *p != 0 ) p++; return p - s; } char* __cdecl strcpy( char * s, const char * t ) { char* p = s; while ( *s++ = *t++ ) ; return p; } char* __cdecl strcat( char * s, const char * t ) { int L = strlen( s ); strcpy( s + L, t ); return s; } void ReadWholeFile( char* name, char** wf, char** wfend ) { int size; DWORD got; HANDLE h = CreateFile( name, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ); *wf = 0; if ( h == INVALID_HANDLE_VALUE ) return; size = GetFileSize( h, 0 ); if ( size == -1 ) return; *wf = (char*)GlobalAlloc( GPTR, size ); *wfend = *wf + size; if ( ReadFile( h, *wf, size, &got, 0 ) == 0 || got == 0 ) *wf= 0; CloseHandle( h ); } void WriteWholeFile( char* name, char* s, int size ) { DWORD written; HANDLE h = CreateFile( name, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 ); if ( h == INVALID_HANDLE_VALUE ) return; WriteFile( h, (LPCVOID)s, size, &written, 0 ); CloseHandle( h ); } void ReleaseWholeFile( char* wf ) { GlobalFree( (HGLOBAL)wf ); } void WinMainCRTStartup() { UINT uExitCode = (UINT)WinMain(0, 0, 0, 0); ExitProcess(uExitCode); } /* End of File */