summaryrefslogtreecommitdiff
path: root/fatfs/doc/img/app1.c
diff options
context:
space:
mode:
authorLeo C2014-08-19 15:35:51 +0200
committerLeo C2014-08-19 15:35:51 +0200
commit4bc81323e51ac138e733c14eeb6f283ae706e904 (patch)
treebcbfa6e9483998fd03953a9719eee8d7813adfb2 /fatfs/doc/img/app1.c
parentdfe91b60ea6c3184dcf3ce7310b2824890ce1b1a (diff)
parent5366852335044c1e68a5c32548d3051cc943552f (diff)
downloadz180-stamp-4bc81323e51ac138e733c14eeb6f283ae706e904.zip
Merge tag 'fatfs-0.10b'
Diffstat (limited to 'fatfs/doc/img/app1.c')
-rw-r--r--fatfs/doc/img/app1.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/fatfs/doc/img/app1.c b/fatfs/doc/img/app1.c
new file mode 100644
index 0000000..c7e690b
--- /dev/null
+++ b/fatfs/doc/img/app1.c
@@ -0,0 +1,43 @@
+/*------------------------------------------------------------/
+/ Open or create a file in append mode
+/------------------------------------------------------------*/
+
+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;
+}
+