Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#8704) Patch: Fix wrong error messages in Windows.
Home

[Freeciv-Dev] (PR#8704) Patch: Fix wrong error messages in Windows.

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: vasc@xxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#8704) Patch: Fix wrong error messages in Windows.
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 12 May 2004 20:01:09 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8704 >

> [vasc - Mon May 10 03:26:09 2004]:

> AFAIK DWORD is a 32-bit int.

DWORD seems to be a long int.  Still 32-bit on my system.

Here's an update of your patch that makes this change.  The only change
is inside the mystrerror() function.

jason

Index: client/clinet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/clinet.c,v
retrieving revision 1.97
diff -u -r1.97 clinet.c
--- client/clinet.c     5 May 2004 20:39:15 -0000       1.97
+++ client/clinet.c     13 May 2004 02:59:44 -0000
@@ -184,13 +184,13 @@
   }
   
   if ((aconnection.sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
-    (void) mystrlcpy(errbuf, mystrerror(errno), errbufsize);
+    (void) mystrlcpy(errbuf, mystrerror(), errbufsize);
     return -1;
   }
 
   if (connect(aconnection.sock, &server_addr.sockaddr,
       sizeof(server_addr)) == -1) {
-    (void) mystrlcpy(errbuf, mystrerror(errno), errbufsize);
+    (void) mystrlcpy(errbuf, mystrerror(), errbufsize);
     my_closesocket(aconnection.sock);
     aconnection.sock = -1;
 #ifdef WIN32_NATIVE
@@ -287,7 +287,7 @@
       }
 
       freelog(LOG_NORMAL, "error in select() return=%d errno=%d (%s)",
-             n, errno, mystrerror(errno));
+             n, errno, mystrerror());
       return -1;
     }
 
@@ -555,12 +555,12 @@
   }
   
   if((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
-    (void) mystrlcpy(errbuf, mystrerror(errno), n_errbuf);
+    (void) mystrlcpy(errbuf, mystrerror(), n_errbuf);
     return NULL;
   }
   
   if(connect(s, &addr.sockaddr, sizeof (addr)) == -1) {
-    (void) mystrlcpy(errbuf, mystrerror(errno), n_errbuf);
+    (void) mystrlcpy(errbuf, mystrerror(), n_errbuf);
     my_closesocket(s);
     return NULL;
   }
@@ -674,13 +674,13 @@
 
   /* Create a socket for broadcasting to servers. */
   if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-    freelog(LOG_ERROR, "socket failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "socket failed: %s", mystrerror());
     return 0;
   }
 
   if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
                  (char *)&opt, sizeof(opt)) == -1) {
-    freelog(LOG_ERROR, "SO_REUSEADDR failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "SO_REUSEADDR failed: %s", mystrerror());
   }
 
   /* Set the UDP Multicast group IP address. */
@@ -694,13 +694,13 @@
   ttl = SERVER_LAN_TTL;
   if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (const char*)&ttl, 
                  sizeof(ttl))) {
-    freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror());
     return 0;
   }
 
   if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (const char*)&opt, 
                  sizeof(opt))) {
-    freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror());
     return 0;
   }
 
