comparison ReadParamsFromFile.c @ 19:740df4b46535

new branch -- for universal -- changed malloc and free -- do PR__start before use
author Sean Halle <seanhalle@yahoo.com>
date Tue, 23 Jul 2013 07:20:05 -0700
parents 93b017e30c76
children 5837ad792168
comparison
equal deleted inserted replaced
7:c72afb3cb906 8:1f1d8ce731b0
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include "Param.h" 11 #include "Param.h"
12 #include "PR__common_includes/Services_offered_by_PR/Memory_Handling/vmalloc__wrapper_library.h"
12 13
13 ParamStruc * makeParamFromStrs( char * type, char *value ); 14 ParamStruc * makeParamFromStrs( char * type, char *value );
14 15
15 #ifndef _GNU_SOURCE 16 #ifndef _GNU_SOURCE
16 #define _GNU_SOURCE 17 #define _GNU_SOURCE
22 getline( char **lineptr, size_t *n, FILE *stream ) 23 getline( char **lineptr, size_t *n, FILE *stream )
23 { 24 {
24 if ( lineptr == NULL || n == NULL) return -1; 25 if ( lineptr == NULL || n == NULL) return -1;
25 if (*lineptr == NULL || *n == 0) 26 if (*lineptr == NULL || *n == 0)
26 { *n = 500; //max length of line in a config file 27 { *n = 500; //max length of line in a config file
27 *lineptr = (char *) malloc( *n ); 28 *lineptr = (char *) PR__malloc( *n );
28 if (*lineptr == NULL) return -1; 29 if (*lineptr == NULL) return -1;
29 } 30 }
30 if( fgets( *lineptr, *n, stream ) ) 31 if( fgets( *lineptr, *n, stream ) )
31 return *n; 32 return *n;
32 else 33 else
43 char* paramType;// = malloc( 12 ); //"double" is the longest type 44 char* paramType;// = malloc( 12 ); //"double" is the longest type
44 char* paramName;// = malloc( 500 ); //max of 500 chars in name 45 char* paramName;// = malloc( 500 ); //max of 500 chars in name
45 char* paramValue;// = malloc( 500 ); //max of 500 chars in value 46 char* paramValue;// = malloc( 500 ); //max of 500 chars in value
46 47
47 lineSz = 500; //max length of line in a config file 48 lineSz = 500; //max length of line in a config file
48 line = (char *) malloc( lineSz ); 49 line = (char *) PR__malloc( lineSz );
49 if( line == NULL ) 50 if( line == NULL )
50 { printf( "\nIn readParamFileIntoBag: no mem for line\n" ); 51 { printf( "\nIn readParamFileIntoBag: no mem for line\n" );
51 return; 52 return;
52 } 53 }
53 54
106 paramStruc = makeParamFromStrs( paramType, paramValue ); 107 paramStruc = makeParamFromStrs( paramType, paramValue );
107 addParamToBag( paramName, paramStruc, bag ); 108 addParamToBag( paramName, paramStruc, bag );
108 } 109 }
109 } 110 }
110 } 111 }
111 free( line ); 112 PR__free( line );
112 } 113 }
113 114