list.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "../../dprint.h"
00034 #include "../../mem/mem.h"
00035 #include "list.h"
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 int db_unixodbc_list_insert(list** start, list** link, int n, strn* value)
00047 {
00048 int i = 0;
00049
00050 if(!(*start)) {
00051 *link = (list*)pkg_malloc(sizeof(list));
00052 if(!(*link)) {
00053 LM_ERR("no more pkg memory (1)\n");
00054 return -1;
00055 }
00056 (*link)->rownum = n;
00057 (*link)->next = NULL;
00058
00059 (*link)->lengths = (unsigned long*)pkg_malloc(sizeof(unsigned long)*n);
00060 if(!(*link)->lengths) {
00061 LM_ERR("no more pkg memory (2)\n");
00062 pkg_free(*link);
00063 *link = NULL;
00064 return -1;
00065 }
00066 for(i=0; i<n; i++)
00067 (*link)->lengths[i] = strlen(value[i].s) + 1;
00068
00069 (*link)->data = (char**)pkg_malloc(sizeof(char*)*n);
00070 if(!(*link)->data) {
00071 LM_ERR("no more pkg memory (3)\n");
00072 pkg_free( (*link)->lengths );
00073 pkg_free(*link);
00074 *link = NULL;
00075 return -1;
00076 }
00077
00078 for(i=0; i<n; i++) {
00079 (*link)->data[i] = pkg_malloc(sizeof(char) * (*link)->lengths[i]);
00080 if(!(*link)->data[i]) {
00081 LM_ERR("no more pkg memory (4)\n");
00082 pkg_free( (*link)->lengths );
00083 pkg_free( (*link)->data );
00084 pkg_free(*link);
00085 *link = NULL;
00086 return -1;
00087 }
00088 strncpy((*link)->data[i], value[i].s, (*link)->lengths[i]);
00089 }
00090
00091 *start = *link;
00092 return 0;
00093 }
00094 else
00095 {
00096 list* nlink;
00097 nlink=(list*)pkg_malloc(sizeof(list));
00098 if(!nlink) {
00099 LM_ERR("no more pkg memory (5)\n");
00100 return -1;
00101 }
00102 nlink->rownum = n;
00103
00104 nlink->lengths = (unsigned long*)pkg_malloc(sizeof(unsigned long)*n);
00105 if(!nlink->lengths) {
00106 LM_ERR("no more pkg memory (6)\n");
00107 pkg_free(nlink);
00108 nlink = NULL;
00109 return -1;
00110 }
00111 for(i=0; i<n; i++)
00112 nlink->lengths[i] = strlen(value[i].s) + 1;
00113
00114 nlink->data = (char**)pkg_malloc(sizeof(char*)*n);
00115 if(!nlink->data) {
00116 LM_ERR("no more pkg memory (7)\n");
00117 pkg_free( nlink->lengths );
00118 pkg_free(nlink);
00119 nlink = NULL;
00120 return -1;
00121 }
00122
00123 for(i=0; i<n; i++) {
00124 nlink->data[i] = pkg_malloc(sizeof(char) * nlink->lengths[i]);
00125 if(!nlink->data[i]) {
00126 LM_ERR("no more pkg memory (8)\n");
00127 pkg_free( nlink->lengths );
00128 pkg_free( nlink->data );
00129 pkg_free(nlink);
00130 nlink = NULL;
00131 return -1;
00132 }
00133 strncpy(nlink->data[i], value[i].s, nlink->lengths[i]);
00134 }
00135
00136 nlink->next = NULL;
00137 (*link)->next = nlink;
00138 *link = (*link)->next;
00139
00140 return 0;
00141 }
00142 }
00143
00144
00145
00146
00147
00148
00149 void db_unixodbc_list_destroy(list *start)
00150 {
00151 int i = 0;
00152
00153 while(start) {
00154 list* temp = start;
00155 start = start->next;
00156 for(i = 0; i < temp->rownum; i++)
00157 pkg_free( temp->data[i] );
00158 pkg_free(temp->data);
00159 pkg_free(temp->lengths);
00160 pkg_free(temp);
00161 }
00162 }
00163