mco_open_file

This function opens a file

Prototype

            mco_file_h mco_open_file(
                /* IN */ char const* file_path,
                /* IN */ int flags,
                /* IN */ mco_db_params_t* db_params,
                /* IN */ mco_db_h con
            );

Arguments

file_path
The path to the file to open.
flags
A bitwise combination (OR) of the following flags:
  • MCO_FILE_OPEN_DEFAULT
  • MCO_FILE_OPEN_READ_ONLY
  • MCO_FILE_OPEN_TRUNCATE
  • MCO_FILE_OPEN_NO_BUFFERING
  • MCO_FILE_OPEN_EXISTING
  • MCO_FILE_OPEN_TEMPORARY
  • MCO_FILE_OPEN_FSYNC_FIX
  • MCO_FILE_OPEN_SUBPARTITION
  • MCO_FILE_OPEN_FSYNC_AIO_BARRIER
  • MCO_FILE_OPEN_COMPRESSED
  • MCO_FILE_OPEN_LOCK
  • MCO_FILE_OPEN_NO_READ_BUFFERING
  • MCO_FILE_OPEN_NO_WRITE_BUFFERING
Detailed descriptions of all file open flags are available here.
db_params
A pointer to a database parameters structure (typically NULL).
con
A pointer to a connection handle (typically NULL).

Description

Opens a file with the specified path. The behavior is controlled by a set of bitwise flags that define options such as read-only access, truncation, buffering, compression, and file locking. This function returns a file handle that can be used in subsequent I/O operations.

Return Value

On success, returns a non-NULL mco_file_h handle representing the opened file. On failure (e.g., file not found, permission denied), returns NULL.

Example

        ...
        /* Open a file for writing, truncating it if it exists */
        mco_file_h f = mco_open_file(file_path, MCO_FILE_OPEN_TRUNCATE, 0, 0);
        if (f == NULL) {
            return (MCO_RET)MCO_E_DISK_OPEN;
        }
        ...
        /* ... use the file handle ... */
        ...
        if (f->close(f) != 0 && ret == MCO_S_OK) {
            ret = (MCO_RET)MCO_E_DISK_CLOSE;
        }

Notes

eXtremeDB/rt defines a macro with the same name that calls the function mco_open_file_rt()

Files

Header file:
mco.h
Source file:
Platform-dependent
Library:
libmcolib.a