bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: more gcc warnings


From: Paul Eggert
Subject: Re: more gcc warnings
Date: Fri, 08 Jul 2005 16:03:01 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

address@hidden (Eric Blake) writes:

> ls.c and stty.c use ioctl without including <sys/ioctl.h>,
> triggering a warning about implicit declarations.  Even worse, since
> ioctl is a varargs function, this is undefined C (luckily, it
> compiles and links okay on cygwin).

Thanks for reporting this.  POSIX says that <stropt.h> declares ioctl,
so let's try including that instead.

> id.c calls error (which ultimately gets to the printf family) with a format
> %u for uid_t and gid_t.

%lu should be good enough; id.c uses that elsewhere.  If we run into
hosts where uid_t and gid_t are wider than long int, then we can worry
about it later.  (Such hosts would not conform to pre-2001 POSIX.)

I installed this patch:

2005-07-08  Paul Eggert  <address@hidden>
 
        Fix porting problems reported by Eric Blake.

        * configure.ac: Add check for HAVE_FIONREAD_IN_SYS_IOCTL.
        * m4/jm-macros.m4 (gl_CHECK_ALL_HEADERS): Check for stropt.h.
        * src/cat.c, src/ls.c, src/stty.c: Include stropt.h if available,
        because POSIX says that's where ioctl is declared.
        * src/cat.c: Use HAVE_FIONREAD_IN_SYS_IOCTL instead of _POSIX_SOURCE
        to decide whether to include <sys/ioctl.h>.

        * src/id.c (print_user): Don't assume uid fits in unsigned int.
        (print_group): Likewise, for gid.

Index: configure.ac
===================================================================
RCS file: /fetish/cu/configure.ac,v
retrieving revision 1.57
diff -p -u -r1.57 configure.ac
--- configure.ac        18 May 2005 19:27:39 -0000      1.57
+++ configure.ac        8 Jul 2005 22:49:47 -0000
@@ -244,6 +244,12 @@ if test $jm_cv_sys_tiocgwinsz_needs_term
                    [Define if your system defines TIOCGWINSZ in sys/pty.h.])
 fi
 
+# For src/cat.c.
+AC_CHECK_DECL([FIONREAD],
+  [AC_DEFINE([HAVE_FIONREAD_IN_SYS_IOCTL], 1,
+     [Define to 1 if <sys/ioctl.h> defines FIONREAD.])],
+  [], [#include <sys/ioctl.h>])
+
 # For src/kill.c.
 AC_CHECK_DECLS([strsignal, sys_siglist, _sys_siglist, __sys_siglist], , ,
   [AC_INCLUDES_DEFAULT
Index: m4/jm-macros.m4
===================================================================
RCS file: /fetish/cu/m4/jm-macros.m4,v
retrieving revision 1.224
diff -p -u -r1.224 jm-macros.m4
--- m4/jm-macros.m4     3 Jul 2005 09:30:00 -0000       1.224
+++ m4/jm-macros.m4     8 Jul 2005 22:49:47 -0000
@@ -196,6 +196,7 @@ AC_DEFUN([gl_CHECK_ALL_HEADERS],
     stdlib.h \
     stdint.h \
     string.h \
+    stropt.h \
     sys/filsys.h \
     sys/fs/s5param.h \
     sys/fs_types.h \
Index: src/cat.c
===================================================================
RCS file: /fetish/cu/src/cat.c,v
retrieving revision 1.102
diff -p -u -r1.102 cat.c
--- src/cat.c   16 Jun 2005 21:40:43 -0000      1.102
+++ src/cat.c   8 Jul 2005 22:49:48 -0000
@@ -27,7 +27,10 @@
 #include <stdio.h>
 #include <getopt.h>
 #include <sys/types.h>
-#ifndef _POSIX_SOURCE
+#if HAVE_STROPT_H
+# include <stropt.h>
+#endif
+#if HAVE_FIONREAD_IN_SYS_IOCTL
 # include <sys/ioctl.h>
 #endif
 #include "system.h"
Index: src/id.c
===================================================================
RCS file: /fetish/cu/src/id.c,v
retrieving revision 1.85
diff -p -u -r1.85 id.c
--- src/id.c    30 May 2005 07:33:00 -0000      1.85
+++ src/id.c    8 Jul 2005 22:49:48 -0000
@@ -202,7 +202,8 @@ print_user (uid_t uid)
       pwd = getpwuid (uid);
       if (pwd == NULL)
        {
-         error (0, 0, _("cannot find name for user ID %u"), uid);
+         error (0, 0, _("cannot find name for user ID %lu"),
+                (unsigned long int) uid);
          ok = false;
        }
     }
@@ -225,7 +226,8 @@ print_group (gid_t gid)
       grp = getgrgid (gid);
       if (grp == NULL)
        {
-         error (0, 0, _("cannot find name for group ID %u"), gid);
+         error (0, 0, _("cannot find name for group ID %lu"),
+                (unsigned long int) gid);
          ok = false;
        }
     }
Index: src/ls.c
===================================================================
RCS file: /fetish/cu/src/ls.c,v
retrieving revision 1.392
diff -p -u -r1.392 ls.c
--- src/ls.c    3 Jul 2005 09:31:19 -0000       1.392
+++ src/ls.c    8 Jul 2005 22:49:48 -0000
@@ -60,6 +60,10 @@
 #include <getopt.h>
 #include <signal.h>
 
+#if HAVE_STROPT_H
+# include <stropt.h>
+#endif
+
 /* Use SA_NOCLDSTOP as a proxy for whether the sigaction machinery is
    present.  */
 #ifndef SA_NOCLDSTOP
Index: src/stty.c
===================================================================
RCS file: /fetish/cu/src/stty.c,v
retrieving revision 1.136
diff -p -u -r1.136 stty.c
--- src/stty.c  3 Jul 2005 07:21:03 -0000       1.136
+++ src/stty.c  8 Jul 2005 22:49:48 -0000
@@ -54,6 +54,10 @@
 #include <getopt.h>
 #include <stdarg.h>
 
+#if HAVE_STROPT_H
+# include <stropt.h>
+#endif
+
 #include "system.h"
 #include "error.h"
 #include "fd-reopen.h"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]