
On Thu, Apr 27, 2017 at 09:01:57 +0200, Michal Privoznik wrote:
In the admin/logging.c example, the getopt() function is used but without proper #include. It relies on unistd.h to subsequently include getopt.h. This is not necessarily always the case. Also, opterr is not needed and actually not used anywhere else in our code.
man 3 opterr: * If the caller has set the global variable opterr to zero, then * getopt() does not print an error message. The caller can determine that there was an error by testing whether the function return value is '?'. (By default, opterr has a nonzero value.)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- examples/admin/logging.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/examples/admin/logging.c b/examples/admin/logging.c index 648d7a6..de258c2 100644 --- a/examples/admin/logging.c +++ b/examples/admin/logging.c @@ -1,11 +1,12 @@ -#include<stdio.h> -#include<stdlib.h> -#include<stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h>
#include "config.h" -#include<unistd.h> -#include<libvirt/libvirt-admin.h> -#include<libvirt/virterror.h> +#include <unistd.h> +#include <getopt.h> +#include <libvirt/libvirt-admin.h> +#include <libvirt/virterror.h>
static void printHelp(const char *argv0) { @@ -31,7 +32,6 @@ int main(int argc, char **argv) const char *set_filters = NULL;
ret = c = -1; - opterr = 0;
NACK to this.