GRASS 8 Programmer's Manual
8.5.0(2026)-8d6ceba290
Toggle main menu visibility
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
}
G_fatal_error
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition
gis/error.c:159
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
gis
writ_zeros.c
Generated on
for GRASS 8 Programmer's Manual by
1.17.0