home *** CD-ROM | disk | FTP | other *** search
- // FileIO.lib
- // ver.1
-
- DosOpen(FileName,retFileHandle,retActionTaken,FileSize,FileAttribute,
- OpenFlag,OpenMode,EABuf)
- // FileName: ascii string specifyin file to open
- // retFileHandle: return unique file handle
- // retActionTaken: return action taken on succesful open; one of these:
- #define FILE_EXISTED 1 // File already existed
- #define FILE_CREATED 2 // File was created
- #define FILE_TRUNCATED 3 // File existed and was replaced by new file
- // FileSize: should be zero unsless creating or overwriting; sets new file size
- // FileAttribute: Apply only when creating file, OR of these bits:
- #define FILE_NORMAL 0x00
- #define FILE_READONLY 0x01
- #define FILE_HIDDEN 0x02
- #define FILE_SYSTEM 0x04
- #define FILE_DIRECTORY 0x10
- #define FILE_ARCHIVED 0x20
- // OpenFlag: Action to take depending on whether file exists
- #define OPEN_ACTION_FAIL_IF_EXISTS 0x00
- #define OPEN_ACTION_OPEN_IF_EXISTS 0x01
- #define OPEN_ACTION_REPLACE_IF_EXISTS 0x02
- #define OPEN_ACTION_FAIL_IF_NEW 0x00
- #define OPEN_ACTION_CREATE_IF_NEW 0x10
- // OpenMode: OR of following flags
- #define OPEN_ACCESS_READONLY 0x0000 // Read only for this process
- #define OPEN_ACCESS_WRITEONLY 0x0001 // Write-only for this process
- #define OPEN_ACCESS_READWRITE 0x0002 // Read and write access for this process
- #define OPEN_SHARE_DENYREADWRITE 0x0010 // Deny read/write access to other process
- #define OPEN_SHARE_DENYWRITE 0x0020 // Deny write access to other process
- #define OPEN_SHARE_DENYREAD 0x0030 // Deny read access to other process
- #define OPEN_SHARE_DENYNONE 0x0040 // Deny neither read nor write to other processes
- #define OPEN_FLAGS_NOINHERIT 0x0080 // file handle private to current process
- #define OPEN_FLAGS_NO_LOCALITY 0x0000 // No locality known
- #define OPEN_FLAGS_SEQUENTIAL 0x0100 // Mainly sequential access
- #define OPEN_FLAGS_RANDOM 0x0200 // Mainly random access
- #define OPEN_FLAGS_RANDOMSEQUENTIAL 0x0300 // Random with some locality
- #define OPEN_FLAGS_NO_CACHE 0x1000 // don't cache data IO
- #define OPEN_FLAGS_FAIL_ON_ERROR 0x2000 // report to caller, not trhough system critical handler
- #define OPEN_FLAGS_WRITE_THROUGH 0x4000 // write before synchronous write returns
- #define OPEN_FLAGS_DASD 0x8000 // filename is a drive (e.g. C:)
- #define OPEN_FLAGS_NONSPOOLED 0x40000
- // EABuf: Read and write extended attrib buffer to this blob if not NULL
- // Return: 0 if no error, else error code
- {
- #define ORD_DOS32OPEN 273
- rc = DynamicLink("doscalls",ORD_DOS32OPEN,BIT32,CDECL,
- FileName,_doFileHandle,_doActionTaken,FileSize,FileAttribute,
- OpenFlag,OpenMode,EABuf);
- if ( 0 == rc ) {
- retFileHandle = _doFileHandle;
- retActionTaken = _doActionTaken;
- }
- return(rc);
- }
-
-
- DosClose(FileHandle)
- // FileHandle: previous value returned from
- // Return: 0 if no error, else error code
- {
- #define ORD_DOS32CLOSE 257
- return DynamicLink("doscalls",ORD_DOS32CLOSE,BIT32,CDECL,FileHandle);
- }
-
- DosRead(FileHandle,BufferArea,BufferLength,BytesRead)
- // FileHandle: previous value returned from
- // BufferArea: where to read to; this will make sure it's big enough
- // BufferLength: maximum size of buffer area to read to
- // BytesRead: Return number of bytes read
- // Return: 0 if no error, else error code
- {
- if ( BufferLength < 1 ) {
- BytesRead = 0;
- _ret = 0;
- } else {
- // Make sure that BufferArea is big enough
- if ( !defined(BufferArea) || BLObSize(BufferArea) < BufferLength )
- BLObSize(BufferArea,BufferLength);
-
- #define ORD_DOS32READ 281
- BLObPut(_BytesRead,0,0,UWORD32);
- _ret = DynamicLink("doscalls",ORD_DOS32READ,BIT32,CDECL,
- FileHandle,BufferArea,BufferLength,_BytesRead);
- BytesRead = BLObGet(_BytesRead,0,UWORD32);
- }
- return _ret;
- }
-
- DosWrite(FileHandle,BufferArea,BufferLength,BytesWritten)
- // FileHandle: previous value returned from
- // BufferArea: where to read bytes from
- // BufferLength: how many bytes to write
- // BytesRead: Return number of bytes actually written
- // Return: 0 if no error, else error code
- {
- if ( BufferLength < 1 ) {
- BytesWritten = 0;
- _ret = 0;
- } else {
- #define ORD_DOS32WRITE 282
- BLObPut(_BytesWritten,0,0,UWORD32);
- _ret = DynamicLink("doscalls",ORD_DOS32WRITE,BIT32,CDECL,
- FileHandle,BufferArea,BufferLength,_BytesWritten);
- BytesWritten = BLObGet(_BytesWritten,0,UWORD32);
- }
- return _ret;
- }
-