#include <stdio.h>
FILE* fopen (
const char* filename, /* file to open */
const char* mode); /* type of access */
Description
The function fopen opens a file for reading or writing. The
parameter filename is a pointer defining the file
to open. The parameter mode is a pointer defining
the access type.
The function is included in the library RL-FlashFS. The prototype
is defined in the file stdio.h.
filename can include a path. If the path does
not exist, all subfolders are created. filename
can have the following prefixes:
Drive Prefix
Description
""
Default Drive system as defined in the file
Config_File.c.
"F:" or "F0:"
Flash drive
"S:" or "S0:"
SPI Flash drive
"R:" or "R0:"
RAM drive
"M:" or "M0:"
Memory Card drive 0
"M1:"
Memory Card drive 1
"U:" or "U0:"
USB Flash drive 0
"U1:"
USB Flash drive 1
"N:" or "N0:"
NAND Flash drive 0
"N1:"
NAND Flash drive 1
The parameter mode can have the following
values:
Mode
Description
"r"
Read mode. Opens a file for reading.
"w"
Write mode. Opens an empty file for writing. If
the file exists, the content is destroyed. If the file does not
exist, an empty file is opened for writing.
"a"
Append mode. Opens a file for appending text. If
the file already exists, data is appended. If the file does not
exist, an empty file is opened for writing. Opening a file with
append mode causes all subsequent writes to be placed at the then
current end-of-file, regardless of interfering calls to
fseek().
"b"
Binary mode. Can be appended to any character
above, but has no effect. The character is allowed for ISO C
standard conformance.
"+"
Update mode. Can be used with any character above
as a second or third character. When a file is opened with update
mode, both reading and writing can be performed. Programmers must
ensure that reading is not directly followed by writing without
an interfering call to fflush() or to a file
positioning function ( fseek() or
rewind()). Also, writing should not be followed
directly by reading without an interfering call to a file
positioning function, unless the writing operation encounters
EOF.
note
File update modes are only supported on FAT file
system!
#include <rtl.h>
#include <stdio.h>
void tst_fopen (void) {
FILE *f;
f = fopen ("Test.txt","r"); /* Open a file from default drive. */
if (f == NULL) {
printf ("File not found!\n");
}
else {
// process file content
fclose (f);
}
f = fopen ("M:\\Temp_Files\\Dump_file.log","w"); /* Create a file in subfolder on SD card.*/
if (f == NULL) {
printf ("Failed to create a file!\n");
}
else {
// write data to file
fclose (f);
}
}
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers of your data.