After a file has been opened, the file handle state flags set with a DosOpen can be queried and reset by calling DosQueryFHState and DosSetFHState . The handle returned by DosSetFHState is used for subsequent input and output to the file.
The following code fragment calls DosSetFHState to set the File Write-Through flag for an opened file. Writes to the file may go through the file system buffer, but the sectors are to be written before any synchronous write call returns. DosQueryFHState is called first to obtain the file handle state bits. Assume that the appropriate file handle has been placed into FileHandle already.
#define INCL_DOSFILEMGR /* File system values */ #include <os2.h> #include <stdio.h> HFILE hfFileHandle; /* File handle */ ULONG ulFileHandleState; /* File handle state */ APIRET ulrc; /* Return code */ ulrc = DosQueryFHState(hfFileHandle, &FileHandleState); if (ulrc != 0) { printf("DosQueryFHState error: return code = %ld", ulrc); return; } ulFileHandleState |= OPEN_FLAGS_WRITE_THROUGH; ulrc = DosSetFHState(hfFileHandle, ulFileHandleState); if (ulrc != 0) { printf("DosSetFHState error: return code = %ld", ulrc); return; }
Here are two scenarios involving the use of this function.