Commit | Line | Data |
---|---|---|
ce3cd9c6 | 1 | #ifndef lint |
f2a77fe1 | 2 | static char *sccsid = "@(#)wwalloc.c 3.5 83/09/15"; |
ce3cd9c6 EW |
3 | #endif |
4 | ||
5 | #include "ww.h" | |
6 | ||
7 | char ** | |
f2a77fe1 | 8 | wwalloc(row, col, nrow, ncol, size) |
ce3cd9c6 | 9 | { |
64431033 | 10 | register char *p, **pp; |
ce3cd9c6 EW |
11 | register int i; |
12 | ||
64431033 EW |
13 | /* fast, call malloc only once */ |
14 | pp = (char **) | |
15 | malloc((unsigned) sizeof (char **) * nrow + size * nrow * ncol); | |
03e75950 EW |
16 | if (pp == 0) { |
17 | wwerrno = WWE_NOMEM; | |
ce3cd9c6 | 18 | return 0; |
03e75950 | 19 | } |
64431033 | 20 | p = (char *)&pp[nrow]; |
f2a77fe1 | 21 | col *= size; |
64431033 EW |
22 | size /= sizeof (char); /* paranoid */ |
23 | size *= ncol; | |
ce3cd9c6 | 24 | for (i = 0; i < nrow; i++) { |
f2a77fe1 | 25 | pp[i] = p - col; |
64431033 | 26 | p += size; |
ce3cd9c6 | 27 | } |
f2a77fe1 | 28 | return pp - row; |
ce3cd9c6 EW |
29 | } |
30 | ||
f2a77fe1 | 31 | wwfree(p, row) |
ce3cd9c6 EW |
32 | register char **p; |
33 | { | |
f2a77fe1 | 34 | free((char *)(p + row)); |
ce3cd9c6 | 35 | } |