Commit | Line | Data |
---|---|---|
ce3cd9c6 | 1 | #ifndef lint |
60de5df9 | 2 | static char sccsid[] = "@(#)wwalloc.c 3.7 %G%"; |
ce3cd9c6 EW |
3 | #endif |
4 | ||
60de5df9 EW |
5 | /* |
6 | * Copyright (c) 1983 Regents of the University of California, | |
7 | * All rights reserved. Redistribution permitted subject to | |
8 | * the terms of the Berkeley Software License Agreement. | |
9 | */ | |
10 | ||
ce3cd9c6 EW |
11 | #include "ww.h" |
12 | ||
13 | char ** | |
f2a77fe1 | 14 | wwalloc(row, col, nrow, ncol, size) |
ce3cd9c6 | 15 | { |
64431033 | 16 | register char *p, **pp; |
ce3cd9c6 EW |
17 | register int i; |
18 | ||
64431033 EW |
19 | /* fast, call malloc only once */ |
20 | pp = (char **) | |
21 | malloc((unsigned) sizeof (char **) * nrow + size * nrow * ncol); | |
03e75950 EW |
22 | if (pp == 0) { |
23 | wwerrno = WWE_NOMEM; | |
ce3cd9c6 | 24 | return 0; |
03e75950 | 25 | } |
64431033 | 26 | p = (char *)&pp[nrow]; |
f2a77fe1 | 27 | col *= size; |
64431033 EW |
28 | size /= sizeof (char); /* paranoid */ |
29 | size *= ncol; | |
ce3cd9c6 | 30 | for (i = 0; i < nrow; i++) { |
f2a77fe1 | 31 | pp[i] = p - col; |
64431033 | 32 | p += size; |
ce3cd9c6 | 33 | } |
f2a77fe1 | 34 | return pp - row; |
ce3cd9c6 EW |
35 | } |
36 | ||
f2a77fe1 | 37 | wwfree(p, row) |
ce3cd9c6 EW |
38 | register char **p; |
39 | { | |
f2a77fe1 | 40 | free((char *)(p + row)); |
ce3cd9c6 | 41 | } |