[JDEV] FIX in io.c

Thomas Charron tcharron at nermail.ups.com
Tue Feb 23 13:13:57 CST 1999


	I just stumbled accross a comment in io.c in the lib/common directory..

/* There has got to be a better way to do this! */
old = c->buff;
c->buff = malloc(strlen(c->buff) + strlen(buffer) + 1);
c->buff[0] = '\0';
strcpy(c->buff, old);
free(old);
strcat(c->buff, buffer);

	There is a better way.. ;-P

realloc(c->buff, strlen(c->buff) + strlen(buffer) + 1);
strcat(c->buff, buffer);

	MUCH prettier, isn't it??  ;-P  Under Unix do a man malloc, it explains
realloc fairly well..  realloc does exactly what you where doing, but in a
much less overhead way..

--
Thomas Charron
United Parcel Service
Northeast Region
IE Software Developer
"Moving at the speed of a T3 Trunk Line!"




More information about the JDev mailing list