Skip to content

Commit

Permalink
utils: Have logit and logerr call alog to unify their code
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
  • Loading branch information
stefanberger committed May 31, 2021
1 parent 827a86d commit fd00f56
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/utils/swtpm_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,39 @@ void append_to_file(const char *pathname, const char *str)
}
}

void logit(const char *logfile, const char *fmt, ...)
static void alog(FILE *stream, const char *logfile, const char *fmt, va_list ap)
{
char *str = NULL;
va_list ap;
int n;

va_start(ap, fmt);
n = vasprintf(&str, fmt, ap);
va_end(ap);

if (n < 0)
return;

if (logfile == NULL)
fprintf(stdout, "%s", str);
fprintf(stream, "%s", str);
else
append_to_file(logfile, str);

free(str);
}

void logerr(const char *logfile, const char *fmt, ...)
void logit(const char *logfile, const char *fmt, ...)
{
char *str = NULL;
va_list ap;
int n;

va_start(ap, fmt);
n = vasprintf(&str, fmt, ap);
alog(stdout, logfile, fmt, ap);
va_end(ap);
}

if (n < 0)
return;

if (logfile == NULL)
fprintf(stderr, "%s", str);
else
append_to_file(logfile, str);
void logerr(const char *logfile, const char *fmt, ...)
{
va_list ap;

free(str);
va_start(ap, fmt);
alog(stderr, logfile, fmt, ap);
va_end(ap);
}

/* Join paths of up to 3 parts into a pre-allocated buffer. The last part is optional */
Expand Down

0 comments on commit fd00f56

Please sign in to comment.