bug-coreutils
[Top][All Lists]
Advanced

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

randread: avoid a warning, remove a cast


From: Jim Meyering
Subject: randread: avoid a warning, remove a cast
Date: Fri, 06 Oct 2006 16:37:41 +0200

FYI:

With the very latest gcc, I'm getting a new warning:

  randread.c: In function 'randread_new':
  randread.c:170: warning: passing argument 2 of 'simple_new' discards 
qualifiers f

I've done this to avoid it:

2006-10-06  Jim Meyering  <address@hidden>

        Avoid a compiler warning: const'ify and remove a cast.
        * randread.c (struct randread_source) [handler]: Make parameter "const".
        [handler_arg]: Add "const" attribute.
        (randread_error): Make parameter "const".
        (simple_new, randread_set_handler, randread_set_handler_arg): Likewise.
        (randread_new): Remove now-unnecessary cast.
        * randread.h: Adjust prototypes.

Index: randread.c
===================================================================
RCS file: /fetish/cu/lib/randread.c,v
retrieving revision 1.2
diff -u -r1.2 randread.c
--- randread.c  26 Aug 2006 06:55:58 -0000      1.2
+++ randread.c  6 Oct 2006 14:34:15 -0000
@@ -82,8 +82,8 @@
      there was an error.  If this function returns, it should fix the
      problem before returning.  The default handler assumes that
      handler_arg is the file name of the source.  */
-  void (*handler) (void *);
-  void *handler_arg;
+  void (*handler) (void const *);
+  void const *handler_arg;

   /* The buffer for SOURCE.  It's kept here to simplify storage
      allocation and to make it easier to clear out buffered random
@@ -116,7 +116,7 @@
 /* The default error handler.  */

 static void
-randread_error (void *file_name)
+randread_error (void const *file_name)
 {
   if (file_name)
     error (exit_failure, errno,
@@ -129,7 +129,7 @@
    handler.  */

 static struct randread_source *
-simple_new (FILE *source, void *handler_arg)
+simple_new (FILE *source, void const *handler_arg)
 {
   struct randread_source *s = xmalloc (sizeof *s);
   s->source = source;
@@ -167,7 +167,7 @@
          file_name = NULL;
        }

-      s = simple_new (source, (void *) file_name);
+      s = simple_new (source, file_name);

       if (source)
        setvbuf (source, s->buf.c, _IOFBF, MIN (sizeof s->buf.c, bytes_bound));
@@ -190,13 +190,13 @@
    does not return.  */

 void
-randread_set_handler (struct randread_source *s, void (*handler) (void *))
+randread_set_handler (struct randread_source *s, void (*handler) (void const 
*))
 {
   s->handler = handler;
 }

 void
-randread_set_handler_arg (struct randread_source *s, void *handler_arg)
+randread_set_handler_arg (struct randread_source *s, void const *handler_arg)
 {
   s->handler_arg = handler_arg;
 }
Index: randread.h
===================================================================
RCS file: /fetish/cu/lib/randread.h,v
retrieving revision 1.1
diff -u -r1.1 randread.h
--- randread.h  8 Aug 2006 22:22:47 -0000       1.1
+++ randread.h  6 Oct 2006 14:34:00 -0000
@@ -27,8 +27,8 @@

 struct randread_source *randread_new (char const *, size_t);
 void randread (struct randread_source *, void *, size_t);
-void randread_set_handler (struct randread_source *, void (*) (void *));
-void randread_set_handler_arg (struct randread_source *, void *);
+void randread_set_handler (struct randread_source *, void (*) (void const *));
+void randread_set_handler_arg (struct randread_source *, void const *);
 int randread_free (struct randread_source *);

 #endif




reply via email to

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