comparison packages/language/c/libc/stdio/current/src/input/fread.cxx @ 115:6ed91473a1cd ecos-sw-2000-08-21

Merge from eCos master repository on 2000-08-21-22:40:54-BST
author jlarmour
date Fri, 25 Aug 2000 17:32:38 +0000
parents
children 0d2b193a635f
comparison
equal deleted inserted replaced
114:5ad2b71d525e 115:6ed91473a1cd
1 //========================================================================
2 //
3 // fread.cxx
4 //
5 // ANSI Stdio fread() function
6 //
7 //========================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Red Hat eCos Public License
12 // Version 1.1 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://www.redhat.com/
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Configurable Operating System,
22 // released September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Red Hat.
25 // Portions created by Red Hat are
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
27 // All Rights Reserved.
28 // -------------------------------------------
29 //
30 //####COPYRIGHTEND####
31 //========================================================================
32 //#####DESCRIPTIONBEGIN####
33 //
34 // Author(s): jlarmour
35 // Contributors:
36 // Date: 2000-04-20
37 // Purpose:
38 // Description:
39 // Usage:
40 //
41 //####DESCRIPTIONEND####
42 //
43 //=======================================================================
44
45 // CONFIGURATION
46
47 #include <pkgconf/libc_stdio.h> // Configuration header
48
49 // INCLUDES
50
51 #include <cyg/infra/cyg_type.h> // Common project-wide type definitions
52 #include <cyg/infra/cyg_ass.h> // Assertion support
53 #include <cyg/infra/cyg_trac.h> // Tracing support
54 #include <stddef.h> // NULL and size_t from compiler
55 #include <stdio.h> // header for this file
56 #include <errno.h> // error codes
57 #include <cyg/libc/stdio/stream.hxx>// Cyg_StdioStream
58
59 // FUNCTIONS
60
61 externC size_t
62 fread( void *ptr, size_t object_size, size_t num_objects, FILE *stream )
63 {
64 Cyg_StdioStream *real_stream = (Cyg_StdioStream *)stream;
65 cyg_ucount32 bytes_read;
66 Cyg_ErrNo err;
67
68
69 CYG_REPORT_FUNCNAMETYPE( "fread", "read %d objects" );
70 CYG_REPORT_FUNCARG4( "ptr=%08x, object_size=%d, num_objects=%d, "
71 "stream=%08x", ptr, object_size, num_objects,
72 stream );
73
74 if ( (object_size==0) || (num_objects==0) ) {
75 CYG_REPORT_RETVAL(0);
76 return 0;
77 } // if
78
79 err = real_stream->read( (cyg_uint8 *)ptr, object_size*num_objects,
80 &bytes_read );
81
82 if (!err && !bytes_read) { // if no err, but nothing to read, try again
83 err = real_stream->refill_read_buffer();
84 if ( !err )
85 err = real_stream->read( (cyg_uint8 *)ptr, object_size*num_objects,
86 &bytes_read );
87 } // if
88
89 if (err) {
90 real_stream->set_error( err );
91 errno = err;
92 } // if
93
94 // we return the number of _objects_ read. Simple division is
95 // sufficient as this returns the quotient rather than rounding
96 CYG_REPORT_RETVAL( bytes_read/object_size );
97 return bytes_read/object_size;
98
99 } // fread()
100
101 // EOF fread.cxx