summaryrefslogtreecommitdiff
path: root/libc/stdio
AgeCommit message (Collapse)Author
2016-06-12Fix infinite loop when fopencookie custom write returns 0 on errorJan Vangorp
The man page for fopencookie prescribes that custom write functions should return 0 on error (and should definitely not return a negative value) [1]. However, the uClibc implementation expects a negative return value in case of an error (libc/stdio/_WRITE.c). If the write function returns 0 on error, we drop into an infinite loop if the error persists. This patch wraps the user supplied write function such that a 0 return value is converted to -1. errno is first set to EAGAIN such that if the custom write function does not set errno in case of error, this is treated as a "soft" error. Custom write functions that cater towards uClibc and _do_ return a negative value are not affected. If no custom write function is supplied, set errno to EINVAL such that this condition is treated as a "hard" error. Previously the behaviour depended on whether the last error before the write happened to be a "hard" or a "soft" error. [1] http://git.kernel.org/cgit/docs/man-pages/man-pages.git/tree/man3/fopencookie.3?id=6c0d0ef0c7a9c4bcf805c6f9e9bc1ef1c3865ea0#n164 Signed-off-by: Jan Vangorp <jan.vangorp_ext@softathome.com>
2016-06-01remove MJN only debug messagesWaldemar Brodkorb
2016-02-24Replaced any occurence of /bin/sh with _PATH_BSHELL to allow easier ↵Ubaldo Porcheddu
portability on system with default shell on a different directory, like for instance on android. Signed-off-by: Ubaldo Porcheddu <ubaldo@eja.it>
2015-12-17libc/stdio: Rework custom streams interface similar to glibc.Waldemar Brodkorb
Save 20 bytes per FILE structure, avoid indirect call for read/write/seek/close operations for normal streams. Additionally, custom streams has fileno = -2 now, like in glibc. bloat-o-meter report (UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y): function old new delta fopencookie 69 131 +62 ftello64 233 260 +27 fseeko64 298 319 +21 fclose 423 442 +19 .rodata 16696 16708 +12 fileno_unlocked 53 45 -8 __ns_name_pack 859 851 -8 vswscanf 184 144 -40 vdprintf 231 187 -44 vsscanf 210 151 -59 vswprintf 269 201 -68 vsnprintf 249 181 -68 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/7 up/down: 141/-295) Total: -154 bytes Signed-off-by: Leonid Lisovskiy <lly.dev@gmail.com> Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
2015-12-09Reduce the initial buffer size for open_memstreamWaldemar Brodkorb
Reduce the initial buffer size for open_memstream (used by vasprintf), as most strings are usually smaller than that. Realloc the buffer after finishing the string to further reduce size. Problem appears in case of UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y, see http://dev.openwrt.org/ticket/13024 Signed-off-by: Felix Fietkau <nbd@openwrt.org> Signed-off-by: Leonid Lisovskiy <lly.dev@gmail.com> Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
2015-08-14add mkstemps, mkstemps64 and mkostemps, mkostemps64 functionsRomain Naour
Change __gen_tempname() prototype in order to pass the additional suffix lenght. In __gen_tempname() add a new check for suffixlen. Update some comments in the code. Signed-off-by: Romain Naour <romain.naour@openwide.fr> Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
2015-06-10_scanf.c: Implement 'm' modifier for 'c' and '[' conversions.Will Newton
The current code implements the 'm' modifier only for 's' conversions and would cause a segfault if it was used for 'c' or '[' conversions. This patch extends the code to cover these cases too. The original version could write scanned data outside the passed buffer because index i used in the '[' conversion handling block was clobbered. Signed-off-by: Will Newton <will.newton@imgtec.com> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2015-04-12remove more of the link_warningsWaldemar Brodkorb
Only the stub warnings left for now.
2015-03-29merge uClibc git masterWaldemar Brodkorb
2015-03-22libc: Fix vfprintf compilation without HAS_FLOATSBernhard Reutner-Fischer
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2015-01-01I think this is what you meanThorsten Glaser
Signed-off-by: Thorsten Glaser <tg@mirbsd.org>
2015-01-01silence GCCThorsten Glaser
Signed-off-by: Thorsten Glaser <tg@mirbsd.org>
2014-12-30remove another two warnings.Waldemar Brodkorb
2014-12-28reduce some unneeded warnings.Waldemar Brodkorb
2014-12-15mkostemp: fix implementationAnthony G. Basile
mkostemp(char *template, int flags) generates a unique temporary filename from a template. The flags parameter accepts three of the same flags as open(2): O_APPEND, O_CLOEXEC, and O_SYNC. The current implementation of mkostemp(3) does not respect the flags and in fact confuses the flags with the file mode which should always be S_IRUSR | S_IWUSR. This patch corrects this issue. Signed-off-by: Anthony G. Basile <blueness@gentoo.org> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2014-12-15stdio: Fix printing 0.0Bernhard Reutner-Fischer
We were relying on FE_DIVBYZERO being turned off when printing "%f", +-.0 Avoid the whole issue by looking at the sign-bit (in a rough approximation). Note that we do not handle gracefully: printf ("\n%llf\n", -0.0); printf ("\n%llf\n", 0.0); nor %Lf for both when NOT cast to long double. Avoiding an FPE due to broken numbers like these does not make sense to me. Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-03-29Revert "_scanf.c: Implement 'm' modifier for 'c' and '[' conversions."Bernhard Reutner-Fischer
This reverts commit e567c399ff86d007d8c4586f0dd5e0ca61e283ca. since it breaks badly (e.g. busybox netstat) Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-03-29_vfprintf.c: use 'fputws_unlocked(S, F)' instead of 'fputws(S, F)'Mirko Vogt
This eliminates a source of reproduceable freezes Signed-off-by: Mirko Vogt <dev@nanl.de> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2013-03-22Fix a problem with scanning wide chars.Nathan Sidwell
We found that the testcase int main (void) { wchar_t s[10]; memset (s, 0, sizeof (s)); int r = sscanf ("s", "%ls", s); printf ("%d\n", r); printf ("%ls\n", s); return 0; } printed 0 <blankline> rather than the expected 1 s The problem was the enum in _scanf.c, which has had a 'CONV_m' value inserted. The attached patch fixes the problem in __psfs_parse_spec by not presuming a particular displacement between the two sets of char-like conversion values. With this patch the above program produces the expected output. Signed-off-by: Nathan Sidwell <nathan@codesourcery.com> Signed-off-by: Bernd Schmidt <bernds@codesourcery.com>
2013-02-05buildsys: switch libc to kbuild-styleBernhard Reutner-Fischer
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-11-18drop support for pre ISO-C compilersMike Frysinger
This drops __signed, __volatile, and __const. Only the latter was used in the code base, and for uClibc, not consistently. Much of the code used plain "const" which meant "__const" was useless. Really, the point of this is to stay in sync with what glibc did. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-11-18Replace FSF snail mail address with URLsMike Frysinger
This matches a similar change made to glibc. No functional changes here. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-10-31_scanf.c: Implement 'm' modifier for 'c' and '[' conversions.Will Newton
The current code implements the 'm' modifier only for 's' conversions and would cause a segfault if it was used for 'c' or '[' conversions. This patch extends the code to cover these cases too. Signed-off-by: Will Newton <will.newton@imgtec.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15_stdio.c: pthread.h was already included by _stdio.hPeter S. Mazinger
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15handle the type mismatch of ftell[o] and fseek[o] if long int != off_tPeter S. Mazinger
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15_fpmaxtostr.c: align comments, no code changePeter S. Mazinger
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15_scanf.c: fix to signedness warningsPeter S. Mazinger
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15popen.c: get rid of a shadow warningPeter S. Mazinger
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15errno and *_init cleanupPeter S. Mazinger
Define a common view of __errno_location, __h_errno_location in common header and use that everywhere, __uClibc_main.c is no special. The rule adopted: for enabled threads we make in libc the __GI_x() variants strong, x() weak and (should) provide another strong x() in libpthread. If threads are disabled, even the __GI_x() variants are weak. _stdio_init,_stdio_term,_locale_init: make all hidden weak in common header Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15_vfprintf.c: use _fpmaxtostr.hPeter S. Mazinger
remove code already in _fpmaxtostr.h Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15_vfprintf.c: get rid of __STDIO_PRINTF_FLOATPeter S. Mazinger
Rely completely on the configuration options chosen, in this case on UCLIBC_HAS_FLOATS. Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15old_vfprintf.c: use _fpmaxtostr.hPeter S. Mazinger
It shows that the internal functions differ... Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15_fpmaxtostr.c: move common to _fpmaxtostr.hPeter S. Mazinger
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15_vfprintf.c: fix typo s/NL_MAX_ARG/NL_ARGMAX/Peter S. Mazinger
NL_MAX_ARG does not exist. Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15_stdio.h: move _load_inttype.h and _store_inttype.h prototypes herePeter S. Mazinger
Use one common prototype for consistency. Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15do not define _ISOC99_SOURCE in specific filesPeter S. Mazinger
This should come properly from features.h or the build. Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15remove duplicate prototypes for _stdio_term().Peter S. Mazinger
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15uClibc_stdio.h: move internal to _stdio.h and make them hiddenPeter S. Mazinger
Move __stdio_mutex_init,_stdio_openlist_{use,del}_count to _stdio.h. Make _stdio_validate_FILE hidden. Make _stdio_openlist_{add,del}_lock hidden for non-NPTL. Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15stdio.h: update partially, mainly for POSIX 2008Peter S. Mazinger
Guard some UCLIBC specific parts. Add comment about bits/getopt.h. open_memstream.c: remove __restrict according to SuSv4. Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15use fputwc in putwchar()Peter S. Mazinger
use fputwc instead of fputc add hidden fputwc to avoid jump relocation Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-06-15fputc.c, stdio.h: no need for hidden putc, putc_unlocked and fputc_unlockedPeter S. Mazinger
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-05-21stdio: implement assignment-allocation "m" characterMike Frysinger
The latest POSIX spec introduces a "m" character to allocate buffers for the user when using scanf type functions. This is like the old glibc "a" flag, but now standardized. With packages starting to use these, we need to implement it. for example: char *s; sscanf("foo", "%ms", &s); printf("%s\n", s); free(s); This will automatically allocate storage for "s", read in "foo" to it, and then display it. I'm not terribly familiar with the stdio layer, so this could be wrong. But it seems to work for me. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-05-05drop support for old systems lacking vforkMark Salter
Only really old systems (<=linux-2.0) lack a dedicated vfork system call. The code that is in place to support them is causing issues with newer arches that also don't provide a vfork system call -- instead, they do vfork by calling clone in userspace. If anyone cares about these really old systems, they can submit a patch to make the system work with them while not breaking newer systems. Signed-off-by: Mark Salter <msalter@redhat.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-03-28stdio: Fix char signedness in _load_inttype()Bernhard Reutner-Fischer
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2012-03-25stdio: prevent retries on fclose/fflush after write errorsDenys Vlasenko
Some test results: The longer patch posted at Sun 14:46:24 +0100 made my target system unbootable. I did not attempt to troubleshoot it, as we are focusing our efforts on the shorter patch now. The shorter patch posted at Mon 01:50:27 +0100 is a good start, but it didn't completely fix the problem for me. I am posting an updated version with a few changes at the end of this message; the patched uClibc 0.9.32.1 tree passes both of my test cases. My changes: 1) Need to break out of the loop on "hard" errors. Otherwise the library call never returns: open("/dev/null", O_RDONLY) = 4 dup2(4, 1) = 1 write(1, "hello world\n", 12) = -1 EBADF (Bad file descriptor) write(1, "hello world\n", 12) = -1 EBADF (Bad file descriptor) write(1, "hello world\n", 12) = -1 EBADF (Bad file descriptor) write(1, "hello world\n", 12) = -1 EBADF (Bad file descriptor) ... 2) Move all of the error handling logic back into the "else" clause. In particular, I believe we do not want to be checking errno unless __WRITE() had indicated a failure, since the value may be undefined: if (errno == EINTR || errno == EAGAIN /* do we have other "soft" errors? */ ) { 3) Whitespace/indentation consistency. -- 8< -- From: Denys Vlasenko <vda.linux@googlemail.com> Currently, uclibc retains buffered data on stdio write errors, and subsequent fclose and fflush will try to write it out again (in most cases, in vain). Which results in something like this: On Wednesday 26 January 2011 13:21, Baruch Siach wrote: > Hi busybox list, > > I'm running the following command under strace (thanks Rob): > > echo 56 > /sys/class/gpio/export > > and I see the following output: > > write(1, "56\n", 3) = -1 EBUSY (Device or resource busy) > write(1, "5", 1) = 1 > > The first EBUSY is OK, since GPIO 56 is already requested. But the second > write() attempt seems strange, and leads to an unwanted outcome. GPIO 5 gets > exported. This patch prevents that. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> Signed-off-by: Kevin Cernekee <cernekee@gmail.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-03-11__stdio_WRITE: make code more readable. No code changesDenys Vlasenko
Pulled assignments out of ifs. do {...} while (1); is a weird method of writing "loop forever", thus rewrote it. No code changes: objdump output is the same. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-01-29tmpnam, tempnam are obsolete in SUSV4Bernhard Reutner-Fischer
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2011-11-20stdio: add support for "e" flag with fopen()Mike Frysinger
Support this useful glibc extension for optionally setting O_CLOEXEC on fopen streams. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2011-11-17stdio: hide _stdio_validate_FILEBernhard Reutner-Fischer
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2011-06-29libc: add missing lock initialization in vswprintfMaksim Rayskiy
Unlike vsnprintf, vswprintf does not properly initialize locking elements of FILE structure, which in some unfortunate cases can result in lockups in _vfwprintf_internal. Interesting, the initialization code was removed in 2a915734a32c5aec9a6a76c13bcb074d30e64171 at the same time as it was added to vsnprintf. Signed-off-by: Maksim Rayskiy <mrayskiy@broadcom.com> Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>