FatFS/documents/res/app1.c
savelij13 a6bc2e0f07 fatfs v0.13 May 21, 2017:
- Changed heading character of configuration keywords "_" to "FF_".
- Removed ASCII-only configuration, FF_CODE_PAGE = 1. Use FF_CODE_PAGE = 437 instead.
- Added f_setcp(), run-time code page configuration. (FF_CODE_PAGE = 0)
- Improved cluster allocation time on stretch a deep buried cluster chain.
- Improved processing time of f_mkdir() with large cluster size by using FF_USE_LFN = 3.
- Improved NoFatChain flag of the fragmented file to be set after it is truncated and got contiguous.
- Fixed archive attribute is left not set when a file on the exFAT volume is renamed. (appeared at R0.12)
- Fixed exFAT FAT entry can be collapsed when write or lseek operation to the existing file is done. (appeared at R0.12c)
- Fixed creating a file can fail when a new cluster allocation to the exFAT directory occures. (appeared at R0.12c)
2025-09-11 10:28:54 +03:00

45 lines
1.1 KiB
C

/*------------------------------------------------------------/
/ Open or create a file in append mode
/ (This function was sperseded by FA_OPEN_APPEND flag at FatFs R0.12a)
/------------------------------------------------------------*/
FRESULT open_append (
FIL* fp, /* [OUT] File object to create */
const char* path /* [IN] File name to be opened */
)
{
FRESULT fr;
/* Opens an existing file. If not exist, creates a new file. */
fr = f_open(fp, path, FA_WRITE | FA_OPEN_ALWAYS);
if (fr == FR_OK) {
/* Seek to end of the file to append data */
fr = f_lseek(fp, f_size(fp));
if (fr != FR_OK)
f_close(fp);
}
return fr;
}
int main (void)
{
FRESULT fr;
FATFS fs;
FIL fil;
/* Open or create a log file and ready to append */
f_mount(&fs, "", 0);
fr = open_append(&fil, "logfile.txt");
if (fr != FR_OK) return 1;
/* Append a line */
f_printf(&fil, "%02u/%02u/%u, %2u:%02u\n", Mday, Mon, Year, Hour, Min);
/* Close the file */
f_close(&fil);
return 0;
}