main: add support for --silence-errors by redirecting stderr to /dev/null

pull/29/head
William Pitcock 2012-07-21 14:33:07 -05:00
parent 475719ec3a
commit f4d84620a1
2 changed files with 10 additions and 2 deletions

9
main.c
View File

@ -437,6 +437,7 @@ usage(void)
printf(" --atleast-pkgconfig-version check whether or not pkgconf is compatible\n"); printf(" --atleast-pkgconfig-version check whether or not pkgconf is compatible\n");
printf(" with a specified pkg-config version\n"); printf(" with a specified pkg-config version\n");
printf(" --errors-to-stdout print all errors on stdout instead of stderr\n"); printf(" --errors-to-stdout print all errors on stdout instead of stderr\n");
printf(" --silence-errors explicitly be silent about errors\n");
printf("\nchecking specific pkg-config database entries:\n\n"); printf("\nchecking specific pkg-config database entries:\n\n");
@ -482,6 +483,7 @@ main(int argc, char *argv[])
pkg_queue_t *pkgq_head = NULL; pkg_queue_t *pkgq_head = NULL;
char *builddir; char *builddir;
int want_errors_on_stdout = 0; int want_errors_on_stdout = 0;
int want_silence_errors = 1;
struct pkg_option options[] = { struct pkg_option options[] = {
{ "version", no_argument, &want_version, 1, }, { "version", no_argument, &want_version, 1, },
@ -516,6 +518,7 @@ main(int argc, char *argv[])
{ "max-version", required_argument, NULL, 29, }, { "max-version", required_argument, NULL, 29, },
{ "ignore-conflicts", no_argument, &want_ignore_conflicts, 30, }, { "ignore-conflicts", no_argument, &want_ignore_conflicts, 30, },
{ "errors-to-stdout", no_argument, &want_errors_on_stdout, 31, }, { "errors-to-stdout", no_argument, &want_errors_on_stdout, 31, },
{ "silence-errors", no_argument, &want_silence_errors, 32, },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
@ -568,6 +571,8 @@ main(int argc, char *argv[])
error_msgout = stderr; error_msgout = stderr;
if (want_errors_on_stdout) if (want_errors_on_stdout)
error_msgout = stdout; error_msgout = stdout;
if (want_silence_errors)
error_msgout = fopen(PATH_DEV_NULL, "w");
if (want_ignore_conflicts || getenv("PKG_CONFIG_IGNORE_CONFLICTS") != NULL) if (want_ignore_conflicts || getenv("PKG_CONFIG_IGNORE_CONFLICTS") != NULL)
global_traverse_flags |= PKGF_SKIP_CONFLICTS; global_traverse_flags |= PKGF_SKIP_CONFLICTS;
@ -590,12 +595,12 @@ main(int argc, char *argv[])
if ((builddir = getenv("PKG_CONFIG_TOP_BUILD_DIR")) != NULL) if ((builddir = getenv("PKG_CONFIG_TOP_BUILD_DIR")) != NULL)
pkg_tuple_add_global("pc_top_builddir", builddir); pkg_tuple_add_global("pc_top_builddir", builddir);
else else
pkg_tuple_add_global("pc_top_builddir", "$(top_builddir)"); pkg_tuple_add_global("pc_top_builddir", "$(top_builddir)");
if ((sysroot_dir = getenv("PKG_CONFIG_SYSROOT_DIR")) != NULL) if ((sysroot_dir = getenv("PKG_CONFIG_SYSROOT_DIR")) != NULL)
pkg_tuple_add_global("pc_sysrootdir", sysroot_dir); pkg_tuple_add_global("pc_sysrootdir", sysroot_dir);
else else
pkg_tuple_add_global("pc_sysrootdir", "/"); pkg_tuple_add_global("pc_sysrootdir", "/");
if (required_pkgconfig_version != NULL) if (required_pkgconfig_version != NULL)
{ {

View File

@ -28,6 +28,9 @@
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# include <windows.h> # include <windows.h>
# include <malloc.h> # include <malloc.h>
# define PATH_DEV_NULL "nul"
#else
# define PATH_DEV_NULL "/dev/null"
#endif #endif
#endif #endif