home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / FILEIO.LIB < prev    next >
Text File  |  1994-03-08  |  5KB  |  111 lines

  1. // FileIO.lib
  2. // ver.1
  3.  
  4. DosOpen(FileName,retFileHandle,retActionTaken,FileSize,FileAttribute,
  5.         OpenFlag,OpenMode,EABuf)
  6.    // FileName: ascii string specifyin file to open
  7.    // retFileHandle: return unique file handle
  8.    // retActionTaken: return action taken on succesful open; one of these:
  9.       #define FILE_EXISTED    1  // File already existed
  10.       #define FILE_CREATED    2  // File was created
  11.       #define FILE_TRUNCATED  3  // File existed and was replaced by new file
  12.    // FileSize: should be zero unsless creating or overwriting; sets new file size
  13.    // FileAttribute: Apply only when creating file, OR of these bits:
  14.       #define FILE_NORMAL     0x00
  15.       #define FILE_READONLY   0x01
  16.       #define FILE_HIDDEN     0x02
  17.       #define FILE_SYSTEM     0x04
  18.       #define FILE_DIRECTORY  0x10
  19.       #define FILE_ARCHIVED   0x20
  20.    // OpenFlag: Action to take depending on whether file exists
  21.       #define OPEN_ACTION_FAIL_IF_EXISTS     0x00
  22.       #define OPEN_ACTION_OPEN_IF_EXISTS     0x01
  23.       #define OPEN_ACTION_REPLACE_IF_EXISTS  0x02
  24.       #define OPEN_ACTION_FAIL_IF_NEW        0x00
  25.       #define OPEN_ACTION_CREATE_IF_NEW      0x10
  26.    // OpenMode: OR of following flags
  27.       #define OPEN_ACCESS_READONLY           0x0000   // Read only for this process
  28.       #define OPEN_ACCESS_WRITEONLY          0x0001   // Write-only for this process
  29.       #define OPEN_ACCESS_READWRITE          0x0002   // Read and write access for this process
  30.       #define OPEN_SHARE_DENYREADWRITE       0x0010   // Deny read/write access to other process
  31.       #define OPEN_SHARE_DENYWRITE           0x0020   // Deny write access to other process
  32.       #define OPEN_SHARE_DENYREAD            0x0030   // Deny read access to other process
  33.       #define OPEN_SHARE_DENYNONE            0x0040   // Deny neither read nor write to other processes
  34.       #define OPEN_FLAGS_NOINHERIT           0x0080   // file handle private to current process
  35.       #define OPEN_FLAGS_NO_LOCALITY         0x0000   // No locality known
  36.       #define OPEN_FLAGS_SEQUENTIAL          0x0100   // Mainly sequential access
  37.       #define OPEN_FLAGS_RANDOM              0x0200   // Mainly random access
  38.       #define OPEN_FLAGS_RANDOMSEQUENTIAL    0x0300   // Random with some locality
  39.       #define OPEN_FLAGS_NO_CACHE            0x1000   // don't cache data IO
  40.       #define OPEN_FLAGS_FAIL_ON_ERROR       0x2000   // report to caller, not trhough system critical handler
  41.       #define OPEN_FLAGS_WRITE_THROUGH       0x4000   // write before synchronous write returns
  42.       #define OPEN_FLAGS_DASD                0x8000   // filename is a drive (e.g. C:)
  43.       #define OPEN_FLAGS_NONSPOOLED          0x40000
  44.    // EABuf: Read and write extended attrib buffer to this blob if not NULL
  45.    // Return: 0 if no error, else error code
  46. {
  47.    #define ORD_DOS32OPEN   273
  48.    rc = DynamicLink("doscalls",ORD_DOS32OPEN,BIT32,CDECL,
  49.                     FileName,_doFileHandle,_doActionTaken,FileSize,FileAttribute,
  50.                     OpenFlag,OpenMode,EABuf);
  51.    if ( 0 == rc ) {
  52.       retFileHandle = _doFileHandle;
  53.       retActionTaken = _doActionTaken;
  54.    }
  55.    return(rc);
  56. }
  57.  
  58.  
  59. DosClose(FileHandle)
  60.    // FileHandle: previous value returned from
  61.    // Return: 0 if no error, else error code
  62. {
  63.    #define ORD_DOS32CLOSE  257
  64.    return DynamicLink("doscalls",ORD_DOS32CLOSE,BIT32,CDECL,FileHandle);
  65. }
  66.  
  67. DosRead(FileHandle,BufferArea,BufferLength,BytesRead)
  68.    // FileHandle: previous value returned from
  69.    // BufferArea: where to read to; this will make sure it's big enough
  70.    // BufferLength: maximum size of buffer area to read to
  71.    // BytesRead: Return number of bytes read
  72.    // Return: 0 if no error, else error code
  73. {
  74.    if ( BufferLength < 1 ) {
  75.       BytesRead = 0;
  76.       _ret = 0;
  77.    } else {
  78.       // Make sure that BufferArea is big enough
  79.       if ( !defined(BufferArea)  ||  BLObSize(BufferArea) < BufferLength )
  80.          BLObSize(BufferArea,BufferLength);
  81.  
  82.       #define ORD_DOS32READ   281
  83.       BLObPut(_BytesRead,0,0,UWORD32);
  84.       _ret = DynamicLink("doscalls",ORD_DOS32READ,BIT32,CDECL,
  85.                          FileHandle,BufferArea,BufferLength,_BytesRead);
  86.       BytesRead = BLObGet(_BytesRead,0,UWORD32);
  87.    }
  88.    return _ret;
  89. }
  90.  
  91. DosWrite(FileHandle,BufferArea,BufferLength,BytesWritten)
  92.    // FileHandle: previous value returned from
  93.    // BufferArea: where to read bytes from
  94.    // BufferLength: how many bytes to write
  95.    // BytesRead: Return number of bytes actually written
  96.    // Return: 0 if no error, else error code
  97. {
  98.    if ( BufferLength < 1 ) {
  99.       BytesWritten = 0;
  100.       _ret = 0;
  101.    } else {
  102.       #define ORD_DOS32WRITE  282
  103.       BLObPut(_BytesWritten,0,0,UWORD32);
  104.       _ret = DynamicLink("doscalls",ORD_DOS32WRITE,BIT32,CDECL,
  105.                          FileHandle,BufferArea,BufferLength,_BytesWritten);
  106.       BytesWritten = BLObGet(_BytesWritten,0,UWORD32);
  107.    }
  108.    return _ret;
  109. }
  110.  
  111.