[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT/LIBNEWLIB PATCH 1/1] Fix fwrite's return value for newline ended strings
Fwrite does not return the correct number of items written. If we pass a string that ends in '\n' we get n - 1(the '\n') for a string of length n. That is because __sputc_r returns EOF for the the newline character. This patch solves the problem by increasing the variable i if __sputc_r returned EOF when p[i] is '\n'. Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx> --- patches/0002-Fixed-fwrite.patch | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 patches/0002-Fixed-fwrite.patch diff --git a/patches/0002-Fixed-fwrite.patch b/patches/0002-Fixed-fwrite.patch new file mode 100644 index 0000000..2be388c --- /dev/null +++ b/patches/0002-Fixed-fwrite.patch @@ -0,0 +1,39 @@ +From c83670abf70a04ed21c567e659ab66136b40796f Mon Sep 17 00:00:00 2001 +From: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx> +Date: Wed, 10 Apr 2019 13:09:41 +0300 +Subject: [PATCH 1/1] Fix fwrite + +Fwrite does not return the correct number of items +written. If we pass a string that ends in '\n' we +get n - 1(the '\n') for a string of length n. +That is because __sputc_r returns EOF for the +the newline character. This patch solves the problem +by increasing the variable i if __sputc_r returned +EOF when p[i] is '\n'. + +Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx> +--- + newlib/libc/stdio/fwrite.c | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/newlib/libc/stdio/fwrite.c b/newlib/libc/stdio/fwrite.c +index 6b3ff90..d910247 100644 +--- a/newlib/libc/stdio/fwrite.c ++++ b/newlib/libc/stdio/fwrite.c +@@ -188,8 +188,11 @@ _DEFUN(_fwrite_r, (ptr, buf, size, count, fp), + + while (i < n) + { +- if (__sputc_r (ptr, p[i], fp) == EOF) +- break; ++ if (__sputc_r (ptr, p[i], fp) == EOF) { ++ if (p[i] == '\n') ++ i++; ++ break; ++ } + + i++; + } +-- +2.20.1 + -- 2.20.1 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |