From bd33d37bc49d549357d987ab34aadfd0159b411e Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 15 Aug 2022 18:58:55 -0400 Subject: [PATCH] =?UTF-8?q?=E8=AF=A5=E9=97=AE=E9=A2=98=E5=9C=A8Keil-MDK?= =?UTF-8?q?=E4=B8=AD=E6=B2=A1=E6=9C=89=E4=B8=80=E4=B8=AA=E5=A4=AA=E5=A5=BD?= =?UTF-8?q?=E7=9A=84=E8=A7=A3=E5=86=B3=E6=96=B9=E6=A1=88=E3=80=82=E6=9C=AC?= =?UTF-8?q?PR=E4=B8=BA=E6=9D=83=E8=A1=A1=E5=88=A9=E5=BC=8A=E4=B9=8B?= =?UTF-8?q?=E5=90=8E=E5=BE=97=E5=88=B0=E7=9A=84=E4=B8=80=E5=A5=97=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E6=96=B9=E6=A1=88=E3=80=82Keil=E6=9B=BE=E7=BB=8F?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E4=BA=86=E5=BA=95=E5=B1=82=E6=A1=A9=E5=87=BD?= =?UTF-8?q?=E6=95=B0=5Fsys=5Fensure=EF=BC=8C=E4=BD=86=E6=98=AF=E7=9B=AE?= =?UTF-8?q?=E5=89=8D=E5=B7=B2=E7=BB=8F=E8=A2=AB=E5=BA=9F=E5=BC=83=E3=80=82?= =?UTF-8?q?=E5=9B=A0=E6=AD=A4=E5=94=AF=E4=B8=80=E7=9A=84=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E6=96=B9=E6=A1=88=E5=B0=B1=E6=98=AF=E6=AF=8F=E5=86=99=E5=AE=8C?= =?UTF-8?q?=E4=B8=80=E5=8F=A5=EF=BC=8C=E5=B0=B1=E8=B0=83=E7=94=A8fsync?= =?UTF-8?q?=E5=8E=BB=E5=90=8C=E6=AD=A5=E4=B8=80=E6=AC=A1=E3=80=82=20?= =?UTF-8?q?=E8=AF=A5=E9=97=AE=E9=A2=98=E5=9C=A8mbedos=E7=A4=BE=E5=8C=BA?= =?UTF-8?q?=E4=B9=9F=E8=BF=9B=E8=A1=8C=E8=BF=87=E8=AE=A8=E8=AE=BA=EF=BC=8C?= =?UTF-8?q?=E4=BB=96=E4=BB=AC=E4=B9=9F=E9=9D=A2=E4=B8=B4=E5=92=8C=E6=88=91?= =?UTF-8?q?=E4=BB=AC=E7=9B=B8=E5=90=8C=E7=9A=84=E4=B8=A4=E4=B8=AA=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9A=201.=20Keil-MDK=E6=97=A0=E6=9C=89=E6=95=88?= =?UTF-8?q?=E7=9A=84fflush=E8=A7=A3=E5=86=B3=E6=96=B9=E6=A1=88=EF=BC=8Cmbe?= =?UTF-8?q?dos=E4=BE=9D=E7=84=B6=E5=9C=A8=E4=BD=BF=E7=94=A8=E6=B7=98?= =?UTF-8?q?=E6=B1=B0=E7=9A=84=5Fsys=5Fensure=E6=A1=A9=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E3=80=82=202.=20Keil-MDK=E6=B2=A1=E6=9C=89fileno=E5=87=BD?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E6=88=91=E6=96=B9=E5=B0=91=E9=83=A8=E5=88=86?= =?UTF-8?q?=E8=BD=AF=E4=BB=B6=E5=8C=85=E5=9B=A0=E6=AD=A4=E8=80=8C=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E4=BD=BF=E7=94=A8Keil=E5=B9=B3=E5=8F=B0=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E3=80=82=20=E5=8F=82=E8=80=83=EF=BC=9Ahttps://github.?= =?UTF-8?q?com/ARMmbed/mbed-os/issues/1601?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit issue: https://github.com/RT-Thread/rt-thread/issues/4928 经过进一步测试发现,Keil-MDK中的fflush函数已经退化成服务于STDOUT的函数,Keil-MDK内部有一个buffer可以存放fputc(stdout) 发过来的数据,如果调用fflush,这些数据是可以flush出去的。但是如果是真正的文件数据,fflush函数并没有提供任何桩函数接口可以让文件flush数据出去。 --- components/libc/compilers/armlibc/syscalls.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index bef92599d6..2c53310771 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2021, RT-Thread Development Team + * Copyright (c) 2006-2022, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -226,6 +226,11 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) size = write(fh, buf, len); if (size >= 0) { + /* + fflush doesn't have a good solution in Keil-MDK, + so it has to sync/flush when for each writen. + */ + fsync(fh); return len - size; /* success */ } else @@ -239,6 +244,18 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) } } +/* + * Flush any OS buffers associated with fh, ensuring that the file + * is up to date on disk. Result is >=0 if OK, negative for an + * error. + * This function is deprecated. It is never called by any other library function, + * and you are not required to re-implement it if you are retargeting standard I/O (stdio). + */ +int _sys_ensure(FILEHANDLE fh) +{ + return fsync(fh); +} + /* * Move the file position to a given offset from the file start. * Returns >=0 on success, <0 on failure. -- GitLab