diff --git a/arch/arm/src/common/up_exit.c b/arch/arm/src/common/up_exit.c index 190382a2da3..a25d6daacdf 100644 --- a/arch/arm/src/common/up_exit.c +++ b/arch/arm/src/common/up_exit.c @@ -110,13 +110,18 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) struct file_struct *filep = &streamlist->sl_streams[i]; if (filep->fs_fd >= 0) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - sinfo(" fd=%d nbytes=%d\n", - filep->fs_fd, - filep->fs_bufpos - filep->fs_bufstart); -#else - sinfo(" fd=%d\n", filep->fs_fd); -#endif +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (filep->fs_bufstart != NULL) + { + sinfo(" fd=%d nbytes=%d\n", + filep->fs_fd, + filep->fs_bufpos - filep->fs_bufstart); + } + else +Eendif + { + sinfo(" fd=%d\n", filep->fs_fd); + } } } #endif diff --git a/arch/avr/src/common/up_exit.c b/arch/avr/src/common/up_exit.c index d816ad1d9f7..a82c640d69d 100644 --- a/arch/avr/src/common/up_exit.c +++ b/arch/avr/src/common/up_exit.c @@ -109,13 +109,18 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) struct file_struct *filep = &streamlist->sl_streams[i]; if (filep->fs_fd >= 0) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - sinfo(" fd=%d nbytes=%d\n", - filep->fs_fd, - filep->fs_bufpos - filep->fs_bufstart); -#else - sinfo(" fd=%d\n", filep->fs_fd); +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (filep->fs_bufstart != NULL) + { + sinfo(" fd=%d nbytes=%d\n", + filep->fs_fd, + filep->fs_bufpos - filep->fs_bufstart); + } + else #endif + { + sinfo(" fd=%d\n", filep->fs_fd); + } } } #endif diff --git a/arch/hc/src/common/up_exit.c b/arch/hc/src/common/up_exit.c index 54d9a2c45c2..9b20fc8abaf 100644 --- a/arch/hc/src/common/up_exit.c +++ b/arch/hc/src/common/up_exit.c @@ -109,13 +109,18 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) struct file_struct *filep = &streamlist->sl_streams[i]; if (filep->fs_fd >= 0) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - sinfo(" fd=%d nbytes=%d\n", - filep->fs_fd, - filep->fs_bufpos - filep->fs_bufstart); -#else - sinfo(" fd=%d\n", filep->fs_fd); +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (filep->fs_bufstart != NULL) + { + sinfo(" fd=%d nbytes=%d\n", + filep->fs_fd, + filep->fs_bufpos - filep->fs_bufstart); + } + else #endif + { + sinfo(" fd=%d\n", filep->fs_fd); + } } } #endif diff --git a/arch/mips/src/common/up_exit.c b/arch/mips/src/common/up_exit.c index 1962c698e0a..d21a27e064d 100644 --- a/arch/mips/src/common/up_exit.c +++ b/arch/mips/src/common/up_exit.c @@ -111,13 +111,18 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) struct file_struct *filep = &streamlist->sl_streams[i]; if (filep->fs_fd >= 0) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - sinfo(" fd=%d nbytes=%d\n", - filep->fs_fd, - filep->fs_bufpos - filep->fs_bufstart); -#else - sinfo(" fd=%d\n", filep->fs_fd); +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (filep->fs_bufstart != NULL) + { + sinfo(" fd=%d nbytes=%d\n", + filep->fs_fd, + filep->fs_bufpos - filep->fs_bufstart); + } + else #endif + { + sinfo(" fd=%d\n", filep->fs_fd); + } } } #endif diff --git a/arch/misoc/src/lm32/lm32_exit.c b/arch/misoc/src/lm32/lm32_exit.c index f6cf75f6f4d..8dd96b0a3ac 100644 --- a/arch/misoc/src/lm32/lm32_exit.c +++ b/arch/misoc/src/lm32/lm32_exit.c @@ -108,13 +108,18 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) struct file_struct *filep = &streamlist->sl_streams[i]; if (filep->fs_fd >= 0) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - sinfo(" fd=%d nbytes=%d\n", - filep->fs_fd, - filep->fs_bufpos - filep->fs_bufstart); -#else - sinfo(" fd=%d\n", filep->fs_fd); +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (filep->fs_bufstart != NULL) + { + sinfo(" fd=%d nbytes=%d\n", + filep->fs_fd, + filep->fs_bufpos - filep->fs_bufstart); + } + else #endif + { + sinfo(" fd=%d\n", filep->fs_fd); + } } } #endif diff --git a/arch/renesas/src/common/up_exit.c b/arch/renesas/src/common/up_exit.c index ed61c7c299f..81843c5ccc1 100644 --- a/arch/renesas/src/common/up_exit.c +++ b/arch/renesas/src/common/up_exit.c @@ -109,13 +109,18 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) struct file_struct *filep = &streamlist->sl_streams[i]; if (filep->fs_fd >= 0) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - sinfo(" fd=%d nbytes=%d\n", - filep->fs_fd, - filep->fs_bufpos - filep->fs_bufstart); -#else - sinfo(" fd=%d\n", filep->fs_fd); +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (filep->fs_bufstart != NULL) + { + sinfo(" fd=%d nbytes=%d\n", + filep->fs_fd, + filep->fs_bufpos - filep->fs_bufstart); + } + else #endif + { + sinfo(" fd=%d\n", filep->fs_fd); + } } } #endif diff --git a/arch/risc-v/src/common/up_exit.c b/arch/risc-v/src/common/up_exit.c index 3dcbd69f292..5456012aeee 100644 --- a/arch/risc-v/src/common/up_exit.c +++ b/arch/risc-v/src/common/up_exit.c @@ -111,13 +111,18 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) struct file_struct *filep = &streamlist->sl_streams[i]; if (filep->fs_fd >= 0) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - sinfo(" fd=%d nbytes=%d\n", - filep->fs_fd, - filep->fs_bufpos - filep->fs_bufstart); -#else - sinfo(" fd=%d\n", filep->fs_fd); +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (filep->fs_bufstart != NULL) + { + sinfo(" fd=%d nbytes=%d\n", + filep->fs_fd, + filep->fs_bufpos - filep->fs_bufstart); + } + else #endif + { + sinfo(" fd=%d\n", filep->fs_fd); + } } } #endif diff --git a/arch/x86/src/common/up_exit.c b/arch/x86/src/common/up_exit.c index 66399be6db1..e5bcd30b465 100644 --- a/arch/x86/src/common/up_exit.c +++ b/arch/x86/src/common/up_exit.c @@ -109,13 +109,18 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) struct file_struct *filep = &streamlist->sl_streams[i]; if (filep->fs_fd >= 0) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - sinfo(" fd=%d nbytes=%d\n", - filep->fs_fd, - filep->fs_bufpos - filep->fs_bufstart); -#else - sinfo(" fd=%d\n", filep->fs_fd); +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (filep->fs_bufstart != NULL) + { + sinfo(" fd=%d nbytes=%d\n", + filep->fs_fd, + filep->fs_bufpos - filep->fs_bufstart); + } + else #endif + { + sinfo(" fd=%d\n", filep->fs_fd); + } } } #endif diff --git a/arch/xtensa/src/common/xtensa_exit.c b/arch/xtensa/src/common/xtensa_exit.c index 7cb12c360fa..d8dafeb20c9 100644 --- a/arch/xtensa/src/common/xtensa_exit.c +++ b/arch/xtensa/src/common/xtensa_exit.c @@ -111,13 +111,18 @@ static void _xtensa_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) struct file_struct *filep = &streamlist->sl_streams[i]; if (filep->fs_fd >= 0) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - sinfo(" fd=%d nbytes=%d\n", - filep->fs_fd, - filep->fs_bufpos - filep->fs_bufstart); -#else - sinfo(" fd=%d\n", filep->fs_fd); +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (filep->fs_bufstart != NULL) + { + sinfo(" fd=%d nbytes=%d\n", + filep->fs_fd, + filep->fs_bufpos - filep->fs_bufstart); + } + else #endif + { + sinfo(" fd=%d\n", filep->fs_fd); + } } } #endif diff --git a/arch/z16/src/common/up_exit.c b/arch/z16/src/common/up_exit.c index b142e6be215..58b2a542869 100644 --- a/arch/z16/src/common/up_exit.c +++ b/arch/z16/src/common/up_exit.c @@ -109,13 +109,18 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) struct file_struct *filep = &streamlist->sl_streams[i]; if (filep->fs_fd >= 0) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - sinfo(" fd=%d nbytes=%d\n", - filep->fs_fd, - filep->fs_bufpos - filep->fs_bufstart); -#else - sinfo(" fd=%d\n", filep->fs_fd); +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (filep->fs_bufstart != NULL) + { + sinfo(" fd=%d nbytes=%d\n", + filep->fs_fd, + filep->fs_bufpos - filep->fs_bufstart); + } + else #endif + { + sinfo(" fd=%d\n", filep->fs_fd); + } } } #endif diff --git a/arch/z80/src/common/up_exit.c b/arch/z80/src/common/up_exit.c index bb65dbd7779..af42e69ce9a 100644 --- a/arch/z80/src/common/up_exit.c +++ b/arch/z80/src/common/up_exit.c @@ -111,13 +111,18 @@ static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg) struct file_struct *filep = &streamlist->sl_streams[i]; if (filep->fs_fd >= 0) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - sinfo(" fd=%d nbytes=%d\n", - filep->fs_fd, - filep->fs_bufpos - filep->fs_bufstart); -#else - sinfo(" fd=%d\n", filep->fs_fd); +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (filep->fs_bufstart != NULL) + { + sinfo(" fd=%d nbytes=%d\n", + filep->fs_fd, + filep->fs_bufpos - filep->fs_bufstart); + } + else #endif + { + sinfo(" fd=%d\n", filep->fs_fd); + } } } #endif diff --git a/configs/eagle100/nettest/defconfig b/configs/eagle100/nettest/defconfig index b782d836165..836fd24fe60 100644 --- a/configs/eagle100/nettest/defconfig +++ b/configs/eagle100/nettest/defconfig @@ -761,7 +761,7 @@ CONFIG_MM_REGIONS=1 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/ez80f910200kitg/ostest/defconfig b/configs/ez80f910200kitg/ostest/defconfig index ba597876aa2..98891cc5f7f 100644 --- a/configs/ez80f910200kitg/ostest/defconfig +++ b/configs/ez80f910200kitg/ostest/defconfig @@ -505,7 +505,7 @@ CONFIG_HEAP2_SIZE=0 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/ez80f910200zco/dhcpd/defconfig b/configs/ez80f910200zco/dhcpd/defconfig index 3e689691867..b696d03129a 100644 --- a/configs/ez80f910200zco/dhcpd/defconfig +++ b/configs/ez80f910200zco/dhcpd/defconfig @@ -658,7 +658,7 @@ CONFIG_HEAP2_SIZE=0 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/ez80f910200zco/httpd/defconfig b/configs/ez80f910200zco/httpd/defconfig index 76f27ba843b..4e2271d50d7 100644 --- a/configs/ez80f910200zco/httpd/defconfig +++ b/configs/ez80f910200zco/httpd/defconfig @@ -672,7 +672,7 @@ CONFIG_HEAP2_SIZE=0 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/ez80f910200zco/nettest/defconfig b/configs/ez80f910200zco/nettest/defconfig index 9096a41faac..4476ee44afe 100644 --- a/configs/ez80f910200zco/nettest/defconfig +++ b/configs/ez80f910200zco/nettest/defconfig @@ -664,7 +664,7 @@ CONFIG_HEAP2_SIZE=0 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/ez80f910200zco/poll/defconfig b/configs/ez80f910200zco/poll/defconfig index f48526690c2..74c3f5ea3c1 100644 --- a/configs/ez80f910200zco/poll/defconfig +++ b/configs/ez80f910200zco/poll/defconfig @@ -674,7 +674,7 @@ CONFIG_HEAP2_SIZE=0 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/freedom-kl25z/nsh/defconfig b/configs/freedom-kl25z/nsh/defconfig index 03f252e999a..ead5cbb0596 100644 --- a/configs/freedom-kl25z/nsh/defconfig +++ b/configs/freedom-kl25z/nsh/defconfig @@ -565,7 +565,7 @@ CONFIG_BUILTIN=y # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/freedom-kl26z/nsh/defconfig b/configs/freedom-kl26z/nsh/defconfig index f76176d5a75..120119687e0 100644 --- a/configs/freedom-kl26z/nsh/defconfig +++ b/configs/freedom-kl26z/nsh/defconfig @@ -556,7 +556,7 @@ CONFIG_BUILTIN=y # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/lpcxpresso-lpc1115/nsh/defconfig b/configs/lpcxpresso-lpc1115/nsh/defconfig index 3607e86da86..abafecbe2bb 100644 --- a/configs/lpcxpresso-lpc1115/nsh/defconfig +++ b/configs/lpcxpresso-lpc1115/nsh/defconfig @@ -528,7 +528,7 @@ CONFIG_BUILTIN=y # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/lpcxpresso-lpc1768/dhcpd/defconfig b/configs/lpcxpresso-lpc1768/dhcpd/defconfig index 418286f3460..c6c3e6ba808 100644 --- a/configs/lpcxpresso-lpc1768/dhcpd/defconfig +++ b/configs/lpcxpresso-lpc1768/dhcpd/defconfig @@ -746,7 +746,7 @@ CONFIG_MM_REGIONS=2 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/micropendous3/hello/defconfig b/configs/micropendous3/hello/defconfig index 6445bfec5c4..2876f12d1c5 100644 --- a/configs/micropendous3/hello/defconfig +++ b/configs/micropendous3/hello/defconfig @@ -340,7 +340,7 @@ CONFIG_MM_REGIONS=1 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/misoc/nsh/defconfig b/configs/misoc/nsh/defconfig index ec5d68bb9df..0bac0c89c72 100644 --- a/configs/misoc/nsh/defconfig +++ b/configs/misoc/nsh/defconfig @@ -472,7 +472,7 @@ CONFIG_MM_REGIONS=1 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/moteino-mega/hello/defconfig b/configs/moteino-mega/hello/defconfig index d78adaa6b7e..d63906adff2 100644 --- a/configs/moteino-mega/hello/defconfig +++ b/configs/moteino-mega/hello/defconfig @@ -397,7 +397,7 @@ CONFIG_MM_REGIONS=1 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/moteino-mega/nsh/defconfig b/configs/moteino-mega/nsh/defconfig index 3a72bd17af0..8dd38900b2d 100644 --- a/configs/moteino-mega/nsh/defconfig +++ b/configs/moteino-mega/nsh/defconfig @@ -406,7 +406,7 @@ CONFIG_MM_REGIONS=1 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 CONFIG_LIB_HOMEDIR="/" diff --git a/configs/ne64badge/ostest/defconfig b/configs/ne64badge/ostest/defconfig index 284662823aa..4cffbda4f89 100644 --- a/configs/ne64badge/ostest/defconfig +++ b/configs/ne64badge/ostest/defconfig @@ -326,7 +326,7 @@ CONFIG_MM_REGIONS=1 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/nutiny-nuc120/nsh/defconfig b/configs/nutiny-nuc120/nsh/defconfig index 3b2c7b3ed38..f5dba7a48c0 100644 --- a/configs/nutiny-nuc120/nsh/defconfig +++ b/configs/nutiny-nuc120/nsh/defconfig @@ -574,7 +574,7 @@ CONFIG_SYMTAB_ORDEREDBYNAME=y # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/olimex-lpc1766stk/nettest/defconfig b/configs/olimex-lpc1766stk/nettest/defconfig index 020666d28c4..7f0e7390b66 100644 --- a/configs/olimex-lpc1766stk/nettest/defconfig +++ b/configs/olimex-lpc1766stk/nettest/defconfig @@ -752,7 +752,7 @@ CONFIG_MM_REGIONS=2 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/p112/ostest/defconfig b/configs/p112/ostest/defconfig index 455f6a52a60..4b93dc48123 100644 --- a/configs/p112/ostest/defconfig +++ b/configs/p112/ostest/defconfig @@ -334,7 +334,7 @@ CONFIG_GRAN_SINGLE=y # # Library Routines # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/spark/composite/defconfig b/configs/spark/composite/defconfig index 3b55a300c27..2dec57c31be 100644 --- a/configs/spark/composite/defconfig +++ b/configs/spark/composite/defconfig @@ -1017,7 +1017,7 @@ CONFIG_SYMTAB_ORDEREDBYNAME=y # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=2 CONFIG_LIB_HOMEDIR="/" diff --git a/configs/spark/nsh/defconfig b/configs/spark/nsh/defconfig index 6f43b59ca41..a1f4763fa5d 100644 --- a/configs/spark/nsh/defconfig +++ b/configs/spark/nsh/defconfig @@ -1017,7 +1017,7 @@ CONFIG_SYMTAB_ORDEREDBYNAME=y # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=2 CONFIG_LIB_HOMEDIR="/" diff --git a/configs/spark/usbmsc/defconfig b/configs/spark/usbmsc/defconfig index 66df842d96a..e75dd29766c 100644 --- a/configs/spark/usbmsc/defconfig +++ b/configs/spark/usbmsc/defconfig @@ -982,7 +982,7 @@ CONFIG_SYMTAB_ORDEREDBYNAME=y # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=2 CONFIG_LIB_HOMEDIR="/" diff --git a/configs/spark/usbserial/defconfig b/configs/spark/usbserial/defconfig index dd4d595afa1..303fa1a49cb 100644 --- a/configs/spark/usbserial/defconfig +++ b/configs/spark/usbserial/defconfig @@ -992,7 +992,7 @@ CONFIG_SYMTAB_ORDEREDBYNAME=y # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=2 CONFIG_LIB_HOMEDIR="/" diff --git a/configs/stm3220g-eval/dhcpd/defconfig b/configs/stm3220g-eval/dhcpd/defconfig index 48243187528..06f421502f7 100644 --- a/configs/stm3220g-eval/dhcpd/defconfig +++ b/configs/stm3220g-eval/dhcpd/defconfig @@ -1032,7 +1032,7 @@ CONFIG_MM_REGIONS=2 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y # CONFIG_STDIO_LINEBUFFER is not set CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/stm3220g-eval/nettest/defconfig b/configs/stm3220g-eval/nettest/defconfig index 4bf75d6522d..f52adbc0c5b 100644 --- a/configs/stm3220g-eval/nettest/defconfig +++ b/configs/stm3220g-eval/nettest/defconfig @@ -1037,7 +1037,7 @@ CONFIG_MM_REGIONS=1 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/stm3240g-eval/dhcpd/defconfig b/configs/stm3240g-eval/dhcpd/defconfig index 5138c8bed06..69eb3f61ace 100644 --- a/configs/stm3240g-eval/dhcpd/defconfig +++ b/configs/stm3240g-eval/dhcpd/defconfig @@ -1036,7 +1036,7 @@ CONFIG_MM_REGIONS=2 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y # CONFIG_STDIO_LINEBUFFER is not set CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/stm3240g-eval/nettest/defconfig b/configs/stm3240g-eval/nettest/defconfig index 22173822ada..e1e0eedc915 100644 --- a/configs/stm3240g-eval/nettest/defconfig +++ b/configs/stm3240g-eval/nettest/defconfig @@ -1041,7 +1041,7 @@ CONFIG_MM_REGIONS=2 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/stm32ldiscovery/nsh/defconfig b/configs/stm32ldiscovery/nsh/defconfig index 07c527576e7..4261827aa33 100644 --- a/configs/stm32ldiscovery/nsh/defconfig +++ b/configs/stm32ldiscovery/nsh/defconfig @@ -839,7 +839,7 @@ CONFIG_BINFMT_DISABLE=y # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/teensy-2.0/hello/defconfig b/configs/teensy-2.0/hello/defconfig index 7252b924f56..c1a3fe1b077 100644 --- a/configs/teensy-2.0/hello/defconfig +++ b/configs/teensy-2.0/hello/defconfig @@ -432,7 +432,7 @@ CONFIG_MM_REGIONS=1 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/teensy-2.0/nsh/defconfig b/configs/teensy-2.0/nsh/defconfig index a1e307241e5..905f64dff34 100644 --- a/configs/teensy-2.0/nsh/defconfig +++ b/configs/teensy-2.0/nsh/defconfig @@ -445,7 +445,7 @@ CONFIG_MM_REGIONS=1 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 CONFIG_LIB_HOMEDIR="/" diff --git a/configs/teensy-2.0/usbmsc/defconfig b/configs/teensy-2.0/usbmsc/defconfig index 8ae953d22e5..437fecf2fe0 100644 --- a/configs/teensy-2.0/usbmsc/defconfig +++ b/configs/teensy-2.0/usbmsc/defconfig @@ -506,7 +506,7 @@ CONFIG_MM_REGIONS=1 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/teensy-lc/nsh/defconfig b/configs/teensy-lc/nsh/defconfig index 26a3e8aed9e..8a28b949a9d 100644 --- a/configs/teensy-lc/nsh/defconfig +++ b/configs/teensy-lc/nsh/defconfig @@ -577,7 +577,7 @@ CONFIG_BUILTIN=y # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/us7032evb1/nsh/defconfig b/configs/us7032evb1/nsh/defconfig index fbc84921425..82a725a488f 100644 --- a/configs/us7032evb1/nsh/defconfig +++ b/configs/us7032evb1/nsh/defconfig @@ -357,7 +357,7 @@ CONFIG_MM_REGIONS=1 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 CONFIG_LIB_HOMEDIR="/" diff --git a/configs/us7032evb1/ostest/defconfig b/configs/us7032evb1/ostest/defconfig index 278a0eeff41..2b025f8ccec 100644 --- a/configs/us7032evb1/ostest/defconfig +++ b/configs/us7032evb1/ostest/defconfig @@ -354,7 +354,7 @@ CONFIG_MM_REGIONS=1 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/xtrs/nsh/defconfig b/configs/xtrs/nsh/defconfig index bfcbaf84fa3..057aa917d43 100644 --- a/configs/xtrs/nsh/defconfig +++ b/configs/xtrs/nsh/defconfig @@ -267,7 +267,7 @@ CONFIG_HEAP2_SIZE=0 # # Library Routines # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/xtrs/ostest/defconfig b/configs/xtrs/ostest/defconfig index 328ce577c77..373e087c99d 100644 --- a/configs/xtrs/ostest/defconfig +++ b/configs/xtrs/ostest/defconfig @@ -266,7 +266,7 @@ CONFIG_HEAP2_SIZE=0 # # Library Routines # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/xtrs/pashello/defconfig b/configs/xtrs/pashello/defconfig index b7a54c78449..4f05dd02565 100644 --- a/configs/xtrs/pashello/defconfig +++ b/configs/xtrs/pashello/defconfig @@ -266,7 +266,7 @@ CONFIG_HEAP2_SIZE=0 # # Library Routines # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 CONFIG_LIB_HOMEDIR="/" diff --git a/configs/z80sim/nsh/defconfig b/configs/z80sim/nsh/defconfig index 549fdf66e8a..a3fb674d317 100644 --- a/configs/z80sim/nsh/defconfig +++ b/configs/z80sim/nsh/defconfig @@ -267,7 +267,7 @@ CONFIG_HEAP2_SIZE=0 # # Library Routines # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/z80sim/ostest/defconfig b/configs/z80sim/ostest/defconfig index 279e54df2b2..7f91b797699 100644 --- a/configs/z80sim/ostest/defconfig +++ b/configs/z80sim/ostest/defconfig @@ -266,7 +266,7 @@ CONFIG_HEAP2_SIZE=0 # # Library Routines # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/z80sim/pashello/defconfig b/configs/z80sim/pashello/defconfig index 05658ccc6f6..0ad39d3b309 100644 --- a/configs/z80sim/pashello/defconfig +++ b/configs/z80sim/pashello/defconfig @@ -265,7 +265,7 @@ CONFIG_HEAP2_SIZE=0 # # Library Routines # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 CONFIG_LIB_HOMEDIR="/" diff --git a/configs/z8encore000zco/ostest/defconfig b/configs/z8encore000zco/ostest/defconfig index c63228ea73f..e294983e7a9 100644 --- a/configs/z8encore000zco/ostest/defconfig +++ b/configs/z8encore000zco/ostest/defconfig @@ -495,7 +495,7 @@ CONFIG_HEAP2_SIZE=0 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/configs/z8f64200100kit/ostest/defconfig b/configs/z8f64200100kit/ostest/defconfig index a5e518b5bbb..dea4dffa3f5 100644 --- a/configs/z8f64200100kit/ostest/defconfig +++ b/configs/z8f64200100kit/ostest/defconfig @@ -496,7 +496,7 @@ CONFIG_HEAP2_SIZE=0 # # Standard C Library Options # -CONFIG_STDIO_BUFFER_SIZE=0 +CONFIG_STDIO_DISABLE_BUFFERING=y CONFIG_STDIO_LINEBUFFER=y CONFIG_NUNGET_CHARS=0 # CONFIG_LIBM is not set diff --git a/fs/vfs/fs_fdopen.c b/fs/vfs/fs_fdopen.c index e69bb7b4324..c795d81630c 100644 --- a/fs/vfs/fs_fdopen.c +++ b/fs/vfs/fs_fdopen.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/vfs/fs_fdopen.c * - * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -221,17 +221,18 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR struct tcb_s *tcb) { /* Zero the structure */ -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING memset(stream, 0, sizeof(FILE)); #elif CONFIG_NUNGET_CHARS > 0 stream->fs_nungotten = 0; #endif -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING /* Initialize the semaphore the manages access to the buffer */ (void)sem_init(&stream->fs_sem, 0, 1); +#if CONFIG_STDIO_BUFFER_SIZE > 0 /* Allocate the IO buffer at the appropriate privilege level for * the group. */ @@ -251,12 +252,15 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR struct tcb_s *tcb) stream->fs_bufpos = stream->fs_bufstart; stream->fs_bufread = stream->fs_bufstart; +#ifdef CONFIG_STDIO_LINEBUFFER /* Setup buffer flags */ -#ifdef CONFIG_STDIO_LINEBUFFER stream->fs_flags |= __FS_FLAG_LBF; /* Line buffering */ -#endif -#endif + +#endif /* CONFIG_STDIO_LINEBUFFER */ +#endif /* CONFIG_STDIO_BUFFER_SIZE > 0 */ +#endif /* !CONFIG_STDIO_DISABLE_BUFFERING */ + /* Save the file description and open flags. Setting the * file descriptor locks this stream. */ diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 6895ace9428..4509665266f 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -405,7 +405,7 @@ struct filelist struct file_struct { int fs_fd; /* File descriptor associated with stream */ -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING sem_t fs_sem; /* For thread safety */ pid_t fs_holder; /* Holder of sem */ int fs_counts; /* Number of times sem is held */ diff --git a/include/stdio.h b/include/stdio.h index cc351730de7..c0aefded7f2 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -58,10 +58,12 @@ #define FILENAME_MAX _POSIX_NAME_MAX -/* The size of the I/O buffers */ +/* The (default) size of the I/O buffers */ -#if CONFIG_STDIO_BUFFER_SIZE > 0 -# define BUFSIZ CONFIG_STDIO_BUFFER_SIZE +#if defined(CONFIG_STDIO_BUFFER_SIZE) && CONFIG_STDIO_BUFFER_SIZE > 0 +# define BUFSIZ CONFIG_STDIO_BUFFER_SIZE +#else +# define BUFSIZ 64 #endif /* The following three definitions are for ANSI C, used by setvbuf */ diff --git a/libc/Kconfig b/libc/Kconfig index e1781e41cf6..b250dbd87e1 100644 --- a/libc/Kconfig +++ b/libc/Kconfig @@ -5,12 +5,22 @@ comment "Standard C Library Options" +config STDIO_DISABLE_BUFFERING + bool "Disable I/O Buffering" + default n + ---help--- + Tiny systems may need to disable all support for I/O buffering in + order to minimum footprint. + config STDIO_BUFFER_SIZE int "C STDIO buffer size" default 64 + depends on !STDIO_DISABLE_BUFFERING ---help--- - Size of buffers using within the C buffered I/O interfaces. - (printf, putchar, fwrite, etc.). + Size of buffers using within the C buffered I/O interfaces (printf, + putchar, fwrite, etc.). This function sets the initial I/O buffer + size. Zero disables I/O buffering. That size may be subsequently + modified using setvbuf(). config STDIO_LINEBUFFER bool "STDIO line buffering" diff --git a/libc/libc.h b/libc/libc.h index 9e947009f23..44104013387 100644 --- a/libc/libc.h +++ b/libc/libc.h @@ -1,7 +1,7 @@ /**************************************************************************** * libc/libc.h * - * Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2014, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -67,7 +67,7 @@ * protection. */ -#if CONFIG_STDIO_BUFFER_SIZE <= 0 +#ifdef CONFIG_STDIO_DISABLE_BUFFERING # define lib_sem_initialize(s) # define lib_take_semaphore(s) # define lib_give_semaphore(s) @@ -186,7 +186,7 @@ int lib_wrflush(FAR FILE *stream); /* Defined in lib_sem.c */ -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING void lib_sem_initialize(FAR struct file_struct *stream); void lib_take_semaphore(FAR struct file_struct *stream); void lib_give_semaphore(FAR struct file_struct *stream); diff --git a/libc/misc/Make.defs b/libc/misc/Make.defs index ec3c76b94da..673591ea6af 100644 --- a/libc/misc/Make.defs +++ b/libc/misc/Make.defs @@ -35,9 +35,13 @@ # Add the internal C files to the build -CSRCS += lib_stream.c lib_filesem.c lib_utsname.c +CSRCS += lib_stream.c lib_utsname.c CSRCS += lib_xorshift128.c lib_tea_encrypt.c lib_tea_decrypt.c +ifneq ($(CONFIG_STDIO_DISABLE_BUFFERING),y) +CSRCS += lib_filesem.c +endif + # Support for platforms that do not have long long types CSRCS += lib_umul32.c lib_umul64.c lib_umul32x64.c diff --git a/libc/misc/lib_filesem.c b/libc/misc/lib_filesem.c index 2fd5d1c9ebf..d84e46ef409 100644 --- a/libc/misc/lib_filesem.c +++ b/libc/misc/lib_filesem.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/misc/lib_filesem.c * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,15 +47,7 @@ #include "libc.h" -#if CONFIG_STDIO_BUFFER_SIZE > 0 - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ +#ifndef CONFIG_STDIO_DISABLE_BUFFERING /**************************************************************************** * Public Functions @@ -142,4 +134,5 @@ void lib_give_semaphore(FAR struct file_struct *stream) ASSERT(sem_post(&stream->fs_sem) == 0); } } -#endif /* CONFIG_STDIO_BUFFER_SIZE */ + +#endif /* CONFIG_STDIO_DISABLE_BUFFERING */ diff --git a/libc/misc/lib_stream.c b/libc/misc/lib_stream.c index b6586ab9699..4ed03433455 100644 --- a/libc/misc/lib_stream.c +++ b/libc/misc/lib_stream.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/misc/lib_stream.c * - * Copyright (C) 2007, 2011, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2011, 2013-2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -109,7 +109,7 @@ void lib_stream_initialize(FAR struct task_group_s *group) #endif /* CONFIG_NFILE_STREAMS > 0 */ /**************************************************************************** - * Name: lib_stream_init + * Name: lib_stream_release * * Description: * This function is called when a TCB is destroyed. Note that it does not @@ -122,7 +122,7 @@ void lib_stream_initialize(FAR struct task_group_s *group) void lib_stream_release(FAR struct task_group_s *group) { FAR struct streamlist *list; -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING int i; #endif @@ -139,9 +139,9 @@ void lib_stream_release(FAR struct task_group_s *group) (void)sem_destroy(&list->sl_sem); +#ifndef CONFIG_STDIO_DISABLE_BUFFERING /* Release each stream in the list */ -#if CONFIG_STDIO_BUFFER_SIZE > 0 for (i = 0; i < CONFIG_NFILE_STREAMS; i++) { FAR struct file_struct *stream = &list->sl_streams[i]; @@ -177,6 +177,6 @@ void lib_stream_release(FAR struct task_group_s *group) } #endif } -#endif /* CONFIG_NFILE_STREAMS > 0 */ +#endif /* CONFIG_NFILE_STREAMS > 0 */ #endif /* (!CONFIG_BUILD_PROTECTED &&7 !CONFIG_BUILD_KERNEL) || __KERNEL__ */ diff --git a/libc/stdio/Make.defs b/libc/stdio/Make.defs index 478ac3f4aaa..9a3a36ddb17 100644 --- a/libc/stdio/Make.defs +++ b/libc/stdio/Make.defs @@ -65,13 +65,17 @@ CSRCS += lib_rdflush.c lib_wrflush.c lib_fputc.c lib_puts.c lib_fputs.c CSRCS += lib_ungetc.c lib_vprintf.c lib_fprintf.c lib_vfprintf.c CSRCS += lib_stdinstream.c lib_stdoutstream.c lib_stdsistream.c CSRCS += lib_stdsostream.c lib_perror.c lib_feof.c lib_ferror.c -CSRCS += lib_clearerr.c lib_setvbuf.c lib_libnoflush.c lib_libsnoflush.c +CSRCS += lib_clearerr.c lib_libnoflush.c lib_libsnoflush.c endif ifeq ($(CONFIG_FS_WRITABLE),y) CSRCS += lib_tempnam.c lib_tmpnam.c endif + +ifneq ($(CONFIG_STDIO_DISABLE_BUFFERING),y) +CSRCS += lib_setvbuf.c +endif endif # Other support that depends on specific, configured features. diff --git a/libc/stdio/lib_fclose.c b/libc/stdio/lib_fclose.c index d02e6310ed5..022d7bde8eb 100644 --- a/libc/stdio/lib_fclose.c +++ b/libc/stdio/lib_fclose.c @@ -107,7 +107,7 @@ int fclose(FAR FILE *stream) } } -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING /* Destroy the semaphore */ sem_destroy(&stream->fs_sem); @@ -123,6 +123,7 @@ int fclose(FAR FILE *stream) /* Clear the whole structure */ memset(stream, 0, sizeof(FILE)); + #else #if CONFIG_NUNGET_CHARS > 0 /* Reset the number of ungetc characters */ @@ -133,6 +134,7 @@ int fclose(FAR FILE *stream) stream->fs_oflags = 0; #endif + /* Setting the file descriptor to -1 makes the stream available for reuse */ stream->fs_fd = -1; diff --git a/libc/stdio/lib_fseek.c b/libc/stdio/lib_fseek.c index 789bcb9359d..4dbe0441702 100644 --- a/libc/stdio/lib_fseek.c +++ b/libc/stdio/lib_fseek.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/stdio/lib_fseek.c * - * Copyright (C) 2007, 2008, 2011, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008, 2011, 2013, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -71,14 +71,7 @@ int fseek(FAR FILE *stream, long int offset, int whence) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - /* Flush any valid read/write data in the buffer (also verifies stream) */ - - if (lib_rdflush(stream) < 0 || lib_wrflush(stream) < 0) - { - return ERROR; - } -#else +#ifdef CONFIG_DEBUG_FEATURES /* Verify that we were provided with a stream */ if (!stream) @@ -88,6 +81,15 @@ int fseek(FAR FILE *stream, long int offset, int whence) } #endif +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + /* Flush any valid read/write data in the buffer (also verifies stream) */ + + if (lib_rdflush(stream) < 0 || lib_wrflush(stream) < 0) + { + return ERROR; + } +#endif + /* On success or failure, discard any characters saved by ungetc() */ #if CONFIG_NUNGET_CHARS > 0 diff --git a/libc/stdio/lib_ftell.c b/libc/stdio/lib_ftell.c index a2e8069639b..ece1a245a60 100644 --- a/libc/stdio/lib_ftell.c +++ b/libc/stdio/lib_ftell.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/stdio/lib_ftell.c * - * Copyright (C) 2008, 2011, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2008, 2011, 2013, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -64,13 +64,13 @@ * ****************************************************************************/ -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING static off_t lib_getrdoffset(FAR FILE *stream) { off_t rdoffset = 0; lib_take_semaphore(stream); - if (stream->fs_bufread != stream->fs_bufstart) + if (stream->fs_bufstart != NULL && stream->fs_bufread != stream->fs_bufstart) { #if CONFIG_NUNGET_CHARS > 0 rdoffset = stream->fs_bufread - stream->fs_bufpos + stream->fs_nungotten; diff --git a/libc/stdio/lib_libfflush.c b/libc/stdio/lib_libfflush.c index dd98140c5cc..22172a66c76 100644 --- a/libc/stdio/lib_libfflush.c +++ b/libc/stdio/lib_libfflush.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/stdio/lib_libfflush.c * - * Copyright (C) 2007-2008, 2011-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2008, 2011-2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -73,10 +73,11 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING FAR const unsigned char *src; ssize_t bytes_written; ssize_t nbuffer; + int ret; /* Return EBADF if the file is not opened for writing */ @@ -89,9 +90,19 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce) lib_take_semaphore(stream); + /* Check if there is an allocated I/O buffer */ + + if (stream->fs_bufstart == NULL) + { + /* No, then there can be nothing remaining in the buffer. */ + + ret = 0; + goto errout_with_sem; + } + /* Make sure that the buffer holds valid data */ - if (stream->fs_bufpos != stream->fs_bufstart) + if (stream->fs_bufpos != stream->fs_bufstart) { /* Make sure that the buffer holds buffered write data. We do not * support concurrent read/write buffer usage. @@ -103,8 +114,8 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce) * remaining in the buffer." */ - lib_give_semaphore(stream); - return 0; + ret = 0; + goto errout_with_sem; } /* How many bytes of write data are used in the buffer now */ @@ -126,8 +137,8 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce) */ stream->fs_flags |= __FS_FLAG_ERROR; - lib_give_semaphore(stream); - return -get_errno(); + ret = -get_errno();; + goto errout_with_sem; } /* Handle partial writes. fflush() must either return with @@ -162,6 +173,11 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce) lib_give_semaphore(stream); return stream->fs_bufpos - stream->fs_bufstart; + +errout_with_sem: + lib_give_semaphore(stream); + return ret; + #else /* Return no bytes remaining in the buffer */ diff --git a/libc/stdio/lib_libfread.c b/libc/stdio/lib_libfread.c index 94f7ce70381..a0aa588169e 100644 --- a/libc/stdio/lib_libfread.c +++ b/libc/stdio/lib_libfread.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/stdio/lib_libfread.c * - * Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -60,7 +60,7 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) { FAR unsigned char *dest = (FAR unsigned char*)ptr; ssize_t bytes_read; -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING int ret; #endif @@ -96,170 +96,177 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) } #endif -#if CONFIG_STDIO_BUFFER_SIZE > 0 - /* If the buffer is currently being used for write access, then - * flush all of the buffered write data. We do not support concurrent - * buffered read/write access. - */ +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + /* Is there an I/O buffer? */ - ret = lib_wrflush(stream); - if (ret < 0) + if (stream->bufstart != NULL) { - lib_give_semaphore(stream); - return ret; - } - - /* Now get any other needed chars from the buffer or the file. */ - - while (count > 0) - { - /* Is there readable data in the buffer? */ - - while ((count > 0) && (stream->fs_bufpos < stream->fs_bufread)) - { - /* Yes, copy a byte into the user buffer */ - - *dest++ = *stream->fs_bufpos++; - count--; - } - - /* The buffer is empty OR we have already supplied the number of - * bytes requested in the read. Check if we need to read - * more from the file. + /* If the buffer is currently being used for write access, then + * flush all of the buffered write data. We do not support concurrent + * buffered read/write access. */ - if (count > 0) + ret = lib_wrflush(stream); + if (ret < 0) { - size_t buffer_available; + lib_give_semaphore(stream); + return ret; + } - /* We need to read more data into the buffer from the file */ + /* Now get any other needed chars from the buffer or the file. */ - /* Mark the buffer empty */ + while (count > 0) + { + /* Is there readable data in the buffer? */ - stream->fs_bufpos = stream->fs_bufread = stream->fs_bufstart; + while ((count > 0) && (stream->fs_bufpos < stream->fs_bufread)) + { + /* Yes, copy a byte into the user buffer */ - /* How much space is available in the buffer? */ + *dest++ = *stream->fs_bufpos++; + count--; + } - buffer_available = stream->fs_bufend - stream->fs_bufread; - - /* Will the number of bytes that we need to read fit into - * the buffer space that is available? If the read size is - * larger than the buffer, then read some of the data - * directly into the user's buffer. + /* The buffer is empty OR we have already supplied the number of + * bytes requested in the read. Check if we need to read + * more from the file. */ - if (count > buffer_available) + if (count > 0) { - bytes_read = read(stream->fs_fd, dest, count); - if (bytes_read < 0) + size_t buffer_available; + + /* We need to read more data into the buffer from the file */ + + /* Mark the buffer empty */ + + stream->fs_bufpos = stream->fs_bufread = stream->fs_bufstart; + + /* How much space is available in the buffer? */ + + buffer_available = stream->fs_bufend - stream->fs_bufread; + + /* Will the number of bytes that we need to read fit into + * the buffer space that is available? If the read size is + * larger than the buffer, then read some of the data + * directly into the user's buffer. + */ + + if (count > buffer_available) { - /* An error occurred on the read. The error code is - * in the 'errno' variable. - */ - - goto errout_with_errno; - } - else if (bytes_read == 0) - { - /* We are at the end of the file. But we may already - * have buffered data. In that case, we will report - * the EOF indication later. - */ - - goto shortread; - } - else - { - /* Some bytes were read. Adjust the dest pointer */ - - dest += bytes_read; - - /* Were all of the requested bytes read? */ - - if ((size_t)bytes_read < count) + bytes_read = read(stream->fs_fd, dest, count); + if (bytes_read < 0) { - /* No. We must be at the end of file. */ + /* An error occurred on the read. The error code is + * in the 'errno' variable. + */ + + goto errout_with_errno; + } + else if (bytes_read == 0) + { + /* We are at the end of the file. But we may already + * have buffered data. In that case, we will report + * the EOF indication later. + */ goto shortread; } else { - /* Yes. We are done. */ + /* Some bytes were read. Adjust the dest pointer */ - count = 0; + dest += bytes_read; + + /* Were all of the requested bytes read? */ + + if ((size_t)bytes_read < count) + { + /* No. We must be at the end of file. */ + + goto shortread; + } + else + { + /* Yes. We are done. */ + + count = 0; + } } } - } - else - { - /* The number of bytes required to satisfy the read - * is less than or equal to the size of the buffer - * space that we have left. Read as much as we can - * into the buffer. - */ - - bytes_read = read(stream->fs_fd, stream->fs_bufread, buffer_available); - if (bytes_read < 0) - { - /* An error occurred on the read. The error code is - * in the 'errno' variable. - */ - - goto errout_with_errno; - } - else if (bytes_read == 0) - { - /* We are at the end of the file. But we may already - * have buffered data. In that case, we will report - * the EOF indication later. - */ - - goto shortread; - } else { - /* Some bytes were read */ + /* The number of bytes required to satisfy the read + * is less than or equal to the size of the buffer + * space that we have left. Read as much as we can + * into the buffer. + */ - stream->fs_bufread += bytes_read; + bytes_read = read(stream->fs_fd, stream->fs_bufread, buffer_available); + if (bytes_read < 0) + { + /* An error occurred on the read. The error code is + * in the 'errno' variable. + */ + + goto errout_with_errno; + } + else if (bytes_read == 0) + { + /* We are at the end of the file. But we may already + * have buffered data. In that case, we will report + * the EOF indication later. + */ + + goto shortread; + } + else + { + /* Some bytes were read */ + + stream->fs_bufread += bytes_read; + } } } } - } #else - /* Now get any other needed chars from the file. */ + /* Now get any other needed chars from the file. */ - while (count > 0) - { - bytes_read = read(stream->fs_fd, dest, count); - if (bytes_read < 0) + while (count > 0) { - /* An error occurred on the read. The error code is - * in the 'errno' variable. - */ + bytes_read = read(stream->fs_fd, dest, count); + if (bytes_read < 0) + { + /* An error occurred on the read. The error code is + * in the 'errno' variable. + */ - goto errout_with_errno; - } - else if (bytes_read == 0) - { - /* We are at the end of the file. But we may already - * have buffered data. In that case, we will report - * the EOF indication later. - */ + goto errout_with_errno; + } + else if (bytes_read == 0) + { + /* We are at the end of the file. But we may already + * have buffered data. In that case, we will report + * the EOF indication later. + */ - break; - } - else - { - dest += bytes_read; - count -= bytes_read; + break; + } + else + { + dest += bytes_read; + count -= bytes_read; + } } } #endif + /* Here after a successful (but perhaps short) read */ -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING shortread: #endif + bytes_read = dest - (FAR unsigned char *)ptr; /* Set or clear the EOF indicator. If we get here because of a diff --git a/libc/stdio/lib_libfwrite.c b/libc/stdio/lib_libfwrite.c index a9af1ab2a78..8cb067933fb 100644 --- a/libc/stdio/lib_libfwrite.c +++ b/libc/stdio/lib_libfwrite.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/stdio/lib_libfwrite.c * - * Copyright (C) 2007-2009, 2011, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2013-2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -57,12 +57,13 @@ ****************************************************************************/ ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream) -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING { FAR const unsigned char *start = ptr; FAR const unsigned char *src = ptr; ssize_t ret = ERROR; unsigned char *dest; + int ret; /* Make sure that writing to this stream is allowed */ @@ -72,12 +73,22 @@ ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream) return ret; } + /* Check if write access is permitted */ + if ((stream->fs_oflags & O_WROK) == 0) { set_errno(EBADF); goto errout; } + /* If there is no I/O buffer, then output data immediately */ + + if (stream->fs_bufstart == NULL) + { + ret = write(stream->fs_fd, ptr, count); + goto errout; + } + /* Get exclusive access to the stream */ lib_take_semaphore(stream); @@ -165,4 +176,4 @@ errout: return ret; } -#endif /* CONFIG_STDIO_BUFFER_SIZE */ +#endif /* CONFIG_STDIO_DISABLE_BUFFERING */ diff --git a/libc/stdio/lib_rdflush.c b/libc/stdio/lib_rdflush.c index 7a44359aa26..284f59e7d7d 100644 --- a/libc/stdio/lib_rdflush.c +++ b/libc/stdio/lib_rdflush.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/stdio/lib_rdflush.c * - * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2008, 2011, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,6 +46,8 @@ #include "libc.h" +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -59,15 +61,23 @@ * ****************************************************************************/ -#if CONFIG_STDIO_BUFFER_SIZE > 0 int lib_rdflush(FAR FILE *stream) { - if (!stream) + /* Sanity checking */ + + if (stream =- NULL) { set_errno(EBADF); return ERROR; } + /* Do nothing if there is no I/O buffer */ + + if (stream->fs_bufstart == NULL) + { + return OK; + } + /* Get exclusive access to the stream */ lib_take_semaphore(stream); @@ -108,5 +118,5 @@ int lib_rdflush(FAR FILE *stream) lib_give_semaphore(stream); return OK; } -#endif /* CONFIG_STDIO_BUFFER_SIZE */ +#endif /* CONFIG_STDIO_DISABLE_BUFFERING */ diff --git a/libc/stdio/lib_setvbuf.c b/libc/stdio/lib_setvbuf.c index 3875b770b9c..10fbc0e6d0e 100644 --- a/libc/stdio/lib_setvbuf.c +++ b/libc/stdio/lib_setvbuf.c @@ -74,11 +74,6 @@ * by the setvbuf() function. The contents of the array at any time are * unspecified. * - * REVISIT: This initial version of setvbuf has some limitations and not - * all features features required by the specification are available. - * Specifically, this current implementation cannot support sisabling - * stream buffering if CONFIG_STDIO_BUFFER_SIZE > 0 - * * Parmeters: * stream - the stream to flush * buffer - the user allocate buffer. If NULL, will allocates a buffer of @@ -95,7 +90,7 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING FAR unsigned char *newbuf; uint8_t flags; int errcode; @@ -127,18 +122,6 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size) goto errout; } -#if 1 /* REVISIT: _IONBF not yet supported */ - /* Not all features are be available. Without some additional logic, - * we cannot disable buffering if CONFIG_STDIO_BUFFER_SIZE > 0 - */ - - if (mode == _IONBF) - { - errcode = ENOSYS; - goto errout; - } -#endif - /* My assumption is that if size is zero for modes {_IOFBF, _IOLBF} the * caller is only attempting to change the buffering mode. In this case, * the existing buffer should be re-used (if there is one). If there is no @@ -149,7 +132,7 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size) if ((mode == _IOFBF || mode == _IOLBF) && size == 0 && stream->fs_bufstart == NULL) { - size = CONFIG_STDIO_BUFFER_SIZE; + size = BUFSIZE; } /* Make sure that we have exclusive access to the stream */ @@ -186,11 +169,7 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size) * successful. */ -#if 1 /* REVISIT: _IONBF not yet supported */ - flags = stream->fs_flags & ~(__FS_FLAG_LBF | __FS_FLAG_UBF); -#else flags = stream->fs_flags & ~(__FS_FLAG_LBF | __FS_FLAG_NBF | __FS_FLAG_UBF); -#endif /* Allocate a new buffer if one is needed or reuse the existing buffer it * is appropriate to do so. @@ -247,14 +226,12 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size) break; case _IONBF: -#if 0 /* REVISIT: _IONBF not yet supported */ /* No buffer needed... We must be performing unbuffered I/O */ DEBUGASSERT(size == 0); newbuf = NULL; flags |= __FS_FLAG_NBF; break; -#endif default: PANIC(); @@ -299,3 +276,5 @@ errout: return ERROR; #endif } + +#endif /* !CONFIG_STDIO_DISABLE_BUFFERING */ diff --git a/libc/stdio/lib_stdoutstream.c b/libc/stdio/lib_stdoutstream.c index 1fcef637574..5884f70bf53 100644 --- a/libc/stdio/lib_stdoutstream.c +++ b/libc/stdio/lib_stdoutstream.c @@ -82,11 +82,23 @@ static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch) * Name: stdoutstream_flush ****************************************************************************/ -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING static int stdoutstream_flush(FAR struct lib_outstream_s *this) { FAR struct lib_stdoutstream_s *sthis = (FAR struct lib_stdoutstream_s *)this; - return lib_fflush(sthis->stream, true); + FAR struct file *stream; + + DEBUGASSERT(sthis != NULL && sthis->stream != NULL); + stream = sthis->stream; + + if (stream->fs_bufstart != NULL) + { + return lib_fflush(sthis->stream, true); + } + else + { + return OK; + } } #endif @@ -125,8 +137,8 @@ void lib_stdoutstream(FAR struct lib_stdoutstream_s *outstream, * meaning. */ -#if CONFIG_STDIO_BUFFER_SIZE > 0 - if ((stream->fs_oflags & O_BINARY) == 0) +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (stream->fs_bufstart != NULL && (stream->fs_oflags & O_BINARY) == 0) { outstream->public.flush = stdoutstream_flush; } diff --git a/libc/stdio/lib_stdsostream.c b/libc/stdio/lib_stdsostream.c index 01ebc932918..a9957f53c7c 100644 --- a/libc/stdio/lib_stdsostream.c +++ b/libc/stdio/lib_stdsostream.c @@ -82,11 +82,23 @@ static void stdsostream_putc(FAR struct lib_sostream_s *this, int ch) * Name: stdsostream_flush ****************************************************************************/ -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING static int stdsostream_flush(FAR struct lib_sostream_s *this) { - FAR struct lib_stdsostream_s *sthis = (FAR struct lib_stdsostream_s *)this; - return lib_fflush(sthis->stream, true); + FAR struct lib_stdsostream_s *sthis = (FAR struct lib_stdoutstream_s *)this; + FAR struct file *stream; + + DEBUGASSERT(sthis != NULL && sthis->stream != NULL); + stream = sthis->stream; + + if (stream->fs_bufstart != NULL) + { + return lib_fflush(sthis->stream, true); + } + else + { + return OK; + } } #endif @@ -138,8 +150,8 @@ void lib_stdsostream(FAR struct lib_stdsostream_s *outstream, * meaning. */ -#if CONFIG_STDIO_BUFFER_SIZE > 0 - if ((stream->fs_oflags & O_BINARY) == 0) +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + if (stream->fs_bufstart != NULL && (stream->fs_oflags & O_BINARY) == 0) { outstream->public.flush = stdsostream_flush; } diff --git a/libc/stdio/lib_wrflush.c b/libc/stdio/lib_wrflush.c index cb65ef3e395..f9e02ddc330 100644 --- a/libc/stdio/lib_wrflush.c +++ b/libc/stdio/lib_wrflush.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/stdio/lib_wrflush.c * - * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2011-2012, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -60,16 +60,23 @@ int lib_wrflush(FAR FILE *stream) { -#if CONFIG_STDIO_BUFFER_SIZE > 0 +#ifndef CONFIG_STDIO_DISABLE_BUFFERING /* Verify that we were passed a valid (i.e., non-NULL) stream */ #ifdef CONFIG_DEBUG_FEATURES - if (!stream) + if (stream == NULL) { return -EINVAL; } #endif + /* Do nothing if there is no I/O buffer */ + + if (stream->fs_bufstart == NULL) + { + return OK; + } + /* Verify that the stream is opened for writing... lib_fflush will * return an error if it is called for a stream that is not opened for * writing. Check that first so that this function will not fail in @@ -91,6 +98,7 @@ int lib_wrflush(FAR FILE *stream) */ return lib_fflush(stream, true); + #else /* Verify that we were passed a valid (i.e., non-NULL) stream */