root/src/u_realloc.c

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

DEFINITIONS

This source file includes following definitions.
  1. u_realloc

   1 
   2 /*     CalculiX - A 3-dimensional finite element program                   */
   3 /*              Copyright (C) 1998-2015 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 extern int log_realloc;
  23 
  24 /*
  25  Diehl program
  26 */
  27 
  28 void *u_realloc(void* ptr,size_t size,const char *file,const int line, const char* ptr_name){
  29 
  30     /* reallocating a field with pointer ptr to size bytes */
  31 
  32   void *a;
  33   char *env;
  34 
  35   a=realloc(ptr,size);
  36 
  37   if(a==NULL && ptr!=NULL && size!=0){
  38     printf("*ERROR in u_realloc: error allocating memory\n");
  39     printf("variable=%s, file=%s, line=%d, size(bytes)=%ld, oldaddress=%ld\n",ptr_name,file,line,size,(long int)ptr);
  40     exit(16);
  41   }
  42   else {
  43     if(log_realloc==-1) {
  44       log_realloc=0;
  45       env=getenv("CCX_LOG_ALLOC");
  46       if(env) {log_realloc=atoi(env);}
  47     }      
  48     if(log_realloc==1) {
  49       printf("REALLOCATION of variable %s, file %s, line=%d: size(bytes)=%ld, oldaddress= %ld,address= %ld\n",ptr_name,file,line,size,(long int)ptr,(long int)a);
  50     }      
  51     return(a);
  52   }
  53 }

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