Home | Previous Page | Next Page   Function Descriptions >

mi_file_open( )

The mi_file_open( ) function opens an operating-system file.

Syntax

mi_integer mi_file_open(filename, open_flags, open_mode)
   const char *filename;
   mi_integer open_flags;
   mi_integer open_mode;
filename
is the pathname of the file to open.
open_flags
is a value bit mask that can have any of the following values:

open flags that the operating-system open command supports: UNIX or Linux open(2) or Windows _open.

MI_O_SERVER_FILE
(default)
indicates that the file to open is on the server computer.
MI_O_CLIENT_FILE
indicates that the file to open is on the client computer. When you set this flag, you also need to include the appropriate file-mode flag values, as described later in this section.
open_mode
is the file-permission mode in a format that the operating-system open command supports: UNIX or Linux open(2) or Windows _open.
Valid in Client LIBMI Application? Valid in User-Defined Routine?
Yes Yes

Usage

The mi_file_open( ) function opens the filename file in the access mode that open_flags specifies and the open mode that open_mode specifies. The function returns an integer file descriptor to this open file, through which you can access an operating-system file. The mi_file_open( ) function is the constructor function for a file descriptor. The mi_file_open( ) function allocates a new file descriptor for the duration of the client session.

The file ownership (owner and permissions) that open_mode specifies must be compatible with what open_flags specifies and what the operating-system open command supports.

Server Only

From a C UDR, mi_file_open( ) can access files on the server computer. The function uses the user and group identifier of the session user to open the file. The function assumes the file ownership of the server environment.

End of Server Only
Client Only

In a client LIBMI application, mi_file_open( ) assumes the file ownership of the application user.

End of Client Only

You can include environment variables in the filename path with the following syntax:

$ENV_VAR

This environment variable must be set in the server environment; that is, it must be set before the database server starts.

The open_flags argument contains two pieces of information:

For opening client files, the mi_file_open( ) function passes the open_flags argument to the underlying operating-system call that opens a file. These flags are translated to appropriate operating-system flags on the client side. (Therefore, the open_flags values must match those that your operating-system call supports.)

The file-mode flag values for the open_flags argument indicate the access modes of the file.

Client Only

Valid values for client files include the following file-mode constants. When MI_O_CLIENT_FILE is specified, you must an MI_* flag.

File-Mode Constant
Purpose
MI_O_EXCL
Open the file only if fname_spec does not exist. Raise an exception if fname_spec does exist.
MI_O_TRUNC
Truncate the file, if it already exists.
MI_O_APPEND
Append to the file, if it already exists.
MI_O_RDONLY
Open the file in read-only mode (from_open_mode only).
MI_O_RDWR
Open the file in read/write mode.
MI_O_WRONLY
Open the file in write-only mode (to_open_mode only).
MI_O_BINARY
Process the data as binary data (to_open_mode only).
MI_O_TEXT
Process the data as text data (not binary, which is used if you do not specify MI_O_TEXT).
End of Client Only
Server Only

The default for the mi_file_open( ) function is to open the file on the server. The file mode is read/write for all users. The file owner is the client user ID. Valid values for the open_flags argument for opening server files include the following file-mode constants.

File-Mode Constant
Purpose
O_EXCL
Open the file only if fname_spec does not exist. Raise an exception if fname_spec does exist.
O_TRUNC
Truncate the file, if it already exists.
O_APPEND
Append to the file, if it already exists.
O_RDONLY
Open the file in read-only mode (from_open_mode only).
O_RDWR
Open the file in read/write mode.
O_WRONLY
Open the file in write-only mode (to_open_mode only).
O_CREAT
Create the file, if the file does not exist.

For a complete list of open( ) system calls, consult the man pages (UNIX) for your computer's operating system.

End of Server Only

Return Values

>=0
is the file descriptor for the file that mi_file_open( ) has opened.
MI_ERROR
indicates that the function was not successful.

The mi_file_open( ) function does not throw an MI_Exception event when it encounters a runtime error. Therefore, it does not cause callbacks to be invoked.

Related Topics

See also the descriptions of mi_file_allocate( ) and mi_file_close( ) and the IBM Informix: DataBlade API Programmer's Guide.

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]