Commit | Line | Data |
---|---|---|
60de5df9 | 1 | /* |
7b19270d KB |
2 | * Copyright (c) 1983, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
46e9ea25 | 4 | * |
3dd3a9e5 KB |
5 | * This code is derived from software contributed to Berkeley by |
6 | * Edward Wang at The University of California, Berkeley. | |
7 | * | |
87f529ec | 8 | * %sccs.include.redist.c% |
60de5df9 EW |
9 | */ |
10 | ||
46e9ea25 | 11 | #ifndef lint |
7b19270d | 12 | static char sccsid[] = "@(#)wwalloc.c 8.1 (Berkeley) %G%"; |
46e9ea25 KB |
13 | #endif /* not lint */ |
14 | ||
ce3cd9c6 EW |
15 | #include "ww.h" |
16 | ||
17 | char ** | |
f2a77fe1 | 18 | wwalloc(row, col, nrow, ncol, size) |
ce3cd9c6 | 19 | { |
64431033 | 20 | register char *p, **pp; |
ce3cd9c6 EW |
21 | register int i; |
22 | ||
64431033 EW |
23 | /* fast, call malloc only once */ |
24 | pp = (char **) | |
25 | malloc((unsigned) sizeof (char **) * nrow + size * nrow * ncol); | |
03e75950 EW |
26 | if (pp == 0) { |
27 | wwerrno = WWE_NOMEM; | |
ce3cd9c6 | 28 | return 0; |
03e75950 | 29 | } |
64431033 | 30 | p = (char *)&pp[nrow]; |
f2a77fe1 | 31 | col *= size; |
64431033 EW |
32 | size /= sizeof (char); /* paranoid */ |
33 | size *= ncol; | |
ce3cd9c6 | 34 | for (i = 0; i < nrow; i++) { |
f2a77fe1 | 35 | pp[i] = p - col; |
64431033 | 36 | p += size; |
ce3cd9c6 | 37 | } |
f2a77fe1 | 38 | return pp - row; |
ce3cd9c6 EW |
39 | } |
40 | ||
f2a77fe1 | 41 | wwfree(p, row) |
ce3cd9c6 EW |
42 | register char **p; |
43 | { | |
f2a77fe1 | 44 | free((char *)(p + row)); |
ce3cd9c6 | 45 | } |