diff options
author | Mike Frysinger <vapier@gentoo.org> | 2008-11-16 04:11:23 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2008-11-16 04:11:23 +0000 |
commit | a7afc3f309c901c544c1be8ff72d61d2f45137f8 (patch) | |
tree | 4eab2d95921d9663c82af9ab4c5d3be6a4a0b114 /libsbutil/sb_printf.c | |
parent | libsbutil: simple custom printf() replacement (diff) | |
download | sandbox-a7afc3f309c901c544c1be8ff72d61d2f45137f8.tar.gz sandbox-a7afc3f309c901c544c1be8ff72d61d2f45137f8.tar.bz2 sandbox-a7afc3f309c901c544c1be8ff72d61d2f45137f8.zip |
unify SB_E{INFO,WARN,ERROR} functions and have them call the internal sb_printf function
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libsbutil/sb_printf.c')
-rw-r--r-- | libsbutil/sb_printf.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/libsbutil/sb_printf.c b/libsbutil/sb_printf.c index 9d3f819..f17a018 100644 --- a/libsbutil/sb_printf.c +++ b/libsbutil/sb_printf.c @@ -148,3 +148,26 @@ void sb_printf(const char *format, ...) sb_vfdprintf(STDOUT_FILENO, format, args); va_end(args); } + +static bool nocolor, init_color = false; +void sb_efunc(int fd, const char *color, const char *hilight, const char *format, ...) +{ + save_errno(); + + if (!init_color) { + nocolor = is_env_on(ENV_NOCOLOR); + init_color = true; + } + + if (!nocolor) + sb_fdprintf(fd, "%s%s%s", color, hilight, COLOR_NORMAL); + else + sb_fdprintf(fd, "%s", hilight); + + va_list args; + va_start(args, format); + sb_vfdprintf(fd, format, args); + va_end(args); + + restore_errno(); +} |