about summary refs log tree commit diff
path: root/src/stdio/open_memstream.c
Commit message (Collapse)AuthorAgeFilesLines
* reduce spurious inclusion of libc.hRich Felker2018-09-121-0/+2
| | | | | | | | | | | | | | | | | | | | | libc.h was intended to be a header for access to global libc state and related interfaces, but ended up included all over the place because it was the way to get the weak_alias macro. most of the inclusions removed here are places where weak_alias was needed. a few were recently introduced for hidden. some go all the way back to when libc.h defined CANCELPT_BEGIN and _END, and all (wrongly implemented) cancellation points had to include it. remaining spurious users are mostly callers of the LOCK/UNLOCK macros and files that use the LFS64 macro to define the awful *64 aliases. in a few places, new inclusion of libc.h is added because several internal headers no longer implicitly include libc.h. declarations for __lockfile and __unlockfile are moved from libc.h to stdio_impl.h so that the latter does not need libc.h. putting them in libc.h made no sense at all, since the macros in stdio_impl.h are needed to use them correctly anyway.
* set stream orientations in open_[w]memstreamRich Felker2018-08-281-0/+1
| | | | | | | | | | | | | | | | fundamentally there is no good reason these functions need to set an orientation (morally it should be possible to write a wchar_t[] memory stream using byte functions, or a char[] memory stream using wide functions), but it's a part of the specification that they do. aside from being able to inspect the orientation with fwide, failure to set the orientation in open_wmemstream is observable if the locale changes between open_wmemstream and the first operation on the stream; this is because the encoding rule (locale) for the stream is required to be bound at the time the stream becomes wide-oriented. for open_wmemstream, call fwide to avoid duplicating the logic for binding the encoding rule. for open_memstream it suffices just to set the mode field in the FILE struct.
* clean up allocation/setup logic for open_[w]memstreamRich Felker2018-04-181-19/+25
| | | | | bring these functions up to date with the current idioms we use/prefer in fmemopen and fopencookie.
* fix open_[w]memstream behavior when no writes take placeRich Felker2015-10-081-2/+9
| | | | | | | | | | | | | the specification for these functions requires that the buffer/size exposed to the caller be valid after any successful call to fflush or fclose on the stream. the implementation's approach is to update them only at flush time, but that misses the case where fflush or fclose is called without any writes having taken place, in which case the write flushing callback will not be called. to fix both the observable bug and the desired invariant, setup empty buffers at open time and fail the open operation if no memory is available.
* refactor stdio open file list handling, move it out of global libc structRich Felker2015-06-161-7/+1
| | | | | | | | | | | | | functions which open in-memory FILE stream variants all shared a tail with __fdopen, adding the FILE structure to stdio's open file list. replacing this common tail with a function call reduces code size and duplication of logic. the list is also partially encapsulated now. function signatures were chosen to facilitate tail call optimization and reduce the need for additional accessor functions. with these changes, static linked programs that do not use stdio no longer have an open file list at all.
* always add memory streams to stdio open file listRich Felker2012-11-091-6/+7
| | | | | | | | | | | | per interpretation for austin group issue #626, fflush(0) and exit() must block waiting for a lock if another thread has locked a memory stream with flockfile. this adds some otherwise-unnecessary synchronization cost to use of memory streams, but there was already a synchronization cost calling malloc anyway. previously the stream was only added to the open file list in single-threaded programs, so that upon subsequent call to pthread_create, locking could be turned on for the stream.
* clean up stdio_impl.hRich Felker2012-11-081-0/+3
| | | | | | | | | | | this header evolved to facilitate the extremely lazy practice of omitting explicit includes of the necessary headers in individual stdio source files; not only was this sloppy, but it also increased build time. now, stdio_impl.h is only including the headers it needs for its own use; any further headers needed by source files are included directly where needed.
* memstreams: fix incorrect handling of file pos > current sizeRich Felker2011-09-041-2/+2
| | | | | the addition is safe and cannot overflow because both operands are positive when considered as signed quantities.
* optimize seek function for memory streamsRich Felker2011-09-041-12/+3
|
* fix twos complement overflow bug in mem streams boundary checkRich Felker2011-09-041-1/+1
| | | | | | the expression -off is not safe in case off is the most-negative value. instead apply - to base which is known to be non-negative and bounded within sanity.
* fix some length calculations in memory streamsRich Felker2011-09-031-1/+1
|
* implement open_memstreamRich Felker2011-09-031-0/+94
this is the first attempt, and may have bugs. only minimal testing has been performed.