fflush has no use?

Rui Zhengxin ruizx at qq.com
Thu Nov 7 03:56:31 UTC 2013

Hi all,
In my application, I need a log file stored on hard disk to record some log messages.
The file pointer of the log file is opened by fopen, and we keep it opening.
When a new log messages coming, I use the fprintf to write it.
In order to update the connent of hard disk, 
the "fflush" function is used to flush buffered file output.

But unfortunately, **"fflush" seems have no use.**

The test code is like this.
 FILE *fp;
 int i;
 fp = fopen("/mnt/log.txt", "a+");
 for (i=0; i<10; i++)
  fprintf(fp, "test fflush %d\n", i);
  if (fflush(fp)!= EOF)
   printf("%d ok!\n", i);
   printf("%d bad!\n", i);
When the above code is executed, 
the console output is always print ok, fflush returns good.

But when restart the board,
then use "cat" command to display the log file, it has nothins.
The length of the log file is zero too.

[/mnt] # ls -l
total 7973
-rw-r--r--  1 root  root  1767821 Jan  1 00:03 hello.exe
-rw-r--r--  1 root  root        0 Jan  1 00:08 log.txt

We also find that if we use "cat" command after fflush, the file content can be stored.

If the fflush function in RTEMS is fully implemented or not? 

Thanks & Best regards,
Rui Zhengxin

More information about the users mailing list