/* filetest.c */ /***************************************************************************/ /* BCW 4.02 Bug report: _rtl_read ( = read ?) dosen't work for: WIN32 at all and WIN 3.1 large dynamic linking! Platform model linking read function bytes ------------------------------------------------- win 3.1 small static _rtl_read OK win 3.1 large static _rtl_read OK * win 3.1 large dynamic _rtl_read -1 * win32 large static _rtl_read -1 * win32 large dynamic _rtl_read -1 win 3.1 small static fread OK win 3.1 large static fread OK win 3.1 large dynamic fread OK win32 large static fread OK win32 large dynamic fread OK ------------------------------------------------- Vesa Lappalainen 14.8.1994 vesal@jyu.fi ****************************************************************************/ #define BY_IOH /* comment this out if you want to use stdio.h */ #include #include #include /***************************************************************************/ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #pragma argsused /***************************************************************************/ LONG n; char *Name = "filetest.c"; static char buf[500]; static char s[100]; #ifdef __WIN32__ /* Platform */ char *platform = "WIN32"; #else char *platform = "WIN 3.1"; #endif #ifdef __SMALL__ /* Memory model */ char *model = "SMALL"; #else char *model = "LARGE"; #endif #ifdef BY_IOH /* ReadTest by io.h and _rlt_read ( = read ) */ char *read_function = "_rtl_read"; static OFSTRUCT OfStruct; HFILE hFile; // OfStruct.cBytes = sizeof(OfStruct); hFile = OpenFile(Name,&OfStruct,OF_READ); if ( hFile == HFILE_ERROR ) goto error; n = _rtl_read(hFile,buf,sizeof(buf)-1); _lclose(hFile); #else /* ReadTest by stdio.h and fread = OK! */ char *read_function = "fread"; FILE *f = fopen(Name,"rb"); if ( f == NULL ) goto error; n = fread(buf,1,sizeof(buf)-1,f); fclose(f); #endif buf[(int)(n>=0 ? n : 0)] = 0; sprintf(s,"Read %ld, %s %s %s",n,read_function,platform,model); MessageBox(NULL,buf,s, MB_APPLMODAL | MB_OK | MB_ICONEXCLAMATION); return 0; error: MessageBox(NULL,Name,"Failed to read", MB_APPLMODAL | MB_OK | MB_ICONEXCLAMATION); return 0; }