GRASS GIS 8 Programmer's Manual
8.5.0dev(2025)-565e82de51
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 GIS 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
30
void
G_write_zeros
(
int
fd,
size_t
n)
31
{
32
char
zeros[1024];
33
char
*z;
34
size_t
i;
35
36
if
(n <= 0)
37
return
;
38
39
/* fill zeros buffer with zeros */
40
if
(n >
sizeof
(zeros))
41
i =
sizeof
(zeros);
42
else
43
i = n;
44
45
z = zeros;
46
while
(i--)
47
*z++ = 0;
48
49
/* write n zeros to fd */
50
while
(n > 0) {
51
if
(n >
sizeof
(zeros))
52
i =
sizeof
(zeros);
53
else
54
i = n;
55
56
if
(
write
(fd, zeros, i) < 0)
57
G_fatal_error
(
_
(
"File writing error in %s() %d:%s"
), __func__,
58
errno, strerror(errno));
59
n -= i;
60
}
61
}
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:30
lib
gis
writ_zeros.c
Generated on Thu Mar 20 2025 07:33:31 for GRASS GIS 8 Programmer's Manual by
1.9.1