diff options
author | Leo C | 2016-09-08 19:15:27 +0200 |
---|---|---|
committer | Leo C | 2016-09-08 19:15:27 +0200 |
commit | 70702af1370e44e32fb2c3c507e4759a187b4fe5 (patch) | |
tree | 5b75a408efadf5fccd8d5d481e91cce73a86897b /fatfs/doc/res/app1.c | |
parent | 7b78a5a287827db9e9b16286f3604aef69b37c5c (diff) | |
download | z180-stamp-70702af1370e44e32fb2c3c507e4759a187b4fe5.zip |
Import fatfs R0.12bfatfs-0.12b
Diffstat (limited to 'fatfs/doc/res/app1.c')
-rw-r--r-- | fatfs/doc/res/app1.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/fatfs/doc/res/app1.c b/fatfs/doc/res/app1.c new file mode 100644 index 0000000..85ce9e2 --- /dev/null +++ b/fatfs/doc/res/app1.c @@ -0,0 +1,44 @@ +/*------------------------------------------------------------/
+/ Open or create a file in append mode
+/ (This function was sperseded by FA_OPEN_APPEND 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;
+}
+
|