M2M_T_FS_HANDLE m2m_fs_open(CHAR *filename, INT32 mode)
Description: the function opens the file using the given path/filename, and mode. It returns the file handle. The function does not create the required directory if missing. See m2m_fs_create(...) to create the directories.
Parameters:
filename: pointer to the zero-terminated
string containing the file name and path if it is already
existing.
mode: open mode, see table below:
OPEN MODE |
INITIAL CONDITIONS: The file must exist, if it does not exist à Error: M2M_F_ERR_NOTFOUND |
M2M_FS_OPEN_READ |
- For Reading: - After opening, the reading starts from the first character of the file. - File data pointer can be moved to perform reading from the selected file position. The file data pointer must not point to the last file character, if reading is tried à Error: M2M_F_ERR_ UNKNOWN.
- No Writing: - If writing is tried à Error: M2M_F_ERR_NOTOPEN
|
M2M_FS_OPEN_MODIFY |
- For Reading: - After opening, the reading starts from the first character of the file. - File data pointer can be moved to perform reading from the selected file position. The file data pointer must not point to the last file character, if reading is tried à Error: M2M_F_ERR_ UNKNOWN
- For Writing: - After opening, the writing start from the
beginning of the file. The writing puts new - File data pointer can be moved to perform writing
on existing characters starting
|
OPEN MODE |
INITIAL CONDITIONS: Creates the file if it does not exist. If the file exists, appends or puts new characters on the old ones |
M2M_FS_OPEN_APPEND |
- For Writing: - After opening, the writing starts from the end of the file (self-seek to the EOF). - File data pointer can be moved to perform writing
on existing characters starting
- No Reading: - If reading is tried àError: M2M_F_ERR_NOTOPEN
|
OPEN MODE |
INITIAL CONDITIONS: Creates the file if it does not exist. If the file exists, truncates it to ‘0’ bytes. |
M2M_FS_OPEN_WRITE M2M_FS_OPEN_CREATE |
- For Writing: - After opening, allows consecutive writings in
append mode (self-seek to the EOF) - File data pointer can be moved to perform writing
on existing characters starting
- No Reading: - If reading is tried àError: M2M_F_ERR_NOTOPEN, regardless of the
position of
|
M2M_FS_OPEN_TRUNCATE |
- For Writing: - After opening, allows consecutive writings in
append mode (self-seek to the EOF) - File data pointer can be moved to perform writing
on existing characters starting
- For Reading: - File data pointer can be moved to perform
reading. The file data pointer must not
|
Return value:
on success:
pointer to the file handle
on failure: NULL
NOTE: m2m_fs_last_error function returns the failure reason.
Examples: 19.1.1 Open and Close