Do locale swapping in the warning()/error() macros themselves instead

of in the underlying functions.
This commit is contained in:
Todd C. Miller
2012-11-25 09:34:15 -05:00
parent 4bde57b8b2
commit 88c6446daf
3 changed files with 130 additions and 36 deletions

View File

@@ -23,10 +23,16 @@
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
# include "compat/stdbool.h"
#endif /* HAVE_STDBOOL_H */
#include "missing.h"
#include "alloc.h"
#include "error.h"
#include "logging.h"
#include "sudo_plugin.h"
#define DEFAULT_TEXT_DOMAIN "sudoers"
@@ -40,7 +46,7 @@ sigjmp_buf error_jmp;
extern sudo_conv_t sudo_conv;
void
error_nodebug(int eval, const char *fmt, ...)
error2(int eval, const char *fmt, ...)
{
va_list ap;
@@ -55,7 +61,7 @@ error_nodebug(int eval, const char *fmt, ...)
}
void
errorx_nodebug(int eval, const char *fmt, ...)
errorx2(int eval, const char *fmt, ...)
{
va_list ap;
@@ -70,7 +76,7 @@ errorx_nodebug(int eval, const char *fmt, ...)
}
void
verror_nodebug(int eval, const char *fmt, va_list ap)
verror2(int eval, const char *fmt, va_list ap)
{
_warning(1, fmt, ap);
sudoers_cleanup(0);
@@ -81,7 +87,7 @@ verror_nodebug(int eval, const char *fmt, va_list ap)
}
void
verrorx_nodebug(int eval, const char *fmt, va_list ap)
verrorx2(int eval, const char *fmt, va_list ap)
{
_warning(0, fmt, ap);
sudoers_cleanup(0);
@@ -92,7 +98,7 @@ verrorx_nodebug(int eval, const char *fmt, va_list ap)
}
void
warning_nodebug(const char *fmt, ...)
warning2(const char *fmt, ...)
{
va_list ap;
@@ -102,7 +108,7 @@ warning_nodebug(const char *fmt, ...)
}
void
warningx_nodebug(const char *fmt, ...)
warningx2(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
@@ -111,13 +117,13 @@ warningx_nodebug(const char *fmt, ...)
}
void
vwarning_nodebug(const char *fmt, va_list ap)
vwarning2(const char *fmt, va_list ap)
{
_warning(1, fmt, ap);
}
void
vwarningx_nodebug(const char *fmt, va_list ap)
vwarningx2(const char *fmt, va_list ap)
{
_warning(0, fmt, ap);
}
@@ -168,3 +174,17 @@ _warning(int use_errno, const char *fmt, va_list ap)
putc('\n', stderr);
}
}
static int oldlocale;
void
warning_set_locale(void)
{
sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale);
}
void
warning_restore_locale(void)
{
sudoers_setlocale(oldlocale, NULL);
}