A
Andrew Fabbro
I have code with stuff like this all over it:
sprintf(errmsg,"somefunc(): %s has illegal character
%c",somestring,somechar);
fatal_error(errmsg);
where fatal_error() just fprintf's to stderr and exits. I'd like to
change the above to something like:
fatal_error("somefunc(): %s has illegal character
%c",somestring,somechar);
to get rid of the sprintf, errmsg variable, etc.
However, in fatal_error, would I have to redo all the work of fprintf
(the parsing of the format and the variables)? If fatal_error's
prototype looks like this:
void fatal_error (const char *format, ...);
is there an easy way to pass the args to fprintf()? So I could do
something like this:
void fatal_error (const char *format, ...) {
fprintf(stderr, format, <some magic to send all the args>);
exit (1);
}
? I realize the code for fprintf is pretty easily available and I
could just copy it, but that doesn't seem right.
Thanks,
-Drew
sprintf(errmsg,"somefunc(): %s has illegal character
%c",somestring,somechar);
fatal_error(errmsg);
where fatal_error() just fprintf's to stderr and exits. I'd like to
change the above to something like:
fatal_error("somefunc(): %s has illegal character
%c",somestring,somechar);
to get rid of the sprintf, errmsg variable, etc.
However, in fatal_error, would I have to redo all the work of fprintf
(the parsing of the format and the variables)? If fatal_error's
prototype looks like this:
void fatal_error (const char *format, ...);
is there an easy way to pass the args to fprintf()? So I could do
something like this:
void fatal_error (const char *format, ...) {
fprintf(stderr, format, <some magic to send all the args>);
exit (1);
}
? I realize the code for fprintf is pretty easily available and I
could just copy it, but that doesn't seem right.
Thanks,
-Drew