/* ** Truncate an open file to a specified size */ int os2Truncate( sqlite3_file *id, i64 nByte ){ APIRET rc = NO_ERROR; ULONG filePosition = 0L; os2File *pFile = (os2File*)id; OSTRACE3( "TRUNCATE %d %lld\n", pFile->h, nByte ); SimulateIOError( return SQLITE_IOERR_TRUNCATE ); rc = DosSetFilePtr( pFile->h, nByte, FILE_BEGIN, &filePosition ); if( rc != NO_ERROR ){ return SQLITE_IOERR; } rc = DosSetFilePtr( pFile->h, 0L, FILE_END, &filePosition ); return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR; }
void *__PHYSFS_platformOpenAppend(const char *filename) { ULONG dummy = 0; HFILE hfile = NULLHANDLE; APIRET rc; /* * File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise * DosQueryFileInfo() will fail if we try to get a file length, etc. */ rc = os2err(DosOpen(filename, &hfile, &dummy, 0, FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW, OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY | OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE | OPEN_ACCESS_READWRITE, NULL)); if (rc == NO_ERROR) { if (os2err(DosSetFilePtr(hfile, 0, FILE_END, &dummy)) != NO_ERROR) { DosClose(hfile); hfile = NULLHANDLE; } /* if */ } /* if */ return((void *) hfile); } /* __PHYSFS_platformOpenAppend */
/* ** Read data from a file into a buffer. Return SQLITE_OK if all ** bytes were read successfully and SQLITE_IOERR if anything goes ** wrong. */ static int os2Read( sqlite3_file *id, /* File to read from */ void *pBuf, /* Write content into this buffer */ int amt, /* Number of bytes to read */ sqlite3_int64 offset /* Begin reading at this offset */ ){ ULONG fileLocation = 0L; ULONG got; os2File *pFile = (os2File*)id; assert( id!=0 ); SimulateIOError( return SQLITE_IOERR_READ ); OSTRACE3( "READ %d lock=%d\n", pFile->h, pFile->locktype ); if( DosSetFilePtr(pFile->h, offset, FILE_BEGIN, &fileLocation) != NO_ERROR ){ return SQLITE_IOERR; } if( DosRead( pFile->h, pBuf, amt, &got ) != NO_ERROR ){ return SQLITE_IOERR_READ; } if( got == (ULONG)amt ) return SQLITE_OK; else { /* Unread portions of the input buffer must be zero-filled */ memset(&((char*)pBuf)[got], 0, amt-got); return SQLITE_IOERR_SHORT_READ; } }
/* ** Write data from a buffer into a file. Return SQLITE_OK on success ** or some other error code on failure. */ static int os2Write( sqlite3_file *id, /* File to write into */ const void *pBuf, /* The bytes to be written */ int amt, /* Number of bytes to write */ sqlite3_int64 offset /* Offset into the file to begin writing at */ ){ ULONG fileLocation = 0L; APIRET rc = NO_ERROR; ULONG wrote; os2File *pFile = (os2File*)id; assert( id!=0 ); SimulateIOError( return SQLITE_IOERR_WRITE ); SimulateDiskfullError( return SQLITE_FULL ); OSTRACE3( "WRITE %d lock=%d\n", pFile->h, pFile->locktype ); if( DosSetFilePtr(pFile->h, offset, FILE_BEGIN, &fileLocation) != NO_ERROR ){ return SQLITE_IOERR; } assert( amt>0 ); while( amt > 0 && ( rc = DosWrite( pFile->h, (PVOID)pBuf, amt, &wrote ) ) == NO_ERROR && wrote > 0 ){ amt -= wrote; pBuf = &((char*)pBuf)[wrote]; } return ( rc != NO_ERROR || amt > (int)wrote ) ? SQLITE_FULL : SQLITE_OK; }
long tell_func(void *datasource) { ULONG ibActual; DosSetFilePtr( (HFILE)datasource, 0, FILE_CURRENT, &ibActual ); return ibActual; }
// Title и String - строки, которые надо записать. VOID Krnl_Debug_Log( PCHAR Title, PCHAR String ) { // Если файла нет - создаем его. HFILE File = NULLHANDLE; ULONG Report = 0; ULONG New_size = 0; PEAOP2 EAs = NULL; ULONG Action = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW; ULONG Mode = OPEN_FLAGS_FAIL_ON_ERROR | OPEN_SHARE_DENYWRITE | OPEN_ACCESS_WRITEONLY; CHAR Log_file_name[ SIZE_OF_PATH ] = ""; GetCurrentPath( Log_file_name ); strcat( Log_file_name, "\\_log.txt" ); DosOpen( Log_file_name, &File, &Report, New_size, FILE_COMMON_ATTRIBUTES, Action, Mode, EAs ); // Записываем строку. if( Report != FILE_CREATED ) { DosSetFilePtr( File, 0, FILE_END, &Report ); DosWrite( File, "\n", strlen( "\n" ), &Report ); } if( Title[ 0 ] != 0 ) { DosWrite( File, Title, strlen( Title ), &Report ); DosWrite( File, ": ", strlen( ": " ), &Report ); } DosWrite( File, String, strlen( String ), &Report ); // Закрываем файл. DosClose( File ); File = NULLHANDLE; // Возврат. return; }
/* Write the contents of buf into record # blkno, for the block file * identified by blkhandle. Blocks are numbered starting at 0. The * requested block may be past the end of the file, in which case * this function is expected to extend the file. */ void blkwrite (BLK *buf, /* buffer, holds contents of block */ _BLKNO_ blkno) /* where to write it */ { LONG offset; ULONG actual; #ifdef FEATURE_RAM /* store it in RAM */ if (nblks > 0) { if (blkno >= nblks) { blklist = (BLK **)realloc(blklist, (nblks + 1024) * sizeof(BLK *)); memset(&blklist[nblks], 0, 1024 * sizeof(BLK *)); nblks += 1024; } if (!blklist[blkno]) blklist[blkno] = malloc(o_blksize); memcpy(blklist[blkno], buf, o_blksize); return; } #endif /* write the block */ offset = (LONG)blkno * (LONG)o_blksize; if (DosSetFilePtr (fd, offset, FILE_BEGIN, &actual) != NO_ERROR || DosWrite (fd, buf, o_blksize, &actual) != NO_ERROR || actual != o_blksize) { msg (MSG_FATAL, "blkwrite(%d) failed", blkno); } /* if */ }
/* ** Move the read/write pointer in a file. */ int os2Seek( OsFile *id, i64 offset ){ APIRET rc = NO_ERROR; ULONG filePointer = 0L; assert( id!=0 ); rc = DosSetFilePtr( ((os2File*)id)->h, offset, FILE_BEGIN, &filePointer ); OSTRACE3( "SEEK %d %lld\n", ((os2File*)id)->h, offset ); return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR; }
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque) { ULONG pos; HFILE hfile = (HFILE) opaque; APIRET rc = os2err(DosSetFilePtr(hfile, 0, FILE_CURRENT, &pos)); BAIL_IF_MACRO(rc != NO_ERROR, NULL, -1); return((PHYSFS_sint64) pos); } /* __PHYSFS_platformTell */
ULONG APIENTRY FileExceptionHandler( PEXCEPTIONREPORTRECORD pReport, struct _EXCEPTIONREGISTRATIONRECORD * pXReg, PCONTEXTRECORD pContext, PVOID pDispatch) { CAMJXRR * pReg = (CAMJXRR*)pXReg; ULONG ulRtn = XCPT_CONTINUE_SEARCH; ULONG rc = 0; ULONG ulSize; ULONG ulAttr; LONG lOffs; char * pErr = 0; PVOID pMem; do { if (pReport->fHandlerFlags || pReport->ExceptionNum != XCPT_ACCESS_VIOLATION || pReport->ExceptionAddress == (PVOID)XCPT_DATA_UNKNOWN || pReport->ExceptionInfo[0] != XCPT_READ_ACCESS || pReport->ExceptionInfo[1] == XCPT_DATA_UNKNOWN || pReport->ExceptionInfo[1] < (ULONG)pReg->pBase || pReport->ExceptionInfo[1] >= (ULONG)pReg->pEnd) { printf( "*** Exception not handled - %08lx\n", pReport->ExceptionNum); return (ulRtn); } if (pReg->lFilePtr >= pReg->lEOF) ERRMSG( "already at EOF") pMem = (PVOID)(pReport->ExceptionInfo[1] & ~0xFFF); ulSize = 1; ulAttr = 0; rc = DosQueryMem( pMem, &ulSize, &ulAttr); if (rc) ERRMSG( "DosQueryMem") if (ulAttr & (PAG_FREE | PAG_COMMIT)) { rc = ulAttr; ERRMSG( "unexpected memory attributes") } rc = DosSetMem( pMem, 0x1000, PAG_COMMIT | PAG_DEFAULT); if (rc) ERRMSG( "DosSetMem") lOffs = (BYTE*)pMem - pReg->pBase; if (lOffs != pReg->lFilePtr) { rc = DosSetFilePtr( pReg->hFile, lOffs, FILE_BEGIN, &pReg->lFilePtr); if (rc) ERRMSG( "DosSetFilePtr") if (lOffs != pReg->lFilePtr) { rc = lOffs; ERRMSG( "seek beyond EOF") }
APIRET XIOfile32::doSetFilePtr(int64_t pos, ULONG method, int64_t* newpos) { if (pos > 0x7fffffff || pos < 0x80000000) return ERROR_INVALID_PARAMETER; ULONG actual; APIRET rc = DosSetFilePtr(s_handle, (long)pos, method, &actual); if (!rc && newpos) *newpos = actual; return rc; }
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos) { ULONG dummy; HFILE hfile = (HFILE) opaque; LONG dist = (LONG) pos; /* hooray for 32-bit filesystem limits! :) */ BAIL_IF_MACRO((PHYSFS_uint64) dist != pos, ERR_SEEK_OUT_OF_RANGE, 0); return(os2err(DosSetFilePtr(hfile, dist, FILE_BEGIN, &dummy)) == NO_ERROR); } /* __PHYSFS_platformSeek */
ULONG MsdGetThumb( CAMRecPtr pcr, char ** ppBuf) { ULONG rc = 0; ULONG ul; HFILE hFile = 0; char szPath[CCHMAXPATH]; do { *ppBuf = malloc( pcr->tnsize); if (!*ppBuf) { rc = CAMERR_MALLOC; break; } strcpy( szPath, pcr->path); strcat( szPath, (pcr->orgname ? pcr->orgname : pcr->title)); rc = DosOpen( szPath, &hFile, &ul, 0, 0, (OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS), (OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYWRITE | OPEN_ACCESS_READONLY), 0); if (rc) { printf( "MsdGetThumb - DosOpen - rc= 0x%lx\n", rc); break; } rc = DosSetFilePtr( hFile, pcr->tnoffs, FILE_BEGIN, &ul); if (rc) { printf( "MsdGetThumb - DosSetFilePtr - rc= 0x%lx\n", rc); break; } if (ul != pcr->tnoffs) { rc = CAMERR_NEEDDATA; printf( "MsdGetThumb - DosSetFilePtr - seek failed\n"); break; } ul = FileReadFile( hFile, *ppBuf, pcr->tnsize, szPath); if (!ul) rc = CAMERR_NEEDDATA; } while (0); if (hFile) DosClose( hFile); if (rc && *ppBuf) { free( *ppBuf); *ppBuf = 0; } return (rc); }
// read bitmap color palette BOOL GBMReadPalette( HFILE hFile, GBM *gbm, GBMRGB *gbmrgb ) { BMP_PRIV *bmp_priv = ( BMP_PRIV * )gbm->priv; ULONG ulActual; if( gbm->bpp != 24 ) { int i; BYTE b[4]; if( bmp_priv->windows ) // OS/2 2.0 and Windows 3.0 { DosSetFilePtr( hFile, // set to beginning of palette bmp_priv->base + 14L + bmp_priv->cbFix, FILE_BEGIN, &ulActual ); for( i = 0; i < ( int )bmp_priv->cclrUsed; i++ ) // read colors { DosRead( hFile, b, 4, &ulActual ); // colors are in file as bgr ( gbmrgb + i )->Blue = *b; ( gbmrgb + i )->Green = *( b + 1 ); ( gbmrgb + i )->Red = *( b + 2 ); } } else // OS/2 1.1 and 1.2 { DosSetFilePtr( hFile, bmp_priv->base + 26L, FILE_BEGIN, &ulActual ); // set to palette start for( i = 0; i < ( 1 << gbm->bpp ); i++ ) // read colors { DosRead( hFile, b, 3, &ulActual ); // colors are in file as bgr ( gbmrgb + i )->Blue = *b; ( gbmrgb + i )->Green = *( b + 1 ); ( gbmrgb + i )->Red = *( b + 2 ); } } } return( TRUE ); }
EXPORT_FUNC Long TT_File_Pos( STREAM_ARG ) { ULONG ibActual; /* !Mike! */ #if 0 return ftell( CUR_Stream->file ) - CUR_Stream->base; /* !Mike! */ #endif DosSetFilePtr( CUR_Stream->file, 0, FILE_CURRENT, &ibActual ); return ibActual - CUR_Stream->base; }
PRInt32 _PR_MD_LSEEK(PRFileDesc *fd, PRInt32 offset, PRSeekWhence whence) { PRInt32 rv; PRUword newLocation; rv = DosSetFilePtr((HFILE)fd->secret->md.osfd, offset, whence, &newLocation); if (rv != NO_ERROR) { _PR_MD_MAP_LSEEK_ERROR(rv); return -1; } else return newLocation; }
int seek_func(void *datasource, ogg_int64_t offset, int whence) { ULONG ulMethod; ULONG ibActual; switch(whence) { case SEEK_SET: ulMethod = FILE_BEGIN; break; case SEEK_CUR: ulMethod = FILE_CURRENT; break; case SEEK_END: ulMethod = FILE_END; break; default: return 0; } DosSetFilePtr( (HFILE)datasource, (LONG)(offset & 0xffffffff), ulMethod, &ibActual ); return 0; }
EXPORT_FUNC TT_Error TT_Skip_File( STREAM_ARGS long distance ) { ULONG ibActual; /* !Mike! */ #if 0 return TT_Seek_File( STREAM_VARS ftell( CUR_Stream->file ) - CUR_Stream->base + distance ); /* !Mike! */ #endif DosSetFilePtr( CUR_Stream->file, 0, FILE_CURRENT, &ibActual ); return TT_Seek_File( STREAM_VARS ibActual - CUR_Stream->base + distance ); }
BOOL ReadPathFileEntry( BYTE Number, CHAR *Entry, BOOL NoPath ) { SDWORD Distance; CHAR ReadEntry[80]; BYTE CharNumber; CHAR *CharPointer; memset( Entry, 0, 65 ); Distance = 82 * Number; DosSetFilePtr( PathFile, &Distance, FILE_BEGIN, NULL ); DosRead( PathFile, ReadEntry, sizeof( ReadEntry ), NULL ); CharNumber = 4; CharPointer = StdStrChr( &ReadEntry[CharNumber], ' ' ); *CharPointer = 0; if( NoPath ) { strcat( Entry, &ReadEntry[CharNumber] ); return( TRUE ); } if( ReadEntry[CharNumber + 1] == ':' ) { memcpy( &Entry[0], &ReadEntry[CharNumber], 2 ); CharNumber += 2; } else { Entry[0] = ConfigData->TMSLaufWerk; Entry[1] = ':'; } if( ReadEntry[CharNumber] != '\\' ) strcat( Entry, TMSPATH ); else { Entry[2] = '\\'; CharNumber += 1; } strcat( Entry, &ReadEntry[CharNumber] ); return( TRUE ); }
FT_Error FX_Activate_Stream( FT_Face face ) { FT_ULong ulPos; FT_Error error; ulPos = face->stream->pos; if ( ! STREAM_FILE( face->stream )) { error = FT_Stream_Open( face->stream, face->stream->pathname.pointer ); if ( !error ) DosSetFilePtr( STREAM_FILE( face->stream ), ulPos, FILE_BEGIN, &(face->stream->pos)); } else error = FT_Err_Ok; return error; }
VOID ReadLine( HFILE File, CHAR *Line ) { SDWORD Distance; CHAR *LineEnd; DosRead( File, (VOID FAR *)Line, 102, NULL ); LineEnd = StdStrChr( Line, '\r' ); LineEnd[0] = 0; LineEnd[1] = 0; Distance = (SDWORD)((SDWORD)(WORD)LineEnd - (SDWORD)(WORD)Line - 102 + 2); DosSetFilePtr( File, &Distance, FILE_CURRENT, NULL ); }
/* * SeekRead - seek to a file position, and read the data */ static BOOL SeekRead( HFILE handle, ULONG newpos, void *ptr, ULONG size ) { ULONG read; ULONG pos; if( DosSetFilePtr(handle, newpos, 0, &pos) != 0 ) { return( FALSE ); } if( DosRead(handle, ptr, size, &read) != 0 ) { return( FALSE ); } if( read != size ) { return( FALSE ); } return( TRUE ); } /* SeekRead */
EXPORT_FUNC TT_Error TT_Seek_File( STREAM_ARGS long position ) { ULONG ibActual; /* !Mike! */ position += CUR_Stream->base; #if 0 if ( fseek( CUR_Stream->file, position, SEEK_SET ) ) /* !Mike! */ #endif if ( DosSetFilePtr( CUR_Stream->file, position, FILE_BEGIN , &ibActual ) ) return TT_Err_Invalid_File_Offset; return TT_Err_Ok; }
INT multiWrite(CHAR *inFile, INT datS, INT sizeF, INT recNum) { struct Samp { SHORT indx; CHAR noteName[NAMESIZE]; }sample; ULONG oneRecSize, start; CHAR noteText[NOTESIZE]; APIRET apiret; ULONG ulAction, ulBufferSize, ulBytesWritten, newP; HFILE hfile; ulBufferSize = sizeF; apiret = DosOpen(inFile, &hfile, &ulAction, ulBufferSize, FILE_NORMAL, OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYWRITE | OPEN_FLAGS_SEQUENTIAL, NULL); oneRecSize = sizeof(sample) + sizeF; start = sizeof(recIndex); DosSetFilePtr(hfile, start+(oneRecSize*(recNum)), FILE_BEGIN, &newP); if( datS == 1 ) { sample.indx = dataRecs.indx; strcpy(sample.noteName, dataRecs.noteName); DosWrite(hfile, &sample, sizeof(sample), &ulBytesWritten); DosWrite(hfile, &dataRecs.noteText, sizeF, &ulBytesWritten); } else { sample.indx = dataR.indx; strcpy(sample.noteName, dataR.noteName); DosWrite(hfile, &sample, sizeof(sample), &ulBytesWritten); DosWrite(hfile, &dataR.noteText, sizeF, &ulBytesWritten); } DosClose(hfile); return(1); }
longlong _lseek64( int fd, longlong offset, int seektype) { APIRET rc; longlong actual; if (_DosSetFilePtrL) rc = _DosSetFilePtrL( fd, offset, seektype, &actual); else { ULONG ulActual; rc = DosSetFilePtr( fd, (long) offset, seektype, &ulActual); actual = ulActual; } if (!rc) return( actual); /* NO_ERROR */ _OS2errno( rc); /* set errno */ return(-1); /* seek failed */ }
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, PHYSFS_uint32 size, PHYSFS_uint32 count) { HFILE hfile = (HFILE) opaque; PHYSFS_sint64 retval; ULONG bw; for (retval = 0; retval < count; retval++) { os2err(DosWrite(hfile, buffer, size, &bw)); if (bw < size) { DosSetFilePtr(hfile, -bw, FILE_CURRENT, &bw); /* try to cleanup. */ return(retval); } /* if */ buffer = (void *) ( ((char *) buffer) + size ); } /* for */ return(retval); } /* __PHYSFS_platformWrite */
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer, PHYSFS_uint32 size, PHYSFS_uint32 count) { HFILE hfile = (HFILE) opaque; PHYSFS_sint64 retval; ULONG br; for (retval = 0; retval < count; retval++) { os2err(DosRead(hfile, buffer, size, &br)); if (br < size) { DosSetFilePtr(hfile, -br, FILE_CURRENT, &br); /* try to cleanup. */ return(retval); } /* if */ buffer = (void *) ( ((char *) buffer) + size ); } /* for */ return(retval); } /* __PHYSFS_platformRead */
HB_ULONG hb_fsOS2DosSetFilePtrL( HB_FHANDLE hFile, HB_FOFFSET nPos, HB_ULONG method, HB_FOFFSET * pnCurPos ) { APIRET ret; if( hb_isWSeB() ) { LONGLONG llCurPos = 0; ret = s_DosSetFilePtrL( ( HFILE ) hFile, ( LONGLONG ) nPos, method, &llCurPos ); *pnCurPos = ( HB_FOFFSET ) llCurPos; } else { ULONG ulCurPos = 0; ret = DosSetFilePtr( ( HFILE ) hFile, ( LONG ) nPos, method, &ulCurPos ); *pnCurPos = ( HB_FOFFSET ) ulCurPos; } hb_fsSetError( ( HB_ERRCODE ) ret ); return ret; }
ULONG FileReadFile( HFILE hFile, char * pBuf, ULONG cbRequest, char * path) { ULONG rc; ULONG ul; ULONG ulRtn; do { ulRtn = 0; rc = DosRead( hFile, pBuf, cbRequest, &ulRtn); if (!rc && ulRtn == cbRequest) break; printf( "FileReadFile - first attempt - rc= 0x%lx request= 0x%lx read= 0x%lx\n file= %s\n", rc, cbRequest, ulRtn, path); DosSleep( 100); rc = DosSetFilePtr( hFile, -(ulRtn), FILE_CURRENT, &ul); if (rc) { printf( "FileReadFile - DosSetFilePtr - rc= 0x%lx\n", rc); ulRtn = 0; break; } ulRtn = 0; rc = DosRead( hFile, pBuf, cbRequest, &ulRtn); if (!rc && ulRtn == cbRequest) break; printf( "FileReadFile - second attempt - rc= 0x%lx request= 0x%lx read= 0x%lx\n", rc, cbRequest, ulRtn); ulRtn = 0; } while (0); return (ulRtn); }
static TT_Error Stream_Deactivate( PStream_Rec stream ) { if ( stream->opened ) { /* Save its current position within the file */ #if 0 stream->position = ftell( stream->file ); /* !Mike! */ #endif DosSetFilePtr( stream->file, 0, FILE_CURRENT, (ULONG *)&(stream->position) ); #if 0 fclose( stream->file ); /* !Mike! */ #endif DosClose( stream->file ); stream->file = 0; stream->opened = FALSE; } return TT_Err_Ok; }