]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - sunrpc/rpc_main.c
.
[thirdparty/glibc.git] / sunrpc / rpc_main.c
index 6cdef73d7989c5ac086831751e19390a255f10f1..954657a7e4aad69e911a717dba8753e42c09c7d3 100644 (file)
@@ -31,8 +31,6 @@
 /*
  * From @(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI;
  */
-const char main_rcsid[] =
-  "$Id$";
 
 /*
  * rpc_main.c, Top level of the RPC protocol compiler.
@@ -42,6 +40,7 @@ const char main_rcsid[] =
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <libintl.h>
 #include <ctype.h>
 #include <sys/types.h>
 #include <sys/param.h>
@@ -79,14 +78,14 @@ static const char *cmdname;
 #define SUNOS_CPP "/lib/cpp"
 
 static const char *svcclosetime = "120";
-static int cppDefined = 0;     /* explicit path for C preprocessor */
+static int cppDefined; /* explicit path for C preprocessor */
 static const char *CPP = SUNOS_CPP;
-static char CPPFLAGS[] = "-C";
+static const char CPPFLAGS[] = "-C";
 static char *pathbuf;
 static int cpp_pid;
 static const char *allv[] =
 {
-  "rpcgen", "-s", "udp", "-s", "tcp",
+  "rpcgen", "-s", "udp", "-s", "tcp"
 };
 static int allc = sizeof (allv) / sizeof (allv[0]);
 static const char *allnv[] =
@@ -133,8 +132,8 @@ static void addarg (const char *cp);
 static void putarg (int whereto, const char *cp);
 static void checkfiles (const char *infile, const char *outfile);
 static int parseargs (int argc, const char *argv[], struct commandline *cmd);
-static void usage (void);
-static void options_usage (void);
+static void usage (void) __attribute__ ((noreturn));
+static void options_usage (void) __attribute__ ((noreturn));
 static void c_initialize (void);
 static char *generate_guard (const char *pathname);
 
@@ -166,17 +165,17 @@ int newstyle;                     /* newstyle of passing arguments (by value) */
 #ifdef __GNU_LIBRARY__
 int Cflag = 1;                 /* ANSI C syntax */
 #else
-int Cflag = 0;                 /* ANSI C/C++ syntax */
+int Cflag;                     /* ANSI C/C++ syntax */
 #endif
-int CCflag = 0;                        /* C++ files */
+int CCflag;                    /* C++ files */
 static int allfiles;           /* generate all files */
 #ifdef __GNU_LIBRARY__
-int tirpcflag = 0;             /* generating code for tirpc, by default */
+int tirpcflag;                 /* generating code for tirpc, by default */
 #else
 int tirpcflag = 1;             /* generating code for tirpc, by default */
 #endif
-xdrfunc *xdrfunc_head = NULL;  /* xdr function list */
-xdrfunc *xdrfunc_tail = NULL;  /* xdr function list */
+xdrfunc *xdrfunc_head;         /* xdr function list */
+xdrfunc *xdrfunc_tail;         /* xdr function list */
 
 int
 main (int argc, const char *argv[])
@@ -246,8 +245,8 @@ main (int argc, const char *argv[])
          mkfile_output (&cmd);
        }
     }
-  exit (nonfatalerrors);
-  /* NOTREACHED */
+
+  return nonfatalerrors;
 }
 
 /*
@@ -291,8 +290,7 @@ open_output (const char *infile, const char *outfile)
   fout = fopen (outfile, "w");
   if (fout == NULL)
     {
-      fprintf (stderr, _ ("%s: unable to open "), cmdname);
-      perror (outfile);
+      fprintf (stderr, _ ("%s: unable to open %s: %m\n"), cmdname, outfile);
       crash ();
     }
   record_open (outfile);
@@ -304,8 +302,8 @@ close_output (const char *outfile)
 {
   if (fclose (fout) == EOF)
     {
-      fprintf (stderr, _("%s: while writing output: "), cmdname);
-      perror (outfile ?: "<stdout>");
+      fprintf (stderr, _("%s: while writing output %s: %m"), cmdname,
+              outfile ?: "<stdout>");
       crash ();
     }
 }
@@ -459,7 +457,7 @@ check_nettype (const char *name, const char *list_to_check[])
          return 1;
        }
     }
-  fprintf (stderr, _ ("illegal nettype :\'%s\'\n"), name);
+  fprintf (stderr, _ ("illegal nettype :`%s'\n"), name);
   return 0;
 }
 
@@ -533,7 +531,7 @@ generate_guard (const char *pathname)
 
   filename = strrchr (pathname, '/');  /* find last component */
   filename = ((filename == NULL) ? pathname : filename + 1);
-  guard = strdup (filename);
+  guard = extendfile (filename, "_H_RPCGEN");
   /* convert to upper case */
   tmp = guard;
   while (*tmp)
@@ -543,7 +541,6 @@ generate_guard (const char *pathname)
       tmp++;
     }
 
-  guard = extendfile (guard, "_H_RPCGEN");
   return guard;
 }
 
@@ -663,6 +660,7 @@ h_output (const char *infile, const char *define, int extend,
     }
 
   fprintf (fout, "\n#endif /* !_%s */\n", guard);
