GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
xdrint.c
Go to the documentation of this file.
1 #include "xdr.h"
2 
3 
4 int db__send_int(int n)
5 {
6  int stat = DB_OK;
7 
8  if (!db__send(&n, sizeof(n)))
9  stat = DB_PROTOCOL_ERR;
10 
11  if (stat == DB_PROTOCOL_ERR)
13 
14  return stat;
15 }
16 
17 int db__recv_int(int *n)
18 {
19  int stat = DB_OK;
20 
21  if (!db__recv(n, sizeof(*n)))
22  stat = DB_PROTOCOL_ERR;
23 
24  if (stat == DB_PROTOCOL_ERR)
26 
27  return stat;
28 }
29 
30 int db__send_int_array(const int *x, int n)
31 {
32  int stat = DB_OK;
33 
34  if (!db__send(&n, sizeof(n)))
35  stat = DB_PROTOCOL_ERR;
36 
37  if (!db__send(x, n * sizeof(*x)))
38  stat = DB_PROTOCOL_ERR;
39 
40  if (stat == DB_PROTOCOL_ERR)
42 
43  return stat;
44 }
45 
46 /* returns an allocated array of ints */
47 /* caller is responsible for free() */
48 int db__recv_int_array(int **x, int *n)
49 {
50  int stat = DB_OK;
51  int count = 0;
52  int *a = NULL;
53 
54  if (!db__recv(&count, sizeof(count)))
55  stat = DB_PROTOCOL_ERR;
56 
57  *n = count;
58 
59  *x = a = (int *)db_calloc(count, sizeof(*a));
60 
61  if (!db__recv(a, count * sizeof(*a)))
62  stat = DB_PROTOCOL_ERR;
63 
64  if (stat == DB_PROTOCOL_ERR)
66 
67  return stat;
68 }
int db__send(const void *buf, size_t size)
Definition: xdr.c:77
void * db_calloc(int n, int m)
int count
int db__send_int_array(const int *x, int n)
Definition: xdrint.c:30
void db_protocol_error(void)
int stat
Definition: g3dcolor.c:369
int db__recv_int_array(int **x, int *n)
Definition: xdrint.c:48
int db__send_int(int n)
Definition: xdrint.c:4
int db__recv(void *buf, size_t size)
Definition: xdr.c:88
return NULL
Definition: dbfopen.c:1394
int n
Definition: dataquad.c:291
int db__recv_int(int *n)
Definition: xdrint.c:17