Access to operating-system files
The provides file-access functions for access to operating-system files from within a C UDR. These functions provide file management that is similar to what operating-system file-access functions provide.
The file-access
functions call the corresponding operating-system functions to perform
their tasks; however, the functions
periodically yield the virtual processor to limit the effects of blocking
I/O.
Restriction: Do not call operating-system file I/O
functions from within a C UDR. Use these file-access
functions instead because they are safer in a C UDR than their operating-system
equivalents. For more information, see Avoid blocking I/O calls.
The following table lists the functions
for the basic file-access operations and the analogous operating-system
calls for these operations.
| File-access operation | File-access function | Operating-system call |
|---|---|---|
| Open an operating-system file and generate a file descriptor for the file | mi_file_open() | open() |
| Seek to a specified position to begin a read or write operation on a file up to 2Gb. | mi_file_seek() | seek() |
| Seek to a specified position to begin a read or write operation on a file greater than 2Gb. | mi_file_seek8() | seek8() |
| Obtain the current seek position on a file up to 2 GB. | mi_file_tell() | tell() |
| Obtain the current seek position on a file greater that 2 GB. | mi_file_tell8() | tell8() |
| Perform a read or write operation for a specified number of bytes | mi_file_read(), mi_file_write() | read(), write() |
| Obtain status information about a specified smart large object | mi_file_sync() | sync() |
| Close an operating-system file and deallocate the file descriptor | mi_file_close() | close() |
| Unlink (remove) an operating-system file | mi_file_unlink() | unlink() |
| Obtain an errno value for the file operation | mi_file_errno() | GLOBAL INT ERRNO; |
Tip: The file-access
functions execute in client LIBMI applications as well as C UDRs.
For modules
that you design to run in both client LIBMI applications and UDRs,
use these file-access functions. For information about the behavior
of these functions in a client LIBMI application, see Write a client LIBMI application.
The accesses
operating-system files through file descriptors. These file descriptors
are similar in purpose to operating-system file descriptors. The following
table summarizes the memory durations for a file descriptor.
| Memory duration | Memory operation | Function name |
|---|---|---|
| Duration of session (PER_SESSION) | Constructor | mi_file_open() |
| Duration of session (PER_SESSION) | Destructor | mi_file_close(), mi_file_unlink() |