File: vector1.c

package info (click to toggle)
proj 4.8.0-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 25,780 kB
  • ctags: 2,042
  • sloc: sh: 355,854; ansic: 14,877; java: 316; makefile: 260; xml: 46
file content (29 lines) | stat: -rw-r--r-- 677 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* make storage for one and two dimensional matricies */
#include <stdlib.h>
#include <projects.h>
	void * /* one dimension array */
vector1(int nvals, int size) { return((void *)pj_malloc(size * nvals)); }
	void /* free 2D array */
freev2(void **v, int nrows) {
	if (v) {
		for (v += nrows; nrows > 0; --nrows)
			pj_dalloc(*--v);
		pj_dalloc(v);
	}
}
	void ** /* two dimension array */
vector2(int nrows, int ncols, int size) {
	void **s;

	if ((s = (void **)pj_malloc(sizeof(void *) * nrows)) != NULL) {
		int rsize, i;

		rsize = size * ncols;
		for (i = 0; i < nrows; ++i)
			if (!(s[i] = pj_malloc(rsize))) {
				freev2(s, i);
				return (void **)0;
			}
	}
	return s;
}