GRASS 8 Programmer's Manual
8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
writ_zeros.c
Go to the documentation of this file.
1
/*!
2
* \file lib/gis/writ_zeros.c
3
*
4
* \brief GIS Library - Write zero functions.
5
*
6
* (C) 2001-2014 by the GRASS Development Team
7
*
8
* This program is free software under the GNU General Public License
9
* (>=v2). Read the file COPYING that comes with GRASS for details.
10
*
11
* \author GRASS Development Team
12
*
13
* \date 1999-2014
14
*/
15
16
#include <errno.h>
17
#include <
unistd.h
>
18
#include <
string.h
>
19
#include <
grass/gis.h
>
20
#include <
grass/glocale.h
>
21
22
/**
23
* \brief Writes <b>n</b> bytes of zero to file descriptor <b>fd</b>
24
*
25
* \param[in] fd file descriptor
26
* \param[in] n number of bytes to write
27
* \return
28
*/
29
void
G_write_zeros
(
int
fd,
size_t
n)
30
{
31
char
zeros
[1024];
32
char
*z;
33
size_t
i;
34
35
if
(n <= 0)
36
return
;
37
38
/* fill zeros buffer with zeros */
39
if
(n >
sizeof
(
zeros
))
40
i =
sizeof
(
zeros
);
41
else
42
i = n;
43
44
z =
zeros
;
45
while
(i--)
46
*z++ = 0;
47
48
/* write n zeros to fd */
49
while
(n > 0) {
50
if
(n >
sizeof
(
zeros
))
51
i =
sizeof
(
zeros
);
52
else
53
i = n;
54
55
if
(
write
(fd,
zeros
, i) < 0)
56
G_fatal_error
(
_
(
"File writing error in %s() %d:%s"
),
__func__
,
57
errno
,
strerror
(
errno
));
58
n -= i;
59
}
60
}
AMI_STREAM
Definition
ami_stream.h:153
G_fatal_error
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
gis.h
glocale.h
_
#define _(str)
Definition
glocale.h:10
string.h
unistd.h
write
#define write
Definition
unistd.h:6
G_write_zeros
void G_write_zeros(int fd, size_t n)
Writes n bytes of zero to file descriptor fd
Definition
writ_zeros.c:29
lib
gis
writ_zeros.c
Generated on Fri Apr 3 2026 06:59:54 for GRASS 8 Programmer's Manual by
1.9.8