To perform I/O operations on a new or existing file, an application must first establish a connection by calling the mmioOpen function. This returns a file handle, which identifies the open file when calling other file I/O functions. Specify the pmmioinfo parameter to identify a pointer to a caller-provided MMIOINFO block containing extra parameters used by mmioOpen. pmmioinfo may be NULL if the default values of the fields of pmmioinfo are sufficient. By specifying an MMIOINFO structure, you can open a memory file, specify a file format I/O procedure, supply a buffer, or specify data transfers in a standard presentation format. For basic file I/O services, set pmmioinfo to NULL. For example, the following code sample shows how to open a data file without a buffer.
hmmio = mmioOpen("filename.ext", NULL, 0);
Basic options for mmioOpen are shown in the following table.
┌──────────────────────────────┬──────────────────────────────┐ │Flag │Description │ ├──────────────────────────────┼──────────────────────────────┤ │MMIO_ALLOCBUF │System allocates an internal │ │ │I/O buffer. │ ├──────────────────────────────┼──────────────────────────────┤ │MMIO_APPEND │Allows appending to the end of│ │ │a file. │ ├──────────────────────────────┼──────────────────────────────┤ │MMIO_BUFSHARED │Uses shared memory if MMIO │ │ │allocates an I/O buffer. │ ├──────────────────────────────┼──────────────────────────────┤ │MMIO_CREATE │Creates a new file. │ ├──────────────────────────────┼──────────────────────────────┤ │MMIO_DELETE │Deletes the file if it already│ │ │exists. │ ├──────────────────────────────┼──────────────────────────────┤ │MMIO_NOIDENTIFY │Does not attempt to identify │ │ │the file type. │ ├──────────────────────────────┼──────────────────────────────┤ │MMIO_READ │Opens a file for reading only │ │ │(default). │ ├──────────────────────────────┼──────────────────────────────┤ │MMIO_READWRITE │Opens a file for both reading │ │ │and writing. │ ├──────────────────────────────┼──────────────────────────────┤ │MMIO_VERTBAR │Uses the vertical bar │ │ │character (|) as a file │ │ │separator character rather │ │ │than the plus sign (+). │ ├──────────────────────────────┼──────────────────────────────┤ │MMIO_WRITE │Opens a file for writing only.│ └──────────────────────────────┴──────────────────────────────┘
The following example creates a new file named NEW.TXT and opens it for writing:
hmmio = mmioOpen("NEW.TXT", NULL, MMIO_CREATE | MMIO_WRITE);
You can also use mmioOpen to specify sharing options for data files. These options enable DOS files to be opened and accessed by more than one process, allowing an application to take advantage of the multi-processing feature of the OS/2 operating system.
Sharing options for data files are shown in the following table.
┌───────────────┬─────────────────────────────────────────────┐ │Flag │Description │ ├───────────────┼─────────────────────────────────────────────┤ │MMIO_DENYNONE │Opens a file without denying other processes │ │ │read or write access to the file. │ ├───────────────┼─────────────────────────────────────────────┤ │MMIO_DENYREAD │Opens a file and denies other processes read │ │ │access to the file. │ ├───────────────┼─────────────────────────────────────────────┤ │MMIO_DENYWRITE │Opens a file and denies other processes write│ │ │access to the file. │ ├───────────────┼─────────────────────────────────────────────┤ │MMIO_EXCLUSIVE │Opens a file with exclusive mode, denying │ │ │other processes both read and write access to│ │ │the file. │ └───────────────┴─────────────────────────────────────────────┘