#ifndef NULL
#define NULL 0
#endif
/*
* Copyright (C) 1996 by Environmental Systems Research Institute Inc.
* All Rights Reserved.
*
* N O T I C E
*
* THIS MATERIAL IS BEING PRIVIDED TO ARCVIEW GIS USERS BY ESRI.
* UNAUTHORIZED ACCESS IS PROHIBITED
*/
/*
*-------------------------------------------------------------------
*
* CAllocate1 - Allocate a one dimensional array
*
*-------------------------------------------------------------------
*P PURPOSE:
*
* CAllocate1 dynamically allocates a one dimensional array
*
*E
*-------------------------------------------------------------------
*A ARGUMENTS:
*
* number (int) number of elements in array
* size (int) size in bytes of an array element
*
* RETURN VALUE (char *) Pointer to allocated memory
* NULL == allocate failed
*
*E
*-------------------------------------------------------------------
*H HISTORY:
*
*E
*-------------------------------------------------------------------
*/
#include
char *CAllocate1 (int number ,
int size )
{
return (char *)calloc(number, size);
}
/*
*-------------------------------------------------------------------
*
* CAllocate2 - Allocate a two dimensional array
*
*-------------------------------------------------------------------
*P PURPOSE:
*
* CAllocate2 dynamically allocates a two dimensional array
*
*E
*-------------------------------------------------------------------
*A ARGUMENTS:
*
* nrows (int) number of rows in array
* ncols (int) number of cols in array
* size (int) size in bytes of an array element
*
* RETURN VALUE (char **) Pointer to allocated memory
* NULL == allocate failed
*
*E
*-------------------------------------------------------------------
*H HISTORY:
*E
*-------------------------------------------------------------------
*/
char **CAllocate2 (int nrows ,
int ncols ,
int size )
{
char *data;
char **rows;
char **ptr;
int len;
int cur;
int i;
if ((data = (char *)calloc (nrows*ncols, size)) == NULL) {
return (NULL);
}
if ((rows = (char **)calloc (nrows, sizeof(char **))) == NULL) {
free ((char *)data);
return (NULL);
}
ptr = rows;
len = ncols*size;
cur = 0;
for (i=0; i (char *) pointer to space to be freed
*
*E
*-------------------------------------------------------------------
*H HISTORY:
*
*E
*-------------------------------------------------------------------
*/
CFree1 (char *ptr)
{
free(ptr);
}
/*
*-------------------------------------------------------------------
*
* CFree2 - Frees a two dimensional array
*
*-------------------------------------------------------------------
*P PURPOSE:
*
* CFree2 frees a two dimensional array
*
*E
*-------------------------------------------------------------------
*A ARGUMENTS:
*
* ptr (char **) ptr to space to be freed
* nrows (int ) number of rows in array
*
*E
*-------------------------------------------------------------------
*H HISTORY:
*
*E
*-------------------------------------------------------------------
*/
CFree2 (char **ptr,
int nrows)
{
char *h;
int i;
for (i = 1, h = ptr[0]; i < nrows; i++) {
if (h > ptr[i]) {
h = ptr[i];
}
}
free(h); free((char *)ptr);
}