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