btrfs-progs: add helper to print messages to stderr

Add similar helper to pr_verbose that prints on stderr, for commands
that need to print to stderr based on the set verbosity level.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2022-10-04 21:03:51 +02:00
parent 964a6377e7
commit c780ab6611
2 changed files with 21 additions and 0 deletions

View File

@ -151,3 +151,21 @@ void error_msg(enum common_error error, const char *msg, ...)
fprintf(stderr, PREFIX_ERROR "%s\n", str);
}
}
/*
* Print a message according to the global verbosity level - to stderr.
*
* level: minimum verbose level at which the message will be printed
*/
__attribute__ ((format (printf, 2, 3)))
void pr_stderr(int level, const char *fmt, ...)
{
va_list args;
if (!should_print(level))
return;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}

View File

@ -130,6 +130,9 @@ void internal_error(const char *fmt, ...);
__attribute__ ((format (printf, 2, 3)))
void pr_verbose(int level, const char *fmt, ...);
__attribute__ ((format (printf, 2, 3)))
void pr_stderr(int level, const char *fmt, ...);
/*
* Commonly used errors
*/