if (unfolded != NULL) {
oldunfolded = *unfolded;
- *unfolded = concatstr(2, oldunfolded, line);
+ xasprintf(unfolded, "%s%s",
+ oldunfolded != NULL ? oldunfolded : "", line);
free(oldunfolded);
}
chomp(line);
oldretstr = retstr;
- retstr = concatstr(2, oldretstr, line);
+ xasprintf(&retstr, "%s%s",
+ oldretstr != NULL ? oldretstr : "", line);
free(oldretstr);
free(line);
{
thread_list_state *s = (thread_list_state *)state;
int i, j, archivefd, thread_idx;
- char *line, *tmp, *subj, *from;
+ char *line, *tmp, *subj, *from, *tmpfrom;
char *archivename;
int num_threads = 0;
struct thread *threads = NULL;
}
for (i=s->firstindex; i<=s->lastindex; i++) {
-
- snprintf(buf, sizeof(buf), "%d", i);
-
- archivename = concatstr(3, s->listdir, "/archive/", buf);
+ xasprintf(&archivename, "%s/archive/%d", s->listdir, i);
archivefd = open(archivename, O_RDONLY);
free(archivename);
num_threads++;
threads = xrealloc(threads,
num_threads*sizeof(struct thread));
- threads[num_threads-1].subject = concatstr(2,tmp,"\n");
+ xasprintf(&(threads[num_threads-1].subject), "%s\n", tmp);
threads[num_threads-1].num_mails = 0;
threads[num_threads-1].mails = NULL;
thread_idx = num_threads-1;
threads[thread_idx].mails = xrealloc(threads[thread_idx].mails,
threads[thread_idx].num_mails*sizeof(struct mail));
threads[thread_idx].mails[threads[thread_idx].num_mails-1].idx = i;
- threads[thread_idx].mails[threads[thread_idx].num_mails-1].from =
- concatstr(5, " ", buf, " - ", tmp, "\n");
+ xasprintf(&tmpfrom, " %s - %s\n", buf, tmp);
+ threads[thread_idx].mails[threads[thread_idx].num_mails-1].from = tmpfrom;
free(subj);
free(from);
len++;
if (strncasecmp(line, "Subject:", len) == 0) {
tmp = unistr_utf8_to_header(tmp);
- subject = concatstr(2, "Subject: ", tmp);
+ xasprintf(&subject, "Subject: %s", tmp);
free(tmp);
free(line);
return (xstrdup(atsign + 1));
}
-char *concatstr(int count, ...)
-{
- va_list arg;
- const char *str;
- int i;
- size_t len = 0;
- char *retstr;
-
- va_start(arg, count);
-
- for(i = 0; i < count; i++) {
- str = va_arg(arg, const char *);
- if(str)
- len += strlen(str);
- }
-
- retstr = xmalloc(len + 1);
- retstr[0] = retstr[len] = 0;
-
- va_start(arg, count);
-
- for(i = 0; i < count; i++) {
- str = va_arg(arg, const char *);
- if(str)
- strcat(retstr, str);
- }
-
- va_end(arg);
-
- return retstr;
-}
-
char *hostnamestr(void)
{
struct hostent *hostlookup;