FreeNOS
lib
libposix
stdio
fwrite.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
fwrite
(
const
void
*ptr,
size_t
size,
25
size_t
nitems,
FILE
*stream)
26
{
27
size_t
i;
28
char
*buf = (
char
*) ptr;
29
30
// Write items
31
for
(i = 0; i < nitems; i++)
32
{
33
ssize_t
num =
write
(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
}
write
ssize_t write(int fildes, const void *buf, size_t nbyte)
Write on a file.
Definition:
write.cpp:22
types.h
fwrite
size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream)
The fwrite() function shall write, from the array pointed to by ptr, up to nitems elements whose size...
Definition:
fwrite.cpp:24
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
FILE
A structure containing information about a file.
Definition:
stdio.h:60
stdlib.h
errno.h
Generated by
1.8.17