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