X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Futil.c;h=d43d8def01d7c514a95945a061038812ff866421;hp=eb0ea9af6f8ca2a3718d55c4201087a4b52db99a;hb=b5d427e440402aff987a060ff6ceefcb97117fa4;hpb=16176f3b7ce78da85646e814bd2f3ffe5babb82b diff --git a/src/util.c b/src/util.c index eb0ea9af..d43d8def 100644 --- a/src/util.c +++ b/src/util.c @@ -48,18 +48,19 @@ # define strerror_r(errnum, buf, bufsize) strerror_s(buf, bufsize, errnum) #endif -static size_t utf16le_strlen(const utf16lechar *s) +static size_t +utf16le_strlen(const utf16lechar *s) { const utf16lechar *p = s; while (*p) p++; - return (p - s) / sizeof(utf16lechar); + return (p - s) * sizeof(utf16lechar); } /* Handle %W for UTF16-LE printing and %U for UTF-8 printing. * - * WARNING: this is not yet done properly--- it's assumed that if the format - * string contains %W and/or %U, then it contains no other format specifiers. + * TODO: this is not yet done properly--- it's assumed that if the format string + * contains %W and/or %U, then it contains no other format specifiers. */ static int wimlib_vfprintf(FILE *fp, const char *format, va_list va) @@ -134,17 +135,14 @@ wimlib_fprintf(FILE *fp, const char *format, ...) return ret; } -/* True if wimlib is to print an informational message when an error occurs. - * This can be turned off by calling wimlib_set_print_errors(false). */ -#ifdef ENABLE_ERROR_MESSAGES -#include -static bool wimlib_print_errors = false; - +#if defined(ENABLE_ERROR_MESSAGES) || defined(ENABLE_DEBUG) static void wimlib_vmsg(const char *tag, const char *format, va_list va, bool perror) { +#ifndef DEBUG if (wimlib_print_errors) { +#endif int errno_save = errno; fflush(stdout); fputs(tag, stderr); @@ -161,8 +159,17 @@ wimlib_vmsg(const char *tag, const char *format, } putc('\n', stderr); errno = errno_save; +#ifndef DEBUG } +#endif } +#endif + +/* True if wimlib is to print an informational message when an error occurs. + * This can be turned off by calling wimlib_set_print_errors(false). */ +#ifdef ENABLE_ERROR_MESSAGES +static bool wimlib_print_errors = false; + void wimlib_error(const char *format, ...) @@ -206,6 +213,21 @@ wimlib_warning_with_errno(const char *format, ...) #endif +#ifdef ENABLE_DEBUG +void wimlib_debug(const char *file, int line, const char *func, + const char *format, ...) +{ + + va_list va; + char buf[strlen(file) + strlen(func) + 30]; + + sprintf(buf, "[%s %d] %s(): ", file, line, func); + va_start(va, format); + wimlib_vmsg(buf, format, va, false); + va_end(va); +} +#endif + WIMLIBAPI int wimlib_set_print_errors(bool show_error_messages) {