@@ -711,7 +711,7 @@
 
   if (sendto(sock, buffer, size, 0, &addr.sockaddr,
       sizeof(addr)) < 0) {
-    freelog(LOG_ERROR, "sendto failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "sendto failed: %s", mystrerror());
     return 0;
   } else {
     freelog(LOG_DEBUG, ("Sending request for server announcement on LAN."));
@@ -721,7 +721,7 @@
 
   /* Create a socket for listening for server packets. */
   if ((socklan = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-    freelog(LOG_ERROR, "socket failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "socket failed: %s", mystrerror());
     return 0;
   }
 
@@ -729,7 +729,7 @@
 
   if (setsockopt(socklan, SOL_SOCKET, SO_REUSEADDR,
                  (char *)&opt, sizeof(opt)) == -1) {
-    freelog(LOG_ERROR, "SO_REUSEADDR failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "SO_REUSEADDR failed: %s", mystrerror());
   }
                                                                                
   memset(&addr, 0, sizeof(addr));
@@ -738,7 +738,7 @@
   addr.sockaddr_in.sin_port = htons(SERVER_LAN_PORT + 1);
 
   if (bind(socklan, &addr.sockaddr, sizeof(addr)) < 0) {
-    freelog(LOG_ERROR, "bind failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "bind failed: %s", mystrerror());
     return 0;
   }
 
@@ -746,7 +746,7 @@
   mreq.imr_interface.s_addr = htonl(INADDR_ANY);
   if (setsockopt(socklan, IPPROTO_IP, IP_ADD_MEMBERSHIP, 
                  (const char*)&mreq, sizeof(mreq)) < 0) {
-    freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror());
     return 0;
   }
 
@@ -789,7 +789,7 @@
   tv.tv_usec = 0;
 
   if (select(socklan + 1, &readfs, NULL, &exceptfs, &tv) == -1) {
-    freelog(LOG_ERROR, "select failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "select failed: %s", mystrerror());
   }
 
   if (!FD_ISSET(socklan, &readfs)) {
Index: server/meta.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/meta.c,v
retrieving revision 1.59
diff -u -r1.59 meta.c
--- server/meta.c       25 Jan 2004 13:55:14 -0000      1.59
+++ server/meta.c       13 May 2004 02:59:45 -0000
@@ -202,7 +202,7 @@
    */
   if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
     freelog(LOG_ERROR, "Metaserver: can't open datagram socket: %s",
-           mystrerror(errno));
+           mystrerror());
     metaserver_failed();
     return;
   }
@@ -219,14 +219,14 @@
 
   /* set source IP */
   if (bind(sockfd, &bind_addr.sockaddr, sizeof(bind_addr)) == -1) {
-    freelog(LOG_ERROR, "Metaserver: bind failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "Metaserver: bind failed: %s", mystrerror());
     metaserver_failed();
     return;
   }
 
   /* no, this is not weird, see man connect(2) --vasc */
   if (connect(sockfd, &meta_addr.sockaddr, sizeof(meta_addr))==-1) {
-    freelog(LOG_ERROR, "Metaserver: connect failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "Metaserver: connect failed: %s", mystrerror());
     metaserver_failed();
     return;
   }
Index: server/sernet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v
retrieving revision 1.118
diff -u -r1.118 sernet.c
--- server/sernet.c     5 May 2004 20:39:16 -0000       1.118
+++ server/sernet.c     13 May 2004 02:59:45 -0000
@@ -715,7 +715,7 @@
   fromlen = sizeof(fromend);
 
   if ((new_sock = accept(sockfd, &fromend.sockaddr, &fromlen)) == -1) {
-    freelog(LOG_ERROR, "accept failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "accept failed: %s", mystrerror());
     return -1;
   }
 
@@ -781,13 +781,13 @@
 
   /* Create socket for client connections. */
   if((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
-    die("socket failed: %s", mystrerror(errno));
+    die("socket failed: %s", mystrerror());
   }
 
   opt=1; 
   if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, 
                (char *)&opt, sizeof(opt)) == -1) {
-    freelog(LOG_ERROR, "SO_REUSEADDR failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "SO_REUSEADDR failed: %s", mystrerror());
   }
 
   if (!net_lookup_service(srvarg.bind_addr, srvarg.port, &src)) {
@@ -797,23 +797,23 @@
   }
 
   if(bind(sock, &src.sockaddr, sizeof (src)) == -1) {
-    freelog(LOG_FATAL, "bind failed: %s", mystrerror(errno));
+    freelog(LOG_FATAL, "bind failed: %s", mystrerror());
     exit(EXIT_FAILURE);
   }
 
   if(listen(sock, MAX_NUM_CONNECTIONS) == -1) {
-    freelog(LOG_FATAL, "listen failed: %s", mystrerror(errno));
+    freelog(LOG_FATAL, "listen failed: %s", mystrerror());
     exit(EXIT_FAILURE);
   }
 
   /* Create socket for server LAN announcements */
   if ((socklan = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-     freelog(LOG_ERROR, "socket failed: %s", mystrerror(errno));
+     freelog(LOG_ERROR, "socket failed: %s", mystrerror());
   }
 
   if (setsockopt(socklan, SOL_SOCKET, SO_REUSEADDR,
                  (char *)&opt, sizeof(opt)) == -1) {
-    freelog(LOG_ERROR, "SO_REUSEADDR failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "SO_REUSEADDR failed: %s", mystrerror());
   }
 
   my_nonblock(socklan);
@@ -826,7 +826,7 @@
   addr.sockaddr_in.sin_port = htons(SERVER_LAN_PORT);
 
   if (bind(socklan, &addr.sockaddr, sizeof(addr)) < 0) {
-    freelog(LOG_ERROR, "bind failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "bind failed: %s", mystrerror());
   }
 
   mreq.imr_multiaddr.s_addr = inet_addr(group);
@@ -834,7 +834,7 @@
 
   if (setsockopt(socklan, IPPROTO_IP, IP_ADD_MEMBERSHIP,
                  (const char*)&mreq, sizeof(mreq)) < 0) {
-    freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror());
   }
 
   close_socket_set_callback(close_socket_callback);
@@ -980,7 +980,7 @@
   tv.tv_usec = 0;
 
   if (select(socklan + 1, &readfs, NULL, &exceptfs, &tv) == -1) {
-    freelog(LOG_ERROR, "select failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "select failed: %s", mystrerror());
   }
 
   if (FD_ISSET(socklan, &readfs)) {
@@ -1019,7 +1019,7 @@
 
   /* Create a socket to broadcast to client. */
   if ((socksend = socket(AF_INET,SOCK_DGRAM, 0)) < 0) {
-    freelog(LOG_ERROR, "socket failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "socket failed: %s", mystrerror());
     return;
   }
 
@@ -1034,13 +1034,13 @@
   ttl = SERVER_LAN_TTL;
   if (setsockopt(socksend, IPPROTO_IP, IP_MULTICAST_TTL, 
                  (const char*)&ttl, sizeof(ttl))) {
-    freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror());
     return;
   }
 
   if (setsockopt(socksend, SOL_SOCKET, SO_BROADCAST, 
                  (const char*)&setting, sizeof(setting))) {
-    freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "setsockopt failed: %s", mystrerror());
     return;
   }
 
@@ -1084,7 +1084,7 @@
   /* Sending packet to client with the information gathered above. */
   if (sendto(socksend, buffer,  size, 0, &addr.sockaddr,
       sizeof(addr)) < 0) {
-    freelog(LOG_ERROR, "sendto failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "sendto failed: %s", mystrerror());
     return;
   }
 
Index: utility/ioz.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ioz.c,v
retrieving revision 1.16
diff -u -r1.16 ioz.c
--- utility/ioz.c       4 Apr 2003 15:47:49 -0000       1.16
+++ utility/ioz.c       13 May 2004 02:59:45 -0000
@@ -297,7 +297,7 @@
       int errnum;
       const char *estr = gzerror(fp->u.zlib, &errnum);
       if (errnum == Z_ERRNO) {
-       retval = mystrerror(errno);
+       retval = mystrerror();
       } else {
        retval = estr;
       }
@@ -305,7 +305,7 @@
     break;
 #endif
   case FZ_PLAIN:
-    retval = mystrerror(errno);
+    retval = mystrerror();
     break;
   default:
     /* Should never happen */
Index: utility/netintf.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/netintf.c,v
retrieving revision 1.20
diff -u -r1.20 netintf.c
--- utility/netintf.c   4 May 2004 16:57:59 -0000       1.20
+++ utility/netintf.c   13 May 2004 02:59:45 -0000
@@ -99,7 +99,7 @@
   WSADATA wsa;
 
   if (WSAStartup(MAKEWORD(1, 1), &wsa) != 0) {
-    freelog(LOG_ERROR, "no usable WINSOCK.DLL: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "no usable WINSOCK.DLL: %s", mystrerror());
   }
 #endif
 
@@ -129,20 +129,20 @@
   int f_set;
 
   if ((f_set=fcntl(sockfd, F_GETFL)) == -1) {
-    freelog(LOG_ERROR, "fcntl F_GETFL failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "fcntl F_GETFL failed: %s", mystrerror());
   }
 
   f_set |= O_NONBLOCK;
 
   if (fcntl(sockfd, F_SETFL, f_set) == -1) {
-    freelog(LOG_ERROR, "fcntl F_SETFL failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "fcntl F_SETFL failed: %s", mystrerror());
   }
 #else
 #ifdef HAVE_IOCTL
   long value=1;
 
   if (ioctl(sockfd, FIONBIO, (char*)&value) == -1) {
-    freelog(LOG_ERROR, "ioctl failed: %s", mystrerror(errno));
+    freelog(LOG_ERROR, "ioctl failed: %s", mystrerror());
   }
 #endif
 #endif
Index: utility/shared.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/shared.c,v
retrieving revision 1.110
diff -u -r1.110 shared.c
--- utility/shared.c    2 May 2004 11:42:24 -0000       1.110
+++ utility/shared.c    13 May 2004 02:59:46 -0000
@@ -919,7 +919,7 @@
                dirs[dir_num]);
       } else {
        freelog(LOG_ERROR, _("Could not read data directory %s: %s."),
-               dirs[dir_num], mystrerror(errno));
+               dirs[dir_num], mystrerror());
       }
       continue;
     }
Index: utility/support.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/support.c,v
retrieving revision 1.27
diff -u -r1.27 support.c
--- utility/support.c   10 Jul 2003 03:34:30 -0000      1.27
+++ utility/support.c   13 May 2004 02:59:46 -0000
@@ -134,16 +134,30 @@
 /***************************************************************
   Return a string which describes a given error (errno-style.)
 ***************************************************************/
-const char *mystrerror(int errnum)
+const char *mystrerror(void)
 {
-#if defined(HAVE_STRERROR)
-  return strerror(errnum);
+#ifdef WIN32_NATIVE
+  static char buf[256];
+  long int error;
+
+  error = GetLastError();
+  if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | 
FORMAT_MESSAGE_IGNORE_INSERTS,
+                    NULL, error, 0, buf, sizeof(buf), NULL)) {
+    my_snprintf(buf, sizeof(buf),
+               _("error %ld (failed FormatMessage)"), error);
+  }
+  return buf;
+#else
+#ifdef HAVE_STRERROR
+  return strerror(errno);
 #else
   static char buf[64];
+
   my_snprintf(buf, sizeof(buf),
-             _("error %d (compiled without strerror)"), errnum);
+             _("error %d (compiled without strerror)"), errno);
   return buf;
 #endif
+#endif
 }
 
 
Index: utility/support.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/support.h,v
retrieving revision 1.18
diff -u -r1.18 support.h
--- utility/support.h   10 Jul 2003 03:34:30 -0000      1.18
+++ utility/support.h   13 May 2004 02:59:46 -0000
@@ -32,7 +32,7 @@
 int mystrcasecmp(const char *str0, const char *str1);
 int mystrncasecmp(const char *str0, const char *str1, size_t n);
 
-const char *mystrerror(int errnum);
+const char *mystrerror(void);
 void myusleep(unsigned long usec);
 
 size_t mystrlcpy(char *dest, const char *src, size_t n);

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