bootstrap: std:stoul non-portable [PR 98412]
authorNathan Sidwell <nathan@acm.org>
Mon, 21 Dec 2020 17:16:48 +0000 (09:16 -0800)
committerNathan Sidwell <nathan@acm.org>
Mon, 21 Dec 2020 17:20:15 +0000 (09:20 -0800)
Fix some more system-specific issues.  Not everyone's C++11 is the same :(

PR bootstrap/98412
libcody/
* client.cc: Include cstdlib.
* server.cc: Include cstdlib.
gcc/cp/
* mapper-client.cc: INCLUDE_STRING, INCLUDE_VECTOR.
(module_client::open_module_client): Avoid std::stoul.
* mapper-resolver.cc: INCLUDE_STRING, INCLUDE_VECTOR.

gcc/cp/mapper-client.cc
gcc/cp/mapper-resolver.cc
libcody/client.cc
libcody/server.cc

index 2ad770b3d78d1cd2beb62554151a3732d858a635..df821bab7e107094ffec9a6a45267a7795853403 100644 (file)
@@ -24,6 +24,8 @@ along with GCC; see the file COPYING3.  If not see
 // will include it later under the above check
 #include <sys/socket.h>
 #endif
+#define INCLUDE_STRING
+#define INCLUDE_VECTOR
 #include "system.h"
 
 #include "line-map.h"
@@ -171,14 +173,18 @@ module_client::open_module_client (location_t loc, const char *o,
                  }
                else
                  {
+                   char *ptr;
                    if (!from.empty ())
                      {
-                       fd_from = std::stoul (from, &pos, 10);
-                       if (pos != from.size ())
+                       /* Sadly str::stoul is not portable.  */
+                       const char *cstr = from.c_str ();
+                       fd_from = strtoul (cstr, &ptr, 10);
+                       if (*ptr)
                          {
+                           /* Not a number -- a named pipe.  */
                            int dir = to.empty ()
                              ? O_RDWR | O_CLOEXEC : O_RDONLY | O_CLOEXEC;
-                           fd_from = open (from.c_str (), dir);
+                           fd_from = open (cstr, dir);
                          }
                        if (to.empty ())
                          fd_to = fd_from;
@@ -190,12 +196,14 @@ module_client::open_module_client (location_t loc, const char *o,
                      ;
                    else
                      {
-                       fd_to = std::stoul (to, &pos, 10);
-                       if (pos != to.size ())
+                       const char *cstr = to.c_str ();
+                       fd_to = strtoul (cstr, &ptr, 10);
+                       if (*ptr)
                          {
+                           /* Not a number, a named pipe.  */
                            int dir = from.empty ()
                              ? O_RDWR | O_CLOEXEC : O_WRONLY | O_CLOEXEC;
-                           fd_to = open (to.c_str (), dir);
+                           fd_to = open (cstr, dir);
                            if (fd_to < 0)
                              close (fd_from);
                          }
index 53c482441b47de55f0bed60fa38e897f0a9292a6..e348757d99c1b3fc544d51d88471378c34b58b41 100644 (file)
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3.  If not see
 /* Forward to the resolver in c++tools.  */
 
 #include "config.h"
+#define INCLUDE_STRING
+#define INCLUDE_VECTOR
 #define INCLUDE_ALGORITHM
 #include "system.h"
 
index 54111b851d0f139c3694cfd949e847ca04bd6e10..edfe44d34b2562b872e36ae6f8576a175592f44e 100644 (file)
@@ -6,6 +6,7 @@
 #include "internal.hh"
 // C
 #include <cerrno>
+#include <cstdlib>
 #include <cstring>
 
 // Client code
index b9ceec48a68559db1febc2b9373281b0802a8015..e2fa069bb9335042156810d95573caeeabe76ccc 100644 (file)
@@ -8,6 +8,7 @@
 #include <tuple>
 // C
 #include <cerrno>
+#include <cstdlib>
 #include <cstring>
 
 // Server code