root/src/u_calloc.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. u_calloc

   1 
   2 /*     CalculiX - A 3-dimensional finite element program                   */
   3 /*              Copyright (C) 1998-2014 Guido Dhondt                          */
   4 
   5 /*     This program is free software; you can redistribute it and/or     */
   6 /*     modify it under the terms of the GNU General Public License as    */
   7 /*     published by the Free Software Foundation(version 2);    */
   8 /*                    */
   9 
  10 /*     This program is distributed in the hope that it will be useful,   */
  11 /*     but WITHOUT ANY WARRANTY; without even the implied warranty of    */ 
  12 /*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      */
  13 /*     GNU General Public License for more details.                      */
  14 
  15 /*     You should have received a copy of the GNU General Public License */
  16 /*     along with this program; if not, write to the Free Software       */
  17 /*     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         */
  18 
  19 #include <stdio.h>
  20 #include <stdlib.h>
  21 #include "CalculiX.h"
  22 
  23 int log_realloc=-1;
  24 
  25 /*
  26  Diehl program
  27 */
  28 
  29 void *u_calloc(size_t num,size_t size,const char *file,const int line, const char* ptr_name){
  30 
  31     /* allocating num elements of size bytes and initializing them to zero */
  32 
  33   void *a;
  34   char *env;
  35 
  36   if(num==0){
  37     a=NULL;
  38     return(a);
  39   }
  40       
  41   a=calloc(num,size);
  42   if(a==NULL){
  43     printf("*ERROR in u_calloc: error allocating memory\n");
  44     printf("variable=%s, file=%s, line=%d, num=%ld, size=%ld\n",ptr_name,file,line,num,size);
  45     exit(16);
  46   }
  47   else {
  48     if(log_realloc==-1) {
  49       log_realloc=0;
  50       env=getenv("CCX_LOG_ALLOC");
  51       if(env) {log_realloc=atoi(env);}
  52     }      
  53     if(log_realloc==1) {
  54         printf("ALLOCATION of variable %s, file %s, line=%d, num=%ld, size=%ld, address= %ld\n",ptr_name,file,line,num,size,(long int)a);
  55     }      
  56     return(a);
  57   }
  58 }

/* [<][>][^][v][top][bottom][index][help] */