Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

When an application needs to access a file, it must first open it using fs_fopen() or FSFile_Open(). For most applications, the former with its familiar interface suffices. In some cases, the flexibility of the latter is demanded (see Listing - Example FSFile_Open() usage).

Anchor
Listing - Example FSFile_Open() usage
Listing - Example FSFile_Open() usage

Code Block
languagecpp
titleListing - Example FSFile_Open() usage
file ptr --> p_file = FSFile_Open ("\\file.txt",             /* file name    */
                                    FS_FILE_ACCESS_MODE_RD,  /* access mode  */
                                   &err);                    /* return error */
       if (p_file == (FS_FILE *)0) {
         /* $$$$ Handle error */
       }


The return value of FSFile_Open() should always be verified as non-NULL before the application proceeds to access the file. The second argument to this function is a logical OR of mode flags:

...

It is impossible to do this in a single, atomic operation using fs_fopen().

The table below lists Table - fopen() mode strings and mode equivalents lists the mode flag equivalents of the fs_fopen() mode strings.

Panel
borderWidth0
titleTable - fopen() mode strings and mode equivalents


“r” or “rb”

FS_FILE_ACCESS_MODE_RD

“w” or “wb”

FS_FILE_ACCESS_MODE_WR
FS_FILE_ACCESS_MODE_CREATE
FS_FILE_ACCESS_MODE_TRUNC

“a” or “ab”

FS_FILE_ACCESS_MODE_WR
FS_FILE_ACCESS_MODE_CREATE
FS_FILE_ACCESS_MODE_APPEND

“r+” or “rb+” or “r+b”

FS_FILE_ACCESS_MODE_RD
FS_FILE_ACCESS_MODE_WR

“w+” or “wb+” or “w+b”

FS_FILE_ACCESS_MODE_RD
FS_FILE_ACCESS_MODE_WR
FS_FILE_ACCESS_MODE_CREATE FS_FILE_ACCESS_MODE_TRUNC

“a+” or “ab+” or “a+b”

FS_FILE_ACCESS_MODE_RD
FS_FILE_ACCESS_MODE_WR
FS_FILE_ACCESS_MODE_CREATE
FS_FILE_ACCESS_MODE_APPEND