Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | raltbos@xs4all.nl (Richard Bos) |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: fread a file of unknown size |
| Date | 2015-03-10 16:04 +0000 |
| Organization | Go wash your mouth. |
| Message-ID | <54ff150d.5348937@news.xs4all.nl> (permalink) |
| References | <mdi5g9$9hc$1@reader1.panix.com> <mdi64b$jpi$1@dont-email.me> <dbe3eb56-21a0-4720-a4a5-637d22d77105@googlegroups.com> |
fmassei@gmail.com wrote: > On Sunday, March 8, 2015 at 7:59:16 PM UTC+1, Richard Heathfield wrote: > > fread ought to return the number of bytes read. Instead, it returns the > > number of blocks. I expect there was a good reason once. > > Maybe there's one even today: if you are interested in bytes you just put > 1 in the second parameter, but if you are reading, let's say, fixed-length > structures, maybe the number of items read would be more useful. > > .. dunno. > > I also believe that returning the number of bytes would have made much more > sense. Let's put it this way. If you're interested in the number of bytes read, getting that from fread() is easy: use a 1 for the block size. If you're interested in the number of intact records read, getting that from fread() is just as easy: use the size of the record for the block size. If you want a hypothetical freadbytes() where you don't have to specify that you want to know the number of bytes, that's easy to implement in terms of fread(). Going the other way isn't hard, but it requires an extra calculation that fread() now doesn't. There was no good reason to restrict fread() to report bytes only, and some good reason to allow it to report record size. Richard
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
fread a file of unknown size ruben safir <ruben@mrbrklyn.com> - 2015-03-08 14:47 -0400
Re: fread a file of unknown size Richard Heathfield <rjh@cpax.org.uk> - 2015-03-08 18:59 +0000
Re: fread a file of unknown size James Kuyper <jameskuyper@verizon.net> - 2015-03-08 18:21 -0400
Re: fread a file of unknown size Keith Thompson <kst-u@mib.org> - 2015-03-08 18:43 -0700
Re: fread a file of unknown size fmassei@gmail.com - 2015-03-08 15:41 -0700
Re: fread a file of unknown size raltbos@xs4all.nl (Richard Bos) - 2015-03-10 16:04 +0000
Re: fread a file of unknown size Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-03-08 18:44 -0400
Re: fread a file of unknown size jacob navia <jacob@spamsink.net> - 2015-03-08 20:32 +0100
Re: fread a file of unknown size Keith Thompson <kst-u@mib.org> - 2015-03-08 12:48 -0700
Re: fread a file of unknown size glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-03-08 23:39 +0000
Re: fread a file of unknown size James Kuyper <jameskuyper@verizon.net> - 2015-03-08 20:40 -0400
Re: fread a file of unknown size glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-03-09 01:24 +0000
Re: fread a file of unknown size Keith Thompson <kst-u@mib.org> - 2015-03-09 07:53 -0700
Re: fread a file of unknown size glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-03-09 17:36 +0000
Re: fread a file of unknown size Keith Thompson <kst-u@mib.org> - 2015-03-09 10:44 -0700
Re: fread a file of unknown size glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-03-09 20:07 +0000
csiph-web