100,16 → 100,18 |
if( map->next == ( map->size - 1 )){ |
char_map_ref * tmp; |
|
tmp = ( char_map_ref * ) malloc( sizeof( char_map_ref ) * 2 * map->size ); |
tmp = ( char_map_ref * ) realloc( map->items, sizeof( char_map_ref ) * 2 * map->size ); |
if( ! tmp ) return ENOMEM; |
map->size *= 2; |
memcpy( tmp, map->items, sizeof( char_map_ref ) * map->next ); |
free( map->items ); |
map->items = tmp; |
} |
map->items[ map->next ] = ( char_map_ref ) malloc( sizeof( char_map_t )); |
if( ! map->items[ map->next ] ) return ENOMEM; |
char_map_initialize( map->items[ map->next ] ); |
if( char_map_initialize( map->items[ map->next ] ) != EOK ){ |
free( map->items[ map->next ] ); |
map->items[ map->next ] = NULL; |
return ENOMEM; |
} |
map->items[ map->next ]->c = * identifier; |
++ identifier; |
if( length ) -- length; |
132,6 → 134,7 |
char_map_destroy( map->items[ index ] ); |
} |
free( map->items ); |
map->items = NULL; |
} |
} |
|
179,12 → 182,15 |
|
int char_map_initialize( char_map_ref map ){ |
if( ! map ) return EINVAL; |
map->c = 0; |
map->c = '\0'; |
map->value = CHAR_MAP_NULL; |
map->size = 2; |
map->next = 0; |
map->items = malloc( sizeof( char_map_ref ) * map->size ); |
if( ! map->items ) return ENOMEM; |
if( ! map->items ){ |
map->magic = 0; |
return ENOMEM; |
} |
map->items[ map->next ] = NULL; |
map->magic = CHAR_MAP_MAGIC_VALUE; |
return EOK; |