void ICVM_lseek(void){ iRETURNs64( i_lseek( rSTKs32(0), rSTKs64(1), rSTKu32(2) ) ); icvm_returnerr(); }
/**************************************************************************** REMARKS: VxD implementation of the ANSI C fseek function. ****************************************************************************/ int fseek( FILE *f, long int offset, int whence) { if (whence == 0) f->offset = offset; else if (whence == 1) f->offset += offset; else if (whence == 2) f->offset = f->filesize + offset; if (!initComplete) i_lseek(f->handle,f->offset,0); return 0; }
/**************************************************************************** REMARKS: VxD implementation of the ANSI C fopen function. ****************************************************************************/ FILE * fopen( const char *filename, const char *mode) { FILE *f = malloc(sizeof(FILE)); long oldpos; if (f) { f->offset = 0; f->text = (mode[1] == 't' || mode[2] == 't'); f->writemode = (mode[0] == 'w') || (mode[0] == 'a'); f->unputc = EOF; f->endp = f->buf + sizeof(f->buf); f->curp = f->startp = f->buf; if (initComplete) { WORD omode,error; BYTE action; if (mode[0] == 'r') { omode = OPEN_ACCESS_READONLY | OPEN_SHARE_COMPATIBLE; action = ACTION_IFEXISTS_OPEN | ACTION_IFNOTEXISTS_FAIL; } else if (mode[0] == 'w') { omode = OPEN_ACCESS_WRITEONLY | OPEN_SHARE_COMPATIBLE; action = ACTION_IFEXISTS_TRUNCATE | ACTION_IFNOTEXISTS_CREATE; } else { omode = OPEN_ACCESS_READWRITE | OPEN_SHARE_COMPATIBLE; action = ACTION_IFEXISTS_OPEN | ACTION_IFNOTEXISTS_CREATE; } f->handle = (int)R0_OpenCreateFile(false,(char*)filename,omode,ATTR_NORMAL,action,0,&error,&action); if (f->handle == 0) { free(f); return NULL; } f->filesize = R0_GetFileSize((HANDLE)f->handle,&error); if (mode[0] == 'a') fseek(f,0,2); } else { int oflag,pmode; if (mode[0] == 'r') { pmode = _S_IREAD; oflag = _O_RDONLY; } else if (mode[0] == 'w') { pmode = _S_IWRITE; oflag = _O_WRONLY | _O_CREAT | _O_TRUNC; } else { pmode = _S_IWRITE; oflag = _O_RDWR | _O_CREAT | _O_APPEND; } if (f->text) oflag |= _O_TEXT; else oflag |= _O_BINARY; if ((f->handle = i_open(filename,oflag,pmode)) == -1) { free(f); return NULL; } oldpos = i_lseek(f->handle,0,1); f->filesize = i_lseek(f->handle,0,2); i_lseek(f->handle,oldpos,0); } } return f; }