summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/fread.c
Commit message (Collapse)AuthorAgeFilesLines
* stdio: provide _unlocked variants of fflush, fputc, fputs, fread, fwriteKyle Evans2020-01-301-0/+2
| | | | | | | | | | | | | | | | fflush_unlocked is currently desired in ports by sysutils/metalog, and redefined as the locked fflush. fputc_unlocked, fputs_unlocked, fread_unlocked, and fwrite_unlocked are currently desired in ports by devel/elfutils, and redefined as the locked fputs, fread, and fwrite respectively. Reviewed by: kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D23336 Notes: svn path=/head/; revision=357284
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326025
* Make stdio deferred cancel-safe.Konstantin Belousov2017-06-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | If used with fopen(3)/fdopen(3)-ed FILEs, stdio accurately uses non-cancellable internal versions of the functions, i.e. it seems to be fine with regard to cancellation. But if the funopen(3) and f{r,w}open(3) functions were used to open the FILE, and corresponding user functions create cancellation points (they typically have no other choice), then stdio code at least leaks FILE' lock. The change installs cleanup handler which unlocks FILE. Some minimal restructuring of the code was required to make it use common return place to satisfy hand-rolled pthread_cleanup_pop() requirements. Noted by: eugen Reviewed by: eugen, vangyzen Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D11246 Notes: svn path=/head/; revision=320472
* Renumber clauses to reduce diffs to other versionsEd Maste2013-04-231-1/+1
| | | | | | | | | | NetBSD, OpenBSD, and Android's Bionic all number the clauses 1 through 3, so follow suit to make comparison easier. Acked-by: imp@ Notes: svn path=/head/; revision=249808
* Give a less silly response to a silly request.Colin Percival2010-01-101-1/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this commit, fread/fwrite calls with size * nmemb > SIZE_MAX were handled by reading or writing (size_t)(size * nmemb) bytes; for example, on 32-bit platforms, fread(ptr, 641, 6700417, f) would read 1 byte and indicate that the requested 6700417 blocks had been read. This commit adds a check for such integer overflows, and treats them as if an overly large request was passed to read/write; i.e., it sets errno to EINVAL, sets the error indicator on the file, and returns a short object count (0, to be specific). The overflow check involves an integer division, so as a performance optimization we check first to see if both size and nmemb are less than 2^16; if they are, no overflow is possible and we avoid the division. We assume here that size_t is at least 32 bits; this appears to be true on all platforms FreeBSD supports. Although this commit fixes an integer overflow, it is not likely to have any security implications, since any program which would be affected by this bug fix is quite clearly already very confused. Reviewed by: kib MFC after: 1 month Notes: svn path=/head/; revision=201999
* Fix fwrite() to return 0 when size or nmemb are zero.Ed Schouten2009-07-121-3/+1
| | | | | | | | | | | Right now nmemb is returned when size is 0. In newer versions of the standards, it is explicitly required that fwrite() should return 0. Submitted by: Christoph Mallon Approved by: re (kib) Notes: svn path=/head/; revision=195637
* Fix fread() to return a correct value on platforms where sizeof(int) !=Ruslan Ermilov2008-12-011-1/+1
| | | | | | | | | | sizeof(size_t), i.e. on all 64-bit platforms. Reported by: Andrey V. Elsukov MFC after: 3 days Notes: svn path=/head/; revision=185516
* Per Regents of the University of Calfornia letter, remove advertisingWarner Losh2007-01-091-4/+0
| | | | | | | | | clause. # If I've done so improperly on a file, please let me know. Notes: svn path=/head/; revision=165903
* With current pthread implementations, a mutex initialization willDavid Xu2005-12-161-7/+16
| | | | | | | | | | | | | | | allocate a memory block. sscanf calls __svfscanf which in turn calls fread, fread triggers mutex initialization but the mutex is not destroyed in sscanf, this leads to memory leak. To avoid the memory leak and performance issue, we create a none MT-safe version of fread: __fread, and instead let __svfscanf call __fread. PR: threads/90392 Patch submitted by: dhartmei MFC after: 7 days Notes: svn path=/head/; revision=153467
* Add restrict type-qualifier.Mike Barcroft2002-10-121-2/+2
| | | | Notes: svn path=/head/; revision=104989
* Basic support for wide character I/O: getwc(), fgetwc(), getwchar(),Tim J. Robbins2002-08-131-0/+1
| | | | | | | putwc(), fputwc(), putwchar(), ungetwc(), fwide(). Notes: svn path=/head/; revision=101776
* Fix the style of the SCM ID's.David E. O'Brien2002-03-221-4/+2
| | | | | | | I believe have made all of libc .c's as consistent as possible. Notes: svn path=/head/; revision=92986
* Remove 'register' keyword.David E. O'Brien2002-03-211-4/+4
| | | | Notes: svn path=/head/; revision=92889
* Remove _THREAD_SAFE and make libc thread-safe by default byDaniel Eischen2001-01-241-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | adding (weak definitions to) stubs for some of the pthread functions. If the threads library is linked in, the real pthread functions will pulled in. Use the following convention for system calls wrapped by the threads library: __sys_foo - actual system call _foo - weak definition to __sys_foo foo - weak definition to __sys_foo Change all libc uses of system calls wrapped by the threads library from foo to _foo. In order to define the prototypes for _foo(), we introduce namespace.h and un-namespace.h (suggested by bde). All files that need to reference these system calls, should include namespace.h before any standard includes, then include un-namespace.h after the standard includes and before any local includes. <db.h> is an exception and shouldn't be included in between namespace.h and un-namespace.h namespace.h will define foo to _foo, and un-namespace.h will undefine foo. Try to eliminate some of the recursive calls to MT-safe functions in libc/stdio in preparation for adding a mutex to FILE. We have recursive mutexes, but would like to avoid using them if possible. Remove uneeded includes of <errno.h> from a few files. Add $FreeBSD$ to a few files in order to pass commitprep. Approved by: -arch Notes: svn path=/head/; revision=71579
* $Id$ -> $FreeBSD$Peter Wemm1999-08-281-1/+1
| | | | Notes: svn path=/head/; revision=50476
* Add FILE locking stubs for libc.John Birrell1998-04-111-11/+5
| | | | | | | | | | | Change the FILE locking to support kernel threads when linked with libpthread (which you haven't see yet). This requires that libc become thread-safe and thread-aware, testing __isthreaded before attempting to do lock/unlock calls. The impact on non-threaded programs is minor. This change works with libc_r, so it's the best compromise. Notes: svn path=/head/; revision=35129
* Revert $FreeBSD$ to $Id$Peter Wemm1997-02-221-1/+1
| | | | Notes: svn path=/head/; revision=22993
* Make the long-awaited change from $Id$ to $FreeBSD$Jordan K. Hubbard1997-01-141-1/+1
| | | | | | | | | | | This will make a number of things easier in the future, as well as (finally!) avoiding the Id-smashing problem which has plagued developers for so long. Boy, I'm glad we're not using sup anymore. This update would have been insane otherwise. Notes: svn path=/head/; revision=21673
* Suggested by: Bruce Evans, Jeffrey Hsu, Gary PalmerJames Raynard1996-06-221-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | Added $Id$'s to files that were lacking them (gpalmer), made some cosmetic changes to conform to style guidelines (bde) and checked against NetBSD and Lite2 to remove unnecessary divergences (hsu, bde) One last code cleanup:- Removed spurious casts in fseek.c and stdio.c. Added missing function argument in fwalk.c. Added missing header include in flags.c and rget.c. Put in casts where int's were being passed as size_t's. Put in missing prototypes for static functions. Changed second args of __sflags() inflags.c and writehook() in vasprintf.c from char * to const char * to conform to prototypes. This directory now compiles with no warnings with -Wall under gcc-2.6.3 and with considerably less warnings than before with the ultra-pedantic script I used for testing. (Most of the remaining ones are due to const poisoning). Notes: svn path=/head/; revision=16586
* Reviewed by: julian and (hsu?)Julian Elischer1996-01-221-0/+11
| | | | | | | | | Submitted by: John Birrel(L?) changes for threadsafe operations Notes: svn path=/head/; revision=13545
* BSD 4.4 Lite Lib SourcesRodney W. Grimes1994-05-271-0/+81
Notes: svn path=/cvs2svn/branches/unlabeled-1.1.1/; revision=1573