View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000232 | 1003.1(2008)/Issue 7 | System Interfaces | public | 2010-03-31 10:24 | 2013-04-16 13:06 |
Reporter | nsitbon | Assigned To | ajosey | ||
Priority | normal | Severity | Editorial | Type | Error |
Status | Closed | Resolution | Accepted As Marked | ||
Name | Nicolas Sitbon | ||||
Organization | DenyAll | ||||
User Reference | |||||
Section | fread() function | ||||
Page Number | 913 | ||||
Line Number | 30545 | ||||
Interp Status | --- | ||||
Final Accepted Text | 0000232:0000407 | ||||
Summary | 0000232: wrong example for fread() call | ||||
Description | in http://www.opengroup.org/onlinepubs/9699919799/functions/fread.html, in the "examples" section, the fread() call look like this: bytes_read = fread(buf, sizeof(buf), 1, fp); the 2nd and 3rd arguments are inverted, so the returned value (number of elements successfully read) doesn't match the number of elements passed to the function. | ||||
Desired Action | replace the example with: bytes_read = fread(buf, 1, sizeof(buf), fp); or better: bytes_read = fread(buf, sizeof(*buf), sizeof(buf), fp); | ||||
Tags | tc1-2008 |
has duplicate | 0000926 | Closed | 1003.1(2004)/Issue 6 | Documentation error in fread() example at (http://pubs.opengroup.org/onlinepubs/009695399/functions/fread.html) |
|
The call matches the text that introduces the example, which says it "reads a single element". So really the thing that is wrong is the variable name bytes_read. Perhaps it would be a good idea to have two examples: The following example reads a single element from the fp stream into the array pointed to by buf. #include <stdio.h> ... size_t elements_read; char buf[100]; FILE *fp; ... elements_read = fread(buf, sizeof(buf), 1, fp); ... If a read error occurs, elements_read will be zero but the number of bytes read from the stream could be anything from zero to sizeof(buf)-1. The following example reads multiple single-byte elements from the fp stream into the array pointed to by buf. #include <stdio.h> ... size_t bytes_read; char buf[100]; FILE *fp; ... bytes_read = fread(buf, 1, sizeof(buf), fp); ... If a read error occurs, bytes_read will contain the number of bytes read from the stream. |
Date Modified | Username | Field | Change |
---|---|---|---|
2010-03-31 10:24 | nsitbon | New Issue | |
2010-03-31 10:24 | nsitbon | Status | New => Under Review |
2010-03-31 10:24 | nsitbon | Assigned To | => ajosey |
2010-03-31 10:24 | nsitbon | Name | => Nicolas Sitbon |
2010-03-31 10:24 | nsitbon | Organization | => DenyAll |
2010-03-31 10:24 | nsitbon | Section | => fread() function |
2010-03-31 10:24 | nsitbon | Page Number | => 0 |
2010-03-31 10:24 | nsitbon | Line Number | => 0 |
2010-03-31 10:47 | geoffclare | Note Added: 0000407 | |
2010-03-31 23:20 | Don Cragun | Page Number | 0 => 913 |
2010-03-31 23:20 | Don Cragun | Line Number | 0 => 30545 |
2010-03-31 23:20 | Don Cragun | Interp Status | => --- |
2010-04-15 15:42 | geoffclare | Final Accepted Text | => 0000232:0000407 |
2010-04-15 15:42 | geoffclare | Status | Under Review => Resolved |
2010-04-15 15:42 | geoffclare | Resolution | Open => Accepted As Marked |
2010-08-27 12:30 | ajosey | Tag Attached: tc1-2008 | |
2013-04-16 13:06 | ajosey | Status | Resolved => Closed |
2015-02-23 09:37 | geoffclare | Relationship added | has duplicate 0000926 |