saving some strdup() calls

This commit is contained in:
Enno Rehling 2006-01-24 23:19:09 +00:00
parent 779c790f6d
commit fe4ce3261f
2 changed files with 13 additions and 9 deletions

View file

@ -95,10 +95,9 @@ get_keyword(const order * ord)
return ORD_KEYWORD(ord); return ORD_KEYWORD(ord);
} }
char * static char *
getcommand(const order * ord) get_command(const order * ord, char * sbuffer, size_t bufsize)
{ {
char sbuffer[DISPLAYSIZE*2];
char * str = sbuffer; char * str = sbuffer;
const char * text = ORD_STRING(ord); const char * text = ORD_STRING(ord);
#ifdef SHORT_STRINGS #ifdef SHORT_STRINGS
@ -109,7 +108,7 @@ getcommand(const order * ord)
#ifdef SHORT_STRINGS #ifdef SHORT_STRINGS
if (kwd!=NOKEYWORD) { if (kwd!=NOKEYWORD) {
const struct locale * lang = ORD_LOCALE(ord); const struct locale * lang = ORD_LOCALE(ord);
size_t size = sizeof(sbuffer)-(str-sbuffer); size_t size = bufsize-(str-sbuffer);
if (text) --size; if (text) --size;
str += strlcpy(str, LOC(lang, keywords[kwd]), size); str += strlcpy(str, LOC(lang, keywords[kwd]), size);
if (text) { if (text) {
@ -121,7 +120,14 @@ getcommand(const order * ord)
if (text) { if (text) {
str += strlcpy(str, text, sizeof(sbuffer)-(str-sbuffer)); str += strlcpy(str, text, sizeof(sbuffer)-(str-sbuffer));
} }
return strdup(sbuffer); return sbuffer;
}
char *
getcommand(const order * ord)
{
char sbuffer[DISPLAYSIZE*2];
return strdup(get_command(ord, sbuffer, sizeof(sbuffer)));
} }
void void
@ -461,9 +467,7 @@ write_order(const order * ord, const struct locale * lang, char * buffer, size_t
if (kwd==NOKEYWORD) { if (kwd==NOKEYWORD) {
buffer[0]=0; buffer[0]=0;
} else { } else {
char * s = getcommand(ord); get_command(ord, buffer, size);
strncpy(buffer, s, size);
free(s);
} }
} }
return buffer; return buffer;

View file

@ -335,10 +335,10 @@ ri36(FILE * F)
} }
#define MAXLINE 4096*16 #define MAXLINE 4096*16
static char lbuf[MAXLINE];
static char * static char *
getbuf(FILE * F) getbuf(FILE * F)
{ {
char lbuf[MAXLINE];
boolean cont = false; boolean cont = false;
boolean quote = false; boolean quote = false;
boolean comment = false; boolean comment = false;