GRASS Programmer's Manual 6.4.1(2011)
|
00001 #include "xdr.h" 00002 00003 00004 int db__send_int(int n) 00005 { 00006 int stat = DB_OK; 00007 00008 if (!db__send(&n, sizeof(n))) 00009 stat = DB_PROTOCOL_ERR; 00010 00011 if (stat == DB_PROTOCOL_ERR) 00012 db_protocol_error(); 00013 00014 return stat; 00015 } 00016 00017 int db__recv_int(int *n) 00018 { 00019 int stat = DB_OK; 00020 00021 if (!db__recv(n, sizeof(*n))) 00022 stat = DB_PROTOCOL_ERR; 00023 00024 if (stat == DB_PROTOCOL_ERR) 00025 db_protocol_error(); 00026 00027 return stat; 00028 } 00029 00030 int db__send_int_array(const int *x, int n) 00031 { 00032 int stat = DB_OK; 00033 00034 if (!db__send(&n, sizeof(n))) 00035 stat = DB_PROTOCOL_ERR; 00036 00037 if (!db__send(x, n * sizeof(*x))) 00038 stat = DB_PROTOCOL_ERR; 00039 00040 if (stat == DB_PROTOCOL_ERR) 00041 db_protocol_error(); 00042 00043 return stat; 00044 } 00045 00046 /* returns an allocated array of ints */ 00047 /* caller is responsible for free() */ 00048 int db__recv_int_array(int **x, int *n) 00049 { 00050 int stat = DB_OK; 00051 int count = 0; 00052 int *a = NULL; 00053 00054 if (!db__recv(&count, sizeof(count))) 00055 stat = DB_PROTOCOL_ERR; 00056 00057 *n = count; 00058 00059 *x = a = (int *)db_calloc(count, sizeof(*a)); 00060 00061 if (!db__recv(a, count * sizeof(*a))) 00062 stat = DB_PROTOCOL_ERR; 00063 00064 if (stat == DB_PROTOCOL_ERR) 00065 db_protocol_error(); 00066 00067 return stat; 00068 }