[libvirt] [PATCH 1/4] examples: Properly include getopt.h

Michal Privoznik posted 4 patches 8 years, 9 months ago
[libvirt] [PATCH 1/4] examples: Properly include getopt.h
Posted by Michal Privoznik 8 years, 9 months ago
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.

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;
 
     while ((c = getopt(argc, argv, ":hpo:f:")) > 0) {
         switch (c) {
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/4] examples: Properly include getopt.h
Posted by Peter Krempa 8 years, 9 months ago
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.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list