The C Standard identifies specific strings to use for the
mode on calls to
fopen_s(). C11 provides a new mode flag,
x, that provides the mechanism needed to determine if the file that is to be opened exists. To be strictly conforming and portable, one of the strings from the following table (adapted from the C Standard, subclause 126.96.36.199 [ISO/IEC 9899:2011]) must be used:
Strings to Use for the Mode on Calls to
Open text file for reading
Truncate to zero length or create text file for writing
Create text file for writing
Append; open or create text file for writing at end-of-file
Open binary file for reading
Truncate to zero length or create binary file for writing
Create binary file for writing
Append; open or create binary file for writing at end-of-file
Open text file for update (reading and writing)
Truncate to zero length or create text file for update
Create text file for update
Append; open or create text file for update, writing at end-of-file
Open binary file for update (reading and writing)
Truncate to zero length or create binary file for update
Create binary file for update
Append; open or create binary file for update, writing at end-of-file
mode string begins with one of these sequences, the implementation might choose to ignore the remaining characters, or it might use them to select different kinds of files.
fopen_s(), any of the mode strings used for writing (
a) may be prefixed with the
u character to give the file system default access permissions.
mode strings, but only the modes shown in the table are fully portable and C compliant. Beware that Microsoft Visual Studio 2012 and earlier do not support the
u mode characters [MSDN].
mode string that is not recognized by an implementation may cause the call to
fopen() to fail.
|LDRA tool suite|
|Polyspace Bug Finder|
|Bad file access mode or status|
Access mode argument of function in
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
|[ISO/IEC 9899:2011]||Subclause 188.8.131.52, "The |