xdrshort.c

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include "xdr.h"
00003 
00004 
00005 int db__send_short(int n)
00006 {
00007     int stat = DB_OK;
00008     short h = (short)n;
00009 
00010     if (!db__send(&h, sizeof(h)))
00011         stat = DB_PROTOCOL_ERR;
00012 
00013     if (stat == DB_PROTOCOL_ERR)
00014         db_protocol_error();
00015 
00016     return stat;
00017 }
00018 
00019 int db__recv_short(short *n)
00020 {
00021     int stat = DB_OK;
00022 
00023     if (!db__recv(n, sizeof(*n)))
00024         stat = DB_PROTOCOL_ERR;
00025 
00026     if (stat == DB_PROTOCOL_ERR)
00027         db_protocol_error();
00028 
00029     return stat;
00030 }
00031 
00032 int db__send_short_array(const short *x, int n)
00033 {
00034     int stat = DB_OK;
00035 
00036     if (!db__send(&n, sizeof(n)))
00037         stat = DB_PROTOCOL_ERR;
00038 
00039     if (!db__send(x, n * sizeof(*x)))
00040         stat = DB_PROTOCOL_ERR;
00041 
00042     if (stat == DB_PROTOCOL_ERR)
00043         db_protocol_error();
00044 
00045     return stat;
00046 }
00047 
00048 /* returns an allocated array of ints */
00049 /* caller is responsible for free() */
00050 int db__recv_short_array(short **x, int *n)
00051 {
00052     int stat = DB_OK;
00053     int count = 0;
00054     short *a = NULL;
00055 
00056     if (!db__recv(&count, sizeof(count)))
00057         stat = DB_PROTOCOL_ERR;
00058 
00059     *n = count;
00060 
00061     *x = a = (short *)db_calloc(count, sizeof(*a));
00062 
00063     if (!db__recv(a, count * sizeof(*a)))
00064         stat = DB_PROTOCOL_ERR;
00065 
00066     if (stat == DB_PROTOCOL_ERR)
00067         db_protocol_error();
00068 
00069     return stat;
00070 }
Generated on Tue Apr 6 13:27:22 2010 for GRASS Programmer's Manual by  doxygen 1.6.3