FreeNOS
lib
libposix
stdio
fread.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2009 Niek Linnenbank
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#include <
unistd.h
>
19
#include <
sys/types.h
>
20
#include "
stdio.h
"
21
#include "
stdlib.h
"
22
#include "
errno.h
"
23
24
size_t
fread
(
void
*ptr,
size_t
size,
25
size_t
nitems,
FILE
*stream)
26
{
27
size_t
i;
28
char
*buf = (
char
*) ptr;
29
30
// Read items
31
for
(i = 0; i < nitems; i++)
32
{
33
ssize_t
num =
read
(stream->
fd
, buf, size);
34
if
(num < 0 || (
size_t
)num != size)
35
break
;
36
37
buf += size;
38
}
39
40
// Done
41
return
i;
42
}
types.h
read
ssize_t read(int fildes, void *buf, size_t nbyte)
Read from a file.
Definition:
read.cpp:22
stdio.h
FILE::fd
int fd
File descriptor.
Definition:
stdio.h:63
unistd.h
ssize_t
slong ssize_t
Used for a count of bytes or an error indication.
Definition:
types.h:38
fread
size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream)
Binary input.
Definition:
fread.cpp:24
FILE
A structure containing information about a file.
Definition:
stdio.h:60
stdlib.h
errno.h
Generated by
1.8.17