GRASS 8 Programmer's Manual
8.6.0dev(2026)-c83afef6d3
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
* SPDX-FileCopyrightText: 2001-2014 GRASS Development Team
7
* SPDX-License-Identifier: GPL-2.0-or-later
8
*
9
* \author GRASS Development Team
10
*
11
* \date 1999-2014
12
*/
13
14
#include <errno.h>
15
#include <
unistd.h
>
16
#include <
string.h
>
17
#include <
grass/gis.h
>
18
#include <
grass/glocale.h
>
19
20
/**
21
* \brief Writes <b>n</b> bytes of zero to file descriptor <b>fd</b>
22
*
23
* \param[in] fd file descriptor
24
* \param[in] n number of bytes to write
25
* \return
26
*/
27
void
G_write_zeros
(
int
fd,
size_t
n)
28
{
29
char
zeros
[1024];
30
char
*z;
31
size_t
i;
32
33
if
(n <= 0)
34
return
;
35
36
/* fill zeros buffer with zeros */
37
if
(n >
sizeof
(
zeros
))
38
i =
sizeof
(
zeros
);
39
else
40
i = n;
41
42
z =
zeros
;
43
while
(i--)
44
*z++ = 0;
45
46
/* write n zeros to fd */
47
while
(n > 0) {
48
if
(n >
sizeof
(
zeros
))
49
i =
sizeof
(
zeros
);
50
else
51
i = n;
52
53
if
(
write
(fd,
zeros
, i) < 0)
54
G_fatal_error
(
_
(
"File writing error in %s() %d:%s"
),
__func__
,
55
errno
,
strerror
(
errno
));
56
n -= i;
57
}
58
}
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:27
lib
gis
writ_zeros.c
Generated on Fri Sep 11 2026 06:57:48 for GRASS 8 Programmer's Manual by
1.9.8