1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1 /******************************************************************************
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
2 * *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
3 * Copyright (C) 1992-1995 Tony Robinson *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
4 * *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
5 * See the file doc/LICENSE.shorten for conditions on distribution and usage *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
6 * *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
7 ******************************************************************************/
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
8
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
9 /*
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
10 * $Id: array.c,v 1.7 2003/08/26 05:34:04 jason Exp $
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
11 */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
12
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
13 #include <stdio.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
14 #include <stdlib.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
15 #include "shorten.h"
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
16
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
17 void *pmalloc(ulong size, shn_file *this_shn) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
18 void *ptr;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
19
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
20 ptr = malloc(size);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
21
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
22 if(ptr == NULL)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
23 shn_error_fatal(this_shn,"Call to malloc(%ld) failed in pmalloc() -\nyour system may be low on memory", size);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
24
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
25 return(ptr);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
26 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
27
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
28 slong **long2d(ulong n0, ulong n1, shn_file *this_shn) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
29 slong **array0 = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
30
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
31 if((array0 = (slong**) pmalloc((ulong) (n0 * sizeof(slong*) +
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
32 n0 * n1 * sizeof(slong)),this_shn)) != NULL ) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
33 slong *array1 = (slong*) (array0 + n0);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
34 int i;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
35
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
36 for(i = 0; i < n0; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
37 array0[i] = array1 + i * n1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
38 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
39 return(array0);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
40 }
|