GRASS GIS 7 Programmer's Manual
7.0.5(2016)-r00000
writ_zeros.c
Go to the documentation of this file.
1
17
#include <unistd.h>
18
#include <grass/gis.h>
19
20
29
void
G_write_zeros
(
int
fd,
size_t
n)
30
{
31
char
zeros[1024];
32
char
*z;
33
int
i;
34
35
if
(n <= 0)
36
return
;
37
38
/* There is a subtle gotcha to be avoided here.
39
*
40
* i must be an int for the write, but n (size_t) can be long or larger.
41
* Must be careful not to cast long to int, hence
42
* avoid i = n unless n is within range of int */
43
44
/* fill zeros buffer with zeros */
45
if
(n >
sizeof
(zeros))
46
i =
sizeof
(zeros);
47
else
48
i = n;
/* this is ok here */
49
50
z = zeros;
51
while
(i--)
52
*z++ = 0;
53
54
/* write n zeros to fd */
55
while
(n > 0) {
56
if
(n >
sizeof
(zeros))
57
i =
sizeof
(zeros);
58
else
59
i = n;
/* this is ok here */
60
61
write(fd, zeros, i);
62
n -= i;
63
}
64
}
G_write_zeros
void G_write_zeros(int fd, size_t n)
Writes n bytes of 9 to file descriptor fd
Definition:
writ_zeros.c:29
gis
writ_zeros.c
Generated on Sun Oct 2 2016 20:26:53 for GRASS GIS 7 Programmer's Manual by
1.8.12