svn-gvsig-desktop / trunk / libraries / libjni-proj4 / src / vector1.c @ 7098
History | View | Annotate | Download (752 Bytes)
1 |
/* make storage for one and two dimensional matricies */
|
---|---|
2 |
#ifndef lint
|
3 |
static const char SCCSID[]="@(#)vector1.c 4.4 94/03/22 GIE REL"; |
4 |
#endif
|
5 |
#include <stdlib.h> |
6 |
#include <projects.h> |
7 |
void * /* one dimension array */ |
8 |
vector1(int nvals, int size) { return((void *)pj_malloc(size * nvals)); } |
9 |
void /* free 2D array */ |
10 |
freev2(void **v, int nrows) { |
11 |
if (v) {
|
12 |
for (v += nrows; nrows > 0; --nrows) |
13 |
pj_dalloc(*--v); |
14 |
pj_dalloc(v); |
15 |
} |
16 |
} |
17 |
void ** /* two dimension array */ |
18 |
vector2(int nrows, int ncols, int size) { |
19 |
void **s;
|
20 |
|
21 |
if (s = (void **)pj_malloc(sizeof(void *) * nrows)) { |
22 |
int rsize, i;
|
23 |
|
24 |
rsize = size * ncols; |
25 |
for (i = 0; i < nrows; ++i) |
26 |
if (!(s[i] = pj_malloc(rsize))) {
|
27 |
freev2(s, i); |
28 |
return (void **)0; |
29 |
} |
30 |
} |
31 |
return s;
|
32 |
} |