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