Lines 14-34
Link Here
|
14 |
You should have received a copy of the GNU General Public License |
14 |
You should have received a copy of the GNU General Public License |
15 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 |
*/ |
16 |
*/ |
17 |
|
|
|
18 |
#include <stdlib.h> |
17 |
#include <stdlib.h> |
19 |
#include <string.h> |
18 |
#include <string.h> |
20 |
|
19 |
|
21 |
#include "carg_parser.h" |
20 |
#include "carg_parser.h" |
22 |
|
21 |
|
23 |
|
|
|
24 |
/* assure at least a minimum size for buffer `buf' */ |
22 |
/* assure at least a minimum size for buffer `buf' */ |
25 |
char ap_resize_buffer( void *buf, const int min_size ) |
23 |
char ap_resize_buffer( void **buf, const int min_size ) |
26 |
{ |
24 |
{ |
27 |
void *new_buf = 0; |
25 |
void *old_buf = *buf; |
28 |
if( *(void **)buf ) new_buf = realloc( *(void **)buf, min_size ); |
26 |
*buf = realloc(*buf, min_size); |
29 |
else new_buf = malloc( min_size ); |
27 |
if (*buf == NULL) { |
30 |
if( !new_buf ) return 0; |
28 |
*buf = old_buf; |
31 |
*(void **)buf = new_buf; |
29 |
return 0; |
|
|
30 |
} |
32 |
return 1; |
31 |
return 1; |
33 |
} |
32 |
} |
34 |
|
33 |
|