| 23 |
|
char *cp; |
| 24 |
|
char *newp; |
| 25 |
|
|
| 26 |
+ |
if (s == NULL) |
| 27 |
+ |
return(NULL); |
| 28 |
+ |
if (!*s) |
| 29 |
+ |
return(""); |
| 30 |
|
for (cp = s; *cp++; ) /* compute strlen()+1 */ |
| 31 |
|
; |
| 32 |
|
newp = (char *)malloc(cp-s); |
| 34 |
|
eputs("out of memory in savqstr"); |
| 35 |
|
quit(1); |
| 36 |
|
} |
| 37 |
< |
for (cp = newp; (*cp++ = *s++); ) /* inline strcpy() */ |
| 37 |
> |
for (cp = newp; (*cp++ = *s++); ) /* inline strcpy() */ |
| 38 |
|
; |
| 39 |
|
return(newp); /* return new location */ |
| 40 |
|
} |
| 43 |
|
void |
| 44 |
|
freeqstr(char *s) /* free a private string */ |
| 45 |
|
{ |
| 46 |
< |
if (s != NULL) |
| 47 |
< |
free((void *)s); |
| 46 |
> |
if (s != NULL && *s) |
| 47 |
> |
free(s); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
#else |
| 82 |
|
char *cp; |
| 83 |
|
unsigned n; |
| 84 |
|
|
| 85 |
+ |
if (s == NULL) |
| 86 |
+ |
return(NULL); |
| 87 |
+ |
if (!*s) |
| 88 |
+ |
return(""); |
| 89 |
|
for (cp = s; *cp++; ) /* compute strlen()+1 */ |
| 90 |
|
; |
| 91 |
|
if ((n = cp-s) > nrem) { /* do we need more core? */ |
| 92 |
|
bfree(curp, nrem); /* free remnant */ |
| 93 |
|
while (n > nextalloc) |
| 94 |
|
nextalloc <<= 1; |
| 95 |
< |
if ((curp = bmalloc(nrem=nextalloc)) == NULL) { |
| 95 |
> |
if ((curp = (char *)bmalloc(nrem=nextalloc)) == NULL) { |
| 96 |
|
eputs("out of memory in savqstr"); |
| 97 |
|
quit(1); |
| 98 |
|
} |
| 111 |
|
void |
| 112 |
|
freeqstr(char *s) /* free a private string (not recommended) */ |
| 113 |
|
{ |
| 114 |
< |
bfree(s, strlen(s)+1); |
| 114 |
> |
if (s != NULL && *s) |
| 115 |
> |
bfree(s, strlen(s)+1); |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
#endif |