OSDN Git Service

wchar_t now gets wrapped inside "ifndef __cplusplus",
[pf3gnuchains/gcc-fork.git] / gcc / fixinc / server.c
index 7287ed9..e58a09f 100644 (file)
@@ -2,7 +2,7 @@
 /*
  *  server.c  Set up and handle communications with a server process.
  *
- *  Server Handling copyright 1992-1999 The Free Software Foundation
+ *  Server Handling copyright 1992-1999, 2001 The Free Software Foundation
  *
  *  Server Handling is free software.
  *  You may redistribute it and/or modify it under the terms of the
  */
 #include "auto-host.h"
 
-#include "gansidecl.h"
+#include "ansidecl.h"
 #include "system.h"
 #include <signal.h>
 
 #include "server.h"
 
-/* If this particular system's header files define the macro `MAXPATHLEN',
-   we happily take advantage of it; otherwise we use a value which ought
-   to be large enough.  */
-#ifndef MAXPATHLEN
-# define MAXPATHLEN     4096
-#endif
-
-#ifndef STDIN_FILENO
-# define STDIN_FILENO  0
-#endif
-#ifndef STDOUT_FILENO
-# define STDOUT_FILENO 1
-#endif
-
-#ifdef DEBUG
-#define STATIC
-#else
-#define STATIC static
-#endif
-#ifndef tSCC
-#define tSCC static const char
-#endif
-#ifndef NUL
-#define NUL '\0'
-#endif
-
 #if !defined(volatile) && !defined(HAVE_VOLATILE)
 # define volatile
 #endif
 
-STATIC volatile t_bool read_pipe_timeout;
+STATIC volatile enum t_bool read_pipe_timeout;
 STATIC pid_t server_master_pid = NOPROCESS;
 
-static t_pchar def_args[] =
+tSCC* def_args[] =
 { (char *) NULL, (char *) NULL };
 STATIC t_pf_pair server_pair =
 { (FILE *) NULL, (FILE *) NULL };
@@ -97,7 +71,7 @@ STATIC pid_t server_id = NULLPROCESS;
  *  the terminating output line.
  */
 tSCC z_done[] = "ShElL-OuTpUt-HaS-bEeN-cOmPlEtEd";
-STATIC t_pchar p_cur_dir = (char *) NULL;
+tSCC* p_cur_dir = (char *) NULL;
 
 /*
  *  load_data
@@ -119,10 +93,7 @@ load_data (fp)
   t_bool got_done = BOOL_FALSE;
 
   text_size = sizeof (z_line) * 2;
-  pz_scan = pz_text = malloc (text_size);
-
-  if (pz_text == (char *) NULL)
-    return (char *) NULL;
+  pz_scan = pz_text = xmalloc (text_size);
 
   for (;;)
     {
@@ -146,18 +117,9 @@ load_data (fp)
       if (text_size - used_ct < sizeof (z_line))
         {
           size_t off = (size_t) (pz_scan - pz_text);
-          void *p;
          
           text_size += 4096;
-          p = realloc ((void *) pz_text, text_size);
-          if (p == (void *) NULL)
-            {
-              fprintf (stderr, "Failed to get 0x%08lX bytes\n",
-                      (long) text_size);
-              free ((void *) pz_text);
-              return (char *) NULL;
-            }
-          pz_text = (char *) p;
+          pz_text = xrealloc ((void *) pz_text, text_size);
           pz_scan = pz_text + off;
         }
     }
@@ -172,7 +134,7 @@ load_data (fp)
   while ((pz_scan > pz_text) && ISSPACE (pz_scan[-1]))
     pz_scan--;
   *pz_scan = NUL;
-  return realloc ((void *) pz_text, strlen (pz_text) + 1);
+  return xrealloc ((void *) pz_text, strlen (pz_text) + 1);
 }
 
 
@@ -257,8 +219,8 @@ server_setup ()
  *  override with $CONFIG_SHELL, so we do the same.
  */
 
-static char *find_shell PARAMS ((void));
-static char *
+static const char *find_shell PARAMS ((void));
+static const char *
 find_shell ()
 {
   char * shell = getenv ("CONFIG_SHELL");
@@ -310,11 +272,8 @@ run_shell (pz_cmd)
   /*  IF it is still not running, THEN return the nil string.  */
   if (server_id <= 0)
     {
-      char *pz = (char *) malloc (1);
       fprintf (stderr, zNoServer, pz_cmd);
-      if (pz != (char *) NULL)
-        *pz = '\0';
-      return pz;
+      return xcalloc (1, 1);
     }
 
   /*  Make sure the process will pay attention to us, send the
@@ -328,11 +287,8 @@ run_shell (pz_cmd)
       THEN return an empty string.  */
   if (server_id == NULLPROCESS)
     {
-      char *pz = (char *) malloc (1);
       fprintf (stderr, zNoServer, pz_cmd);
-      if (pz != (char *) NULL)
-        *pz = '\0';
-      return pz;
+      return xcalloc (1, 1);
     }
 
   /*  Now try to read back all the data.  If we fail due to either a
@@ -352,9 +308,7 @@ run_shell (pz_cmd)
 
         fprintf (stderr, "CLOSING SHELL SERVER - command failure:\n\t%s\n",
                  pz_cmd);
-        pz = (char *) malloc (1);
-        if (pz != (char *) NULL)
-          *pz = '\0';
+        pz = xcalloc (1, 1);
       }
 #ifdef DEBUG
     fprintf( stderr, "run_shell command success:  %s\n", pz );