GRASS 8 Programmer's Manual 8.6.0dev(2026)-55de52a352
Loading...
Searching...
No Matches
xdrshort.c
Go to the documentation of this file.
1/*!
2 \file lib/db/dbmi_base/xdrshort.c
3
4 \brief DBMI Library (base) - external data representation (short)
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 <stdlib.h>
14#include "xdr.h"
15
16/*!
17 \brief Send short
18
19 \param n
20
21 \return
22 */
24{
25 int stat = DB_OK;
26 short h = (short)n;
27
28 if (!db__send(&h, sizeof(h)))
30
31 if (stat == DB_PROTOCOL_ERR)
33
34 return stat;
35}
36
37/*!
38 \brief Receive short
39
40 \param n
41
42 \return
43 */
44int db__recv_short(short *n)
45{
46 int stat = DB_OK;
47
48 if (!db__recv(n, sizeof(*n)))
50
51 if (stat == DB_PROTOCOL_ERR)
53
54 return stat;
55}
56
57/*!
58 \brief Send short array
59
60 \param x
61 \param n
62
63 \return
64 */
65int db__send_short_array(const short *x, int n)
66{
67 int stat = DB_OK;
68
69 if (!db__send(&n, sizeof(n)))
71
72 if (!db__send(x, n * sizeof(*x)))
74
75 if (stat == DB_PROTOCOL_ERR)
77
78 return stat;
79}
80
81/*!
82 \brief Receive short array
83
84 Returns an allocated array of ints
85 Caller is responsible for free()
86
87 \param x
88 \param n
89
90 \return
91 */
92int db__recv_short_array(short **x, int *n)
93{
94 int stat = DB_OK;
95 int count = 0;
96 short *a = NULL;
97
98 if (!db__recv(&count, sizeof(count)))
100
101 *n = count;
102
103 *x = a = (short *)db_calloc(count, sizeof(*a));
104
105 if (!db__recv(a, count * sizeof(*a)))
107
108 if (stat == DB_PROTOCOL_ERR)
110
111 return stat;
112}
#define NULL
Definition ccmath.h:32
int db__recv(void *buf, size_t size)
int db__send(const void *buf, size_t size)
?
#define DB_PROTOCOL_ERR
Definition dbmi.h:73
#define DB_OK
Definition dbmi.h:69
void * db_calloc(int, int)
Allocate memory.
void db_protocol_error(void)
Report protocol error.
int count
int db__recv_short_array(short **x, int *n)
Receive short array.
Definition xdrshort.c:92
int db__send_short_array(const short *x, int n)
Send short array.
Definition xdrshort.c:65
int db__send_short(int n)
Send short.
Definition xdrshort.c:23
int db__recv_short(short *n)
Receive short.
Definition xdrshort.c:44
#define x