GRASS 8 Programmer's Manual
8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
db/dbmi_base/xdr.c
Go to the documentation of this file.
1
/*!
2
\file lib/db/dbmi_base/xdr.c
3
4
\brief DBMI Library (base) - external data representation
5
6
SPDX-FileCopyrightText: 1999-2009, 2011 GRASS Development Team
7
SPDX-License-Identifier: GPL-2.0-or-later
8
9
\author Joel Jones (CERL/UIUC), Radim Blazek, Brad Douglas, Markus Neteler
10
\author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
11
*/
12
13
#include "
xdr.h
"
14
15
#ifdef __MINGW32__
16
#define USE_STDIO 0
17
#define USE_READN 1
18
#else
19
#define USE_STDIO 1
20
#define USE_READN 0
21
#endif
22
23
#ifndef USE_STDIO
24
#include <
unistd.h
>
25
#endif
26
27
static
FILE
*_send, *_recv;
28
29
#if USE_READN
30
31
static
ssize_t
readn
(
int
fd,
void
*buf,
size_t
count)
32
{
33
ssize_t
total = 0;
34
35
while
(total <
count
) {
36
ssize_t
n =
read
(fd, (
char
*)buf + total,
count
- total);
37
38
if
(n < 0)
39
return
n;
40
if
(n == 0)
41
break
;
42
total += n;
43
}
44
45
return
total;
46
}
47
48
static
ssize_t
writen
(
int
fd,
const
void
*buf,
size_t
count)
49
{
50
ssize_t
total = 0;
51
52
while
(total < count) {
53
ssize_t
n =
write
(fd, (
const
char
*)buf + total, count - total);
54
55
if
(n < 0)
56
return
n;
57
if
(n == 0)
58
break
;
59
total += n;
60
}
61
62
return
total;
63
}
64
65
#endif
66
67
/*!
68
\brief ?
69
70
\param send
71
\param recv
72
*/
73
void
db__set_protocol_fds
(
FILE
*send,
FILE
*recv)
74
{
75
_send = send;
76
_recv = recv;
77
}
78
79
/*!
80
\brief ?
81
82
\param buf
83
\param size
84
85
\return
86
*/
87
int
db__send
(
const
void
*buf,
size_t
size)
88
{
89
#if USE_STDIO
90
return
fwrite
(buf, 1, size, _send) == size;
91
#elif USE_READN
92
return
writen
(
fileno
(_send), buf, size) == size;
93
#else
94
return
write
(
fileno
(_send), buf, size) == size;
95
#endif
96
}
97
98
int
db__recv
(
void
*buf,
size_t
size)
99
{
100
#if USE_STDIO
101
#ifdef USE_BUFFERED_IO
102
fflush
(_send);
103
#endif
104
return
fread
(buf, 1, size, _recv) == size;
105
#elif USE_READN
106
return
readn
(
fileno
(_recv), buf, size) == size;
107
#else
108
return
read
(
fileno
(_recv), buf, size) == size;
109
#endif
110
}
AMI_STREAM
Definition
ami_stream.h:153
db__set_protocol_fds
void db__set_protocol_fds(FILE *send, FILE *recv)
?
Definition
db/dbmi_base/xdr.c:73
db__recv
int db__recv(void *buf, size_t size)
Definition
db/dbmi_base/xdr.c:98
db__send
int db__send(const void *buf, size_t size)
?
Definition
db/dbmi_base/xdr.c:87
count
int count
unistd.h
read
#define read
Definition
unistd.h:5
write
#define write
Definition
unistd.h:6
xdr.h
lib
db
dbmi_base
xdr.c
Generated on Sun Sep 13 2026 06:57:49 for GRASS 8 Programmer's Manual by
1.9.8