Removing K&R support, part 2

Hrvoje Niksic <[email protected]> Mon, 20 Jun 2005 01:02:15 +0200
Newsgroups gmane.comp.web.wget.patches
Message-ID <[email protected]>
2005-06-20  Hrvoje Niksic  <[email protected]>

	* all: Return type of signal handlers is `void'.  Include signal.h
	unconditionally.

	* all: Don't explicitly cast values returned by malloc.  We no
	longer support ancient compilers that don't declare malloc, and we
	never supported C++ builds.

Index: configure.in
===================================================================
RCS file: /pack/anoncvs/wget/configure.in,v
retrieving revision 1.86
diff -u -r1.86 configure.in
--- configure.in	2005/06/19 22:34:46	1.86
+++ configure.in	2005/06/19 22:59:36
@@ -191,7 +191,6 @@
 AC_TYPE_SIZE_T
 AC_TYPE_PID_T
 AC_CHECK_TYPES(uint32_t)
-AC_TYPE_SIGNAL
 AC_CHECK_TYPES(sig_atomic_t, [], [], [
 #include <stdio.h>
 #include <sys/types.h>
Index: src/convert.c
===================================================================
RCS file: /pack/anoncvs/wget/src/convert.c,v
retrieving revision 1.13
diff -u -r1.13 convert.c
--- src/convert.c	2005/06/19 22:34:51	1.13
+++ src/convert.c	2005/06/19 22:59:53
@@ -382,7 +382,7 @@
     }
 
   /* Construct LINK as explained above. */
-  link = (char *)xmalloc (3 * basedirs + strlen (linkfile) + 1);
+  link = xmalloc (3 * basedirs + strlen (linkfile) + 1);
   for (i = 0; i < basedirs; i++)
     memcpy (link + 3 * i, "../", 3);
   strcpy (link + 3 * i, linkfile);
@@ -985,7 +985,7 @@
       else if (*s == ' ')
 	i += 4;			/* #32; */
     }
-  res = (char *)xmalloc (i + 1);
+  res = xmalloc (i + 1);
   s = b;
   for (p = res; *s; s++)
     {
Index: src/ftp-ls.c
===================================================================
RCS file: /pack/anoncvs/wget/src/ftp-ls.c,v
retrieving revision 1.35
diff -u -r1.35 ftp-ls.c
--- src/ftp-ls.c	2005/06/19 22:34:52	1.35
+++ src/ftp-ls.c	2005/06/19 22:59:54
@@ -330,7 +330,7 @@
 		 default -F output.  I believe these cases are very
 		 rare.  */
 	      fnlen = strlen (tok); /* re-calculate `fnlen' */
-	      cur.name = (char *)xmalloc (fnlen + 1);
+	      cur.name = xmalloc (fnlen + 1);
 	      memcpy (cur.name, tok, fnlen + 1);
 	      if (fnlen)
 		{
@@ -775,14 +775,14 @@
       /* And put everything into the linked list */
       if (!dir)
         {
-          l = dir = (struct fileinfo *)xmalloc (sizeof (struct fileinfo));
+          l = dir = xnew (struct fileinfo);
           memcpy (l, &cur, sizeof (cur));
           l->prev = l->next = NULL;
         }
       else
         {
           cur.prev = l;
-          l->next = (struct fileinfo *)xmalloc (sizeof (struct fileinfo));
+          l->next = xnew (struct fileinfo);
           l = l->next;
           memcpy (l, &cur, sizeof (cur));
           l->next = NULL;
Index: src/hash.c
===================================================================
RCS file: /pack/anoncvs/wget/src/hash.c,v
retrieving revision 1.41
diff -u -r1.41 hash.c
--- src/hash.c	2005/06/19 22:34:53	1.41
+++ src/hash.c	2005/06/19 22:59:56
@@ -1,5 +1,5 @@
 /* Hash tables.
-   Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 2000-2003 Free Software Foundation, Inc.
 
 This file is part of GNU Wget.
 
@@ -48,8 +48,7 @@
 /* Make do without them. */
 # define xnew(x) xmalloc (sizeof (x))
 # define xnew_array(type, x) xmalloc (sizeof (type) * (x))
-# define xmalloc malloc		/* or something that exits
-				   if not enough memory */
+# define xmalloc malloc
 # define xfree free
 # define countof(x) (sizeof (x) / sizeof ((x)[0]))
 # define TOLOWER(x) ('A' <= (x) && (x) <= 'Z' ? (x) - 32 : (x))
Index: src/html-parse.c
===================================================================
RCS file: /pack/anoncvs/wget/src/html-parse.c,v
retrieving revision 1.24
diff -u -r1.24 html-parse.c
--- src/html-parse.c	2005/06/19 22:34:53	1.24
+++ src/html-parse.c	2005/06/19 22:59:58
@@ -241,7 +241,7 @@
   if (ga_newsize != (sizevar))							\
     {										\
       if (resized)								\
-	basevar = (type *)xrealloc (basevar, ga_newsize * sizeof (type));	\
+	basevar = xrealloc (basevar, ga_newsize * sizeof (type));		\
       else									\
 	{									\
 	  void *ga_new = xmalloc (ga_newsize * sizeof (type));			\
@@ -1051,7 +1051,7 @@
 int main ()
 {
   int size = 256;
-  char *x = (char *)xmalloc (size);
+  char *x = xmalloc (size);
   int length = 0;
   int read_count;
   int tag_counter = 0;
@@ -1060,7 +1060,7 @@
     {
       length += read_count;
       size <<= 1;
-      x = (char *)xrealloc (x, size);
+      x = xrealloc (x, size);
     }
 
   map_html_tags (x, length, test_mapper, &tag_counter, 0, NULL, NULL);
Index: src/http.c
===================================================================
RCS file: /pack/anoncvs/wget/src/http.c,v
retrieving revision 1.194
diff -u -r1.194 http.c
--- src/http.c	2005/06/19 22:34:54	1.194
+++ src/http.c	2005/06/19 23:00:02
@@ -2870,14 +2870,14 @@
     gen_md5_finish (ctx, hash);
     dump_hash (response_digest, hash);
 
-    res = (char*) xmalloc (strlen (user)
-			   + strlen (user)
-			   + strlen (realm)
-			   + strlen (nonce)
-			   + strlen (path)
-			   + 2 * MD5_HASHLEN /*strlen (response_digest)*/
-			   + (opaque ? strlen (opaque) : 0)
-			   + 128);
+    res = xmalloc (strlen (user)
+		   + strlen (user)
+		   + strlen (realm)
+		   + strlen (nonce)
+		   + strlen (path)
+		   + 2 * MD5_HASHLEN /*strlen (response_digest)*/
+		   + (opaque ? strlen (opaque) : 0)
+		   + 128);
     sprintf (res, "Digest \
 username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", response=\"%s\"",
 	     user, realm, nonce, path, response_digest);
Index: src/log.c
===================================================================
RCS file: /pack/anoncvs/wget/src/log.c,v
retrieving revision 1.32
diff -u -r1.32 log.c
--- src/log.c	2005/06/19 22:34:54	1.32
+++ src/log.c	2005/06/19 23:00:04
@@ -208,7 +208,7 @@
 	    {
 	      /* Allocate memory and concatenate the old and the new
                  contents. */
-	      ln->malloced_line = (char *)xmalloc (old_len + len + 1);
+	      ln->malloced_line = xmalloc (old_len + len + 1);
 	      memcpy (ln->malloced_line, ln->static_line,
 		      old_len);
 	      memcpy (ln->malloced_line + old_len, start, len);
Index: src/main.c
===================================================================
RCS file: /pack/anoncvs/wget/src/main.c,v
retrieving revision 1.139
diff -u -r1.139 main.c
--- src/main.c	2005/06/19 22:34:55	1.139
+++ src/main.c	2005/06/19 23:00:05
@@ -35,9 +35,7 @@
 # include <unistd.h>
 #endif /* HAVE_UNISTD_H */
 #include <string.h>
-#ifdef HAVE_SIGNAL_H
-# include <signal.h>
-#endif
+#include <signal.h>
 #ifdef HAVE_NLS
 #ifdef HAVE_LOCALE_H
 # include <locale.h>
@@ -70,7 +68,7 @@
 
 extern struct cookie_jar *wget_cookie_jar;
 
-static RETSIGTYPE redirect_output_signal (int);
+static void redirect_output_signal (int);
 
 const char *exec_name;
 
@@ -993,13 +991,9 @@
 #ifdef HAVE_SIGNAL
 /* Hangup signal handler.  When wget receives SIGHUP or SIGUSR1, it
    will proceed operation as usual, trying to write into a log file.
-   If that is impossible, the output will be turned off.
-
-   #### It is unsafe to do call libc functions from a signal handler.
-   What we should do is, set a global variable, and have the code in
-   log.c pick it up.  */
+   If that is impossible, the output will be turned off.  */
 
-static RETSIGTYPE
+static void
 redirect_output_signal (int sig)
 {
   const char *signal_name = (sig == SIGHUP ? "SIGHUP" :
Index: src/mswindows.c
===================================================================
RCS file: /pack/anoncvs/wget/src/mswindows.c,v
retrieving revision 1.42
diff -u -r1.42 mswindows.c
--- src/mswindows.c	2005/06/19 22:34:55	1.42
+++ src/mswindows.c	2005/06/19 23:00:07
@@ -499,7 +499,7 @@
 {
   xfree_null (title_buf);
   xfree_null (curr_url);
-  title_buf = (char *)xmalloc (strlen (url) + 20);
+  title_buf = xmalloc (strlen (url) + 20);
   curr_url = xstrdup (url);
   old_percentage = -1;
   sprintf (title_buf, "Wget %s", curr_url);
Index: src/netrc.c
===================================================================
RCS file: /pack/anoncvs/wget/src/netrc.c,v
retrieving revision 1.20
diff -u -r1.20 netrc.c
--- src/netrc.c	2005/06/19 22:34:55	1.20
+++ src/netrc.c	2005/06/19 23:00:07
@@ -164,7 +164,7 @@
 {
   int length = 0;
   int bufsize = 81;
-  char *line = (char *)xmalloc (bufsize);
+  char *line = xmalloc (bufsize);
 
   while (fgets (line + length, bufsize - length, fp))
     {
@@ -220,7 +220,7 @@
 	}
 
       /* Allocate a new acc_t structure.  */
-      a = (acc_t *)xmalloc (sizeof (acc_t));
+      a = xmalloc (sizeof (acc_t));
     }
 
   /* Zero the structure, so that it is ready to use.  */
Index: src/progress.c
===================================================================
RCS file: /pack/anoncvs/wget/src/progress.c,v
retrieving revision 1.48
diff -u -r1.48 progress.c
--- src/progress.c	2005/06/19 22:34:55	1.48
+++ src/progress.c	2005/06/19 23:00:09
@@ -36,9 +36,7 @@
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
-#ifdef HAVE_SIGNAL_H
-# include <signal.h>
-#endif
+#include <signal.h>
 
 #include "wget.h"
 #include "progress.h"
@@ -956,7 +954,7 @@
 }
 
 #ifdef SIGWINCH
-RETSIGTYPE
+void
 progress_handle_sigwinch (int sig)
 {
   received_sigwinch = 1;
Index: src/progress.h
===================================================================
RCS file: /pack/anoncvs/wget/src/progress.h,v
retrieving revision 1.9
diff -u -r1.9 progress.h
--- src/progress.h	2005/06/19 22:34:55	1.9
+++ src/progress.h	2005/06/19 23:00:09
@@ -39,6 +39,6 @@
 void progress_update (void *, wgint, double);
 void progress_finish (void *, double);
 
-RETSIGTYPE progress_handle_sigwinch (int);
+void progress_handle_sigwinch (int);
 
 #endif /* PROGRESS_H */
Index: src/url.c
===================================================================
RCS file: /pack/anoncvs/wget/src/url.c,v
retrieving revision 1.131
diff -u -r1.131 url.c
--- src/url.c	2005/06/19 22:34:57	1.131
+++ src/url.c	2005/06/19 23:00:12
@@ -205,7 +205,7 @@
     return allow_passthrough ? (char *)s : xstrdup (s);
 
   newlen = (p1 - s) + addition;
-  newstr = (char *)xmalloc (newlen + 1);
+  newstr = xmalloc (newlen + 1);
 
   p1 = s;
   p2 = newstr;
@@ -984,7 +984,7 @@
 url_full_path (const struct url *url)
 {
   int length = full_path_length (url);
-  char *full_path = (char *) xmalloc (length + 1);
+  char *full_path = xmalloc (length + 1);
 
   full_path_write (url, full_path);
   full_path[length] = '\0';
@@ -1692,7 +1692,7 @@
 	start_insert = base;
 
       span = start_insert - base;
-      merge = (char *)xmalloc (span + linklength + 1);
+      merge = xmalloc (span + linklength + 1);
       if (span)
 	memcpy (merge, base, span);
       memcpy (merge + span, link, linklength);
@@ -1747,7 +1747,7 @@
 	start_insert = slash;
 
       span = start_insert - base;
-      merge = (char *)xmalloc (span + linklength + 1);
+      merge = xmalloc (span + linklength + 1);
       if (span)
 	memcpy (merge, base, span);
       memcpy (merge + span, link, linklength);
@@ -1785,7 +1785,7 @@
 	}
 
       span = start_insert - base;
-      merge = (char *)xmalloc (span + linklength + 1);
+      merge = xmalloc (span + linklength + 1);
       if (span)
 	memcpy (merge, base, span);
       if (need_explicit_slash)
Index: src/utils.c
===================================================================
RCS file: /pack/anoncvs/wget/src/utils.c,v
retrieving revision 1.101
diff -u -r1.101 utils.c
--- src/utils.c	2005/06/19 22:34:57	1.101
+++ src/utils.c	2005/06/19 23:00:15
@@ -45,9 +45,6 @@
 #ifdef HAVE_PWD_H
 # include <pwd.h>
 #endif
-#ifdef HAVE_LIMITS_H
-# include <limits.h>
-#endif
 #ifdef HAVE_UTIME_H
 # include <utime.h>
 #endif
@@ -71,10 +68,7 @@
 #endif
 
 /* Needed for run_with_timeout. */
-#undef USE_SIGNAL_TIMEOUT
-#ifdef HAVE_SIGNAL_H
-# include <signal.h>
-#endif
+#include <signal.h>
 #ifdef HAVE_SETJMP_H
 # include <setjmp.h>
 #endif
@@ -86,13 +80,11 @@
 # endif
 #endif
 
+#undef USE_SIGNAL_TIMEOUT
 #ifdef HAVE_SIGNAL
-# ifdef HAVE_SIGSETJMP
+# if defined(HAVE_SIGSETJMP) || defined(HAVE_SIGBLOCK)
 #  define USE_SIGNAL_TIMEOUT
 # endif
-# ifdef HAVE_SIGBLOCK
-#  define USE_SIGNAL_TIMEOUT
-# endif
 #endif
 
 #include "wget.h"
@@ -117,7 +109,7 @@
 char *
 strdupdelim (const char *beg, const char *end)
 {
-  char *res = (char *)xmalloc (end - beg + 1);
+  char *res = xmalloc (end - beg + 1);
   memcpy (res, beg, end - beg);
   res[end - beg] = '\0';
   return res;
@@ -141,7 +133,7 @@
     {
       if (*s == ',')
 	{
-	  res = (char **)xrealloc (res, (i + 2) * sizeof (char *));
+	  res = xrealloc (res, (i + 2) * sizeof (char *));
 	  res[i] = strdupdelim (p, s);
 	  res[++i] = NULL;
 	  ++s;
@@ -153,7 +145,7 @@
       else
 	++s;
     }
-  res = (char **)xrealloc (res, (i + 2) * sizeof (char *));
+  res = xrealloc (res, (i + 2) * sizeof (char *));
   res[i] = strdupdelim (p, s);
   res[i + 1] = NULL;
   return res;
@@ -616,7 +608,7 @@
   if (!cut)
     return xstrdup (file);
 
-  result = (char *)xmalloc (cut - base + 1 + strlen (file) + 1);
+  result = xmalloc (cut - base + 1 + strlen (file) + 1);
   memcpy (result, base, cut - base);
   result[cut - base] = '/';
   strcpy (result + (cut - base) + 1, file);
@@ -853,7 +845,7 @@
 {
   int length = 0;
   int bufsize = 82;
-  char *line = (char *)xmalloc (bufsize);
+  char *line = xmalloc (bufsize);
 
   while (fgets (line + length, bufsize - length, fp))
     {
@@ -1065,7 +1057,7 @@
   /* Count v2.  */
   for (j = 0; v2[j]; j++);
   /* Reallocate v1.  */
-  v1 = (char **)xrealloc (v1, (i + j + 1) * sizeof (char **));
+  v1 = xrealloc (v1, (i + j + 1) * sizeof (char **));
   memcpy (v1 + i, v2, (j + 1) * sizeof (char *));
   xfree (v2);
   return v1;
@@ -1633,7 +1625,7 @@
 
 static sigjmp_buf run_with_timeout_env;
 
-static RETSIGTYPE
+static void
 abort_run_with_timeout (int sig)
 {
   assert (sig == SIGALRM);
@@ -1644,7 +1636,7 @@
 
 static jmp_buf run_with_timeout_env;
 
-static RETSIGTYPE
+static void
 abort_run_with_timeout (int sig)
 {
   assert (sig == SIGALRM);
Index: src/wget.h
===================================================================
RCS file: /pack/anoncvs/wget/src/wget.h,v
retrieving revision 1.60
diff -u -r1.60 wget.h
--- src/wget.h	2005/06/19 22:34:57	1.60
+++ src/wget.h	2005/06/19 23:00:16
@@ -213,7 +213,7 @@
     (sizevar) = DR_newsize;						\
   }									\
   if (DR_newsize)							\
-    basevar = (type *)xrealloc (basevar, DR_newsize * sizeof (type));	\
+    basevar = xrealloc (basevar, DR_newsize * sizeof (type));		\
 } while (0)
 
 /* Used to print pointers (usually for debugging).  Print pointers
Index: src/xmalloc.h
===================================================================
RCS file: /pack/anoncvs/wget/src/xmalloc.h,v
retrieving revision 1.7
diff -u -r1.7 xmalloc.h
--- src/xmalloc.h	2005/06/19 22:34:58	1.7
+++ src/xmalloc.h	2005/06/19 23:00:16
@@ -83,10 +83,10 @@
    necessary in standard C, but Wget performs them anyway for the sake
    of pre-standard environments and possibly C++.  */
 
-#define xnew(type) ((type *) xmalloc (sizeof (type)))
-#define xnew0(type) ((type *) xmalloc0 (sizeof (type)))
-#define xnew_array(type, len) ((type *) xmalloc ((len) * sizeof (type)))
-#define xnew0_array(type, len) ((type *) xmalloc0 ((len) * sizeof (type)))
+#define xnew(type) (xmalloc (sizeof (type)))
+#define xnew0(type) (xmalloc0 (sizeof (type)))
+#define xnew_array(type, len) (xmalloc ((len) * sizeof (type)))
+#define xnew0_array(type, len) (xmalloc0 ((len) * sizeof (type)))
 
 #define alloca_array(type, size) ((type *) alloca ((size) * sizeof (type)))