campo-sirio/gfm/daralloc.c

82 lines
1.4 KiB
C
Raw Normal View History

/* DEC **AllocateDecimalArray(dst, n);
*
* ARGUMENT
* int n;
* DEC **dst;
*
* DESCRIPTION
* Creates an array of n DEC pointers, each pointing to a DEC structure.
* All of the DEC structures are zeroed with in id of 2. If dst is null,
* both the pointers and the structures are allocated. Otherwise, when dst
* is not null, only the structures are allocated and each pointer points to
* the corresponding DEC structure.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Returns pointer to the new structure if allocation is successful,
* otherwise returns GM_NULLARR.
*
* POSSIBLE ERROR CODES
*
* GM_NOMEMORY
* GM_ARGVAL (if n == 0)
* GM_NULLPOINTER
*
* AUTHOR
* Jared Levy
* Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved.
*
* MODIFICATIONS
*
*/
#include <stdio.h>
#include <malloc.h>
#include "gm.h"
#include "gmsystem.h"
#ifndef DOS
extern char *calloc(unsigned ,unsigned );
#endif
DEC **AllocateDecimalArray(dst, n)
int n;
DEC **dst;
{
DEC *b, *p;
int i;
_MacStart(GM_DARALLOC);
if (n<=0) {
_MacErr(GM_ARGVAL);
_MacRet(GM_NULLARR);
}
if (!dst) {
_MacErr(GM_NULLPOINTER);
_MacRet(GM_NULLARR);
}
b = (DEC *) calloc(n,sizeof(DEC));
/* insufficient room for pointers */
if(!b) {
_MacErr(GM_NOMEMORY);
_MacRet(GM_NULLARR);
}
for (i=0; i<n; i++) {
p = &(b[i]);
dst[i] = p;
_MacDZero(p);
}
_MacRet(dst);
}