]>
Commit | Line | Data |
---|---|---|
1 | /*------------------------------------------------------------/\r | |
2 | / Open or create a file in append mode\r | |
3 | / (This function was sperseded by FA_OPEN_APPEND flag at FatFs R0.12a)\r | |
4 | /------------------------------------------------------------*/\r | |
5 | \r | |
6 | FRESULT open_append (\r | |
7 | FIL* fp, /* [OUT] File object to create */\r | |
8 | const char* path /* [IN] File name to be opened */\r | |
9 | )\r | |
10 | {\r | |
11 | FRESULT fr;\r | |
12 | \r | |
13 | /* Opens an existing file. If not exist, creates a new file. */\r | |
14 | fr = f_open(fp, path, FA_WRITE | FA_OPEN_ALWAYS);\r | |
15 | if (fr == FR_OK) {\r | |
16 | /* Seek to end of the file to append data */\r | |
17 | fr = f_lseek(fp, f_size(fp));\r | |
18 | if (fr != FR_OK)\r | |
19 | f_close(fp);\r | |
20 | }\r | |
21 | return fr;\r | |
22 | }\r | |
23 | \r | |
24 | \r | |
25 | int main (void)\r | |
26 | {\r | |
27 | FRESULT fr;\r | |
28 | FATFS fs;\r | |
29 | FIL fil;\r | |
30 | \r | |
31 | /* Open or create a log file and ready to append */\r | |
32 | f_mount(&fs, "", 0);\r | |
33 | fr = open_append(&fil, "logfile.txt");\r | |
34 | if (fr != FR_OK) return 1;\r | |
35 | \r | |
36 | /* Append a line */\r | |
37 | f_printf(&fil, "%02u/%02u/%u, %2u:%02u\n", Mday, Mon, Year, Hour, Min);\r | |
38 | \r | |
39 | /* Close the file */\r | |
40 | f_close(&fil);\r | |
41 | \r | |
42 | return 0;\r | |
43 | }\r | |
44 | \r |