~ubuntu-branches/ubuntu/vivid/proj/vivid

« back to all changes in this revision

Viewing changes to src/vector1.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter S Galbraith
  • Date: 2002-01-11 10:27:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020111102712-ayi18r8y2eesv0y9
Tags: upstream-4.4.5
ImportĀ upstreamĀ versionĀ 4.4.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}