File: vector1.c

package info (click to toggle)
proj 4.4.9-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,588 kB
  • ctags: 1,656
  • sloc: ansic: 11,929; sh: 10,327; java: 229; makefile: 144; xml: 53
file content (32 lines) | stat: -rw-r--r-- 752 bytes parent folder | download | duplicates (5)
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
30
31
32
/* make storage for one and two dimensional matricies */
#ifndef lint
static const char SCCSID[]="@(#)vector1.c	4.4	94/03/22	GIE	REL";
#endif
#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)) {
		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;
}