+  free (guard);
   close_input ();
   close_output (outfilename);
 }
@@ -693,11 +691,9 @@ s_output (int argc, const char *argv[], const char *infile, const char *define,
 
   fprintf (fout, "#include <stdio.h>\n");
   fprintf (fout, "#include <stdlib.h>\n");
+  fprintf (fout, "#include <rpc/pmap_clnt.h>\n");
   if (Cflag)
-    {
-      fprintf (fout, "#include <rpc/pmap_clnt.h>\n");
-      fprintf (fout, "#include <string.h>\n");
-    }
+    fprintf (fout, "#include <string.h>\n");
   if (strcmp (svcclosetime, "-1") == 0)
     indefinitewait = 1;
   else if (strcmp (svcclosetime, "0") == 0)
@@ -950,6 +946,8 @@ clnt_output (const char *infile, const char *define, int extend,
   close_output (outfilename);
 }
 
+static const char space[] = " ";
+
 static char *
 file_name (const char *file, const char *ext)
 {
@@ -958,17 +956,17 @@ file_name (const char *file, const char *ext)
 
   if (access (temp, F_OK) != -1)
     return (temp);
-  else
-    return ((char *) " ");
+
+  free (temp);
+  return (char *) space;
 }
 
 static void
 mkfile_output (struct commandline *cmd)
 {
   char *mkfilename;
-  const char *clientname, *clntname, *xdrname, *hdrname;
-  const char *servername, *svcname, *servprogname, *clntprogname;
-  char *temp;
+  char *clientname, *clntname, *xdrname, *hdrname;
+  char *servername, *svcname, *servprogname, *clntprogname;
 
   svcname = file_name (cmd->infile, "_svc.c");
   clntname = file_name (cmd->infile, "_clnt.c");
@@ -982,20 +980,22 @@ mkfile_output (struct commandline *cmd)
     }
   else
     {
-      servername = " ";
-      clientname = " ";
+      servername = (char *) space;
+      clientname = (char *) space;
     }
   servprogname = extendfile (cmd->infile, "_server");
   clntprogname = extendfile (cmd->infile, "_client");
 
   if (allfiles)
     {
-      mkfilename = alloc (strlen ("Makefile.") +
-                         strlen (cmd->infile) + 1);
-      temp = (char *) rindex (cmd->infile, '.');
-      strcat (mkfilename, "Makefile.");
-      strncat (mkfilename, cmd->infile,
-              (temp - cmd->infile));
+      char *cp, *temp;
+
+      mkfilename = alloc (strlen ("Makefile.") + strlen (cmd->infile) + 1);
+      if (mkfilename == NULL)
+       abort ();
+      temp = rindex (cmd->infile, '.');
+      cp = stpcpy (mkfilename, "Makefile.");
+      strncpy (cp, cmd->infile, (temp - cmd->infile));
     }
   else
     mkfilename = (char *) cmd->outfile;
@@ -1051,6 +1051,23 @@ $(LDLIBS) \n\n");
   f_print (fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \
 $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
   close_output (mkfilename);
+
+  free (clntprogname);
+  free (servprogname);
+  if (servername != space)
+    free (servername);
+  if (clientname != space)
+    free (clientname);
+  if (mkfilename != (char *) cmd->outfile)
+    free (mkfilename);
+  if (svcname != space)
+    free (svcname);
+  if (clntname != space)
+    free (clntname);
+  if (xdrname != space)
+    free (xdrname);
+  if (hdrname != space)
+    free (hdrname);
 }
 
 /*
@@ -1145,7 +1162,9 @@ checkfiles (const char *infile, const char *outfile)
       else
        {
          fprintf (stderr,
-                  _("file '%s' already exists and may be overwritten\n"),
+                  /* TRANS: the file will not be removed; this is an
+                     TRANS: informative message.  */
+                  _("file `%s' already exists and may be overwritten\n"),
                   outfile);
          crash ();
        }
@@ -1355,6 +1374,15 @@ parseargs (int argc, const char *argv[], struct commandline *cmd)
   cmd->Scflag = flag['C'];
   cmd->makefileflag = flag['M'];
 
+#ifndef _RPC_THREAD_SAFE_
+  if (mtflag || newstyle)
+    {
+      /* glibc doesn't support these flags.  */
+      f_print (stderr,
+              _("This implementation doesn't support newstyle or MT-safe code!\n"));
+      return (0);
+    }
+#endif
   if (tirpcflag)
     {
       pmflag = inetdflag ? 0 : 1;    /* pmflag or inetdflag is always TRUE */
@@ -1412,7 +1440,7 @@ parseargs (int argc, const char *argv[], struct commandline *cmd)
 static void
 usage (void)
 {
-  fprintf (stderr, _("usage:  %s infile\n"), cmdname);
+  fprintf (stderr, _("usage: %s infile\n"), cmdname);
   fprintf (stderr, _("\t%s [-abkCLNTM][-Dname[=value]] [-i size] \
 [-I [-K seconds]] [-Y path] infile\n"), cmdname);
   fprintf (stderr, _("\t%s [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm] \