lib/pam: remove register keyword
[oweals/cde.git] / cde / config / imake / imake.c
index 1bb833513a2cf7f656fde35eb5d62bf829232142..3444c045fadc92536c86e285b82a7f919ded604c 100644 (file)
@@ -16,7 +16,7 @@
  * details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with these librararies and programs; if not, write
+ * License along with these libraries and programs; if not, write
  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  * Floor, Boston, MA 02110-1301 USA
  */
@@ -226,9 +226,6 @@ typedef union wait  waitType;
 char *malloc(), *realloc();
 void exit();
 #endif
-#if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */
-char *malloc(), *realloc();
-#endif /* macII */
 #ifdef X_NOT_STDC_ENV
 extern char    *getenv();
 #endif
@@ -263,7 +260,7 @@ extern int  errno;
  * This define of strerror is copied from (and should be identical to)
  * Xos.h, which we don't want to include here for bootstrapping reasons.
  */
-#if defined(X_NOT_STDC_ENV) || (defined(sun) && !defined(SVR4)) || defined(macII)
+#if defined(X_NOT_STDC_ENV) || (defined(sun) && !defined(SVR4))
 # ifndef strerror
 extern char *sys_errlist[];
 extern int sys_nerr;
@@ -378,6 +375,9 @@ static void get_libc_version(FILE *);
 static void    get_ld_version(FILE *);
 #endif
 #if defined(sun) && defined(__SVR4)
+static char     *get_full_path(const char *program);
+static int      get_sun_compiler_version(const char *fspec, const char *product,
+                                        int *cmajor, int *cminor);
 static void    get_sun_compiler_versions(FILE *);
 #endif
 static void    get_gcc_incdir(FILE *);
@@ -996,11 +996,11 @@ get_libc_version(FILE *inFile)
         */
       if (readlink (libcso, buf, PATH_MAX) >= 0) {
        for (ptr = buf; *ptr && !isdigit (*ptr); ptr++);
-         int ret = sscanf (ptr, "%d.%d.%d", &libcmajor, &libcminor, &libcteeny);
-         (void) ret;
-         fprintf(inFile, "#define DefaultLinuxCLibMajorVersion %d\n", libcmajor);    
-         fprintf(inFile, "#define DefaultLinuxCLibMinorVersion %d\n", libcminor);    
-         fprintf(inFile, "#define DefaultLinuxCLibTeenyVersion %d\n", libcteeny);    
+       int ret = sscanf (ptr, "%d.%d.%d", &libcmajor, &libcminor, &libcteeny);
+       (void) ret;
+       fprintf(inFile, "#define DefaultLinuxCLibMajorVersion %d\n", libcmajor);
+       fprintf(inFile, "#define DefaultLinuxCLibMinorVersion %d\n", libcminor);
+       fprintf(inFile, "#define DefaultLinuxCLibTeenyVersion %d\n", libcteeny);
       }
     } else {
       /* 
@@ -1015,20 +1015,20 @@ get_libc_version(FILE *inFile)
       int len;
       char *command;
 
-      memset(&aout, '\0', PATH_MAX);
+      memset(aout, '\0', PATH_MAX);
 
       if (!lstat(getenv("TMPDIR"), &sb) && S_ISDIR(sb.st_mode))
-       strncpy(aout, getenv("TMPDIR"), PATH_MAX);
+       strncpy(aout, getenv("TMPDIR"), PATH_MAX - 1);
 #ifdef P_tmpdir /* defined by XPG and XOPEN, but don't assume we have it */
       else if (!lstat(P_tmpdir, &sb) && S_ISDIR(sb.st_mode))
-       strncpy(aout, P_tmpdir, PATH_MAX);
+       strncpy(aout, P_tmpdir, PATH_MAX - 1);
 #endif
       else if (!lstat("/tmp", &sb) && S_ISDIR(sb.st_mode))
-       strncpy(aout, "/tmp", PATH_MAX);
+       strncpy(aout, "/tmp", PATH_MAX - 1);
       else
        abort();
 
-      strncpy(aout+strlen(aout), "/imaketmp.XXXXXX", 16);
+      strncat(aout, "/imaketmp.XXXXXX", PATH_MAX - 1);
 
       if ((fd = mkstemp(aout)) == -1)
        abort ();
@@ -1091,59 +1091,105 @@ get_ld_version(FILE *inFile)
 #endif
 
 #if defined(sun) && defined(__SVR4)
-static void
-get_sun_compiler_versions(FILE *inFile)
+
+static char *
+get_full_path(const char *program)
+{
+  char *buf;
+  char *cmd;
+  FILE *proc;
+
+  buf = calloc(1, PATH_MAX);
+  asprintf(&cmd, "command -v %s", program);
+
+  if ((proc = popen (cmd, "r")) != NULL)
+    fgets (buf, PATH_MAX, proc);
+
+  pclose (proc);
+
+  return strtok (buf, "\n");    /* strip newline */
+}
+
+static int
+get_sun_compiler_version(const char *fspec, const char *product,
+                         int *cmajor, int *cminor)
 {
   char buf[PATH_MAX];
   char cmd[PATH_MAX];
-  static char* sunpro_cc = "/opt/SUNWspro/bin/cc";
-  static char* sunpro_CC = "/opt/SUNWspro/bin/CC";
-  int cmajor, cminor;
-  char* vptr;
+  char *vptr;
   struct stat sb;
-  FILEccproc;
+  FILE *ccproc;
   int ret;
+  char vendor[4];
+
+  if (lstat (fspec, &sb) != 0)
+    return ENOENT;
 
-  if (lstat (sunpro_cc, &sb) == 0) {
-    strncpy (cmd, sunpro_cc, PATH_MAX);
+  strncpy (cmd, fspec, PATH_MAX);
+  strlcpy (vendor, product, 4);
+
+  if (strcmp (vendor, "Sun") == 0)
     strncat (cmd, " -V 2>&1", 8);
-    if ((ccproc = popen (cmd, "r")) != NULL) {
-      if (fgets (buf, PATH_MAX, ccproc) != NULL) {
-       vptr = strrchr (buf, 'C');
-       for (; !isdigit(*vptr); vptr++);
-       ret = sscanf (vptr, "%d.%d", &cmajor, &cminor);
-       fprintf (inFile, 
-                "#define DefaultSunProCCompilerMajorVersion %d\n",
-                cmajor);
-       fprintf (inFile, 
-                "#define DefaultSunProCCompilerMinorVersion %d\n",
-                cminor);
+  else if (strcmp (vendor, "Gnu") == 0)
+    strncat (cmd, " --version 2>&1", 15);
+  else
+    return EINVAL;
+
+  if ((ccproc = popen (cmd, "r")) != NULL) {
+    if (fgets (buf, PATH_MAX, ccproc) != NULL) {
+      for (vptr = buf; !isdigit(*vptr) && *vptr != NULL; vptr++);
+      if (*vptr == NULL) {
+        pclose (ccproc);
+        return EINVAL;
+      } else {
+        ret = sscanf (vptr, "%d.%d", cmajor, cminor);
       }
-      while (fgets (buf, PATH_MAX, ccproc) != NULL) {};
-      pclose (ccproc);
     }
+    pclose (ccproc);
+  } else {
+    return EIO;
   }
-  if (lstat (sunpro_CC, &sb) == 0) {
-    strncpy (cmd, sunpro_CC, PATH_MAX);
-    strncat (cmd, " -V 2>&1", 8);
-    if ((ccproc = popen (cmd, "r")) != NULL) {
-      if (fgets (buf, PATH_MAX, ccproc) != NULL) {
-       vptr = strrchr (buf, 'C');
-       for (; !isdigit(*vptr); vptr++);
-       ret = sscanf (vptr, "%d.%d", &cmajor, &cminor);
-       fprintf (inFile, 
-                "#define DefaultSunProCplusplusCompilerMajorVersion %d\n",
-                cmajor);
-       fprintf (inFile, 
-                "#define DefaultSunProCplusplusCompilerMinorVersion %d\n",
-                cminor);
-      }
-      while (fgets (buf, PATH_MAX, ccproc) != NULL) {};
-      pclose (ccproc);
+
+  return 0;
+}
+
+static void
+get_sun_compiler_versions(FILE *inFile)
+{
+  static const char *compilers[][2] =
+    {{"SunProC",         "/opt/solarisstudio/bin/cc"},
+     {"SunProCplusplus", "/opt/solarisstudio/bin/CC"},
+     {"GnuC",            "gcc"},
+     {"GnuCplusplus",    "g++"}};
+  int cmajor, cminor;
+  int i;
+  int ret;
+
+  for (i = 0; i < sizeof compilers / sizeof compilers[0]; i++) {
+    const char *product = compilers[i][0];
+    char *fspec = get_full_path (compilers[i][1]);
+
+    ret = get_sun_compiler_version (fspec, product, &cmajor, &cminor);
+    free (fspec);
+
+    if (ret == 0) {
+      fprintf (inFile,
+               "#define Default%sCompilerMajorVersion %d\n",
+               product,
+               cmajor);
+      fprintf (inFile,
+               "#define Default%sCompilerMinorVersion %d\n",
+               product,
+               cminor);
+    } else if (ret == EINVAL) {
+      printf ("Failed to detect version of compiler: %s\n", product);
+      exit (EINVAL);
     }
   }
+
   (void) ret;
 }
+
 #endif
 
 static void
@@ -1152,6 +1198,9 @@ get_gcc_incdir(FILE *inFile)
   static char* gcc_path[] = {
 #ifdef linux
     "/usr/bin/cc",     /* for Linux PostIncDir */
+#endif
+#ifdef sun
+    "gcc",
 #endif
     "/usr/local/bin/gcc",
     "/opt/gnu/bin/gcc"
@@ -1163,15 +1212,21 @@ get_gcc_incdir(FILE *inFile)
   char cmd[PATH_MAX];
   char* ptr;
 
-  buf[0] = '\0';
+  memset(buf, 0, PATH_MAX);
   for (i = 0; i < sizeof gcc_path / sizeof gcc_path[0]; i++) {
+#ifdef sun
+    gcc_path[i] = get_full_path (gcc_path[i]);
+#endif
     if (lstat (gcc_path[i], &sb) == 0) {
-      strncpy (cmd, gcc_path[i], PATH_MAX - 25);
-      strncpy (cmd + strlen(cmd), " --print-libgcc-file-name", 25);
+#ifdef sun
+      free (gcc_path[i]);
+#endif
+      strncpy (cmd, gcc_path[i], PATH_MAX - 1 );
+      strncat (cmd, " --print-libgcc-file-name", PATH_MAX - 1);
       if ((gccproc = popen (cmd, "r")) != NULL) {
-       if (fgets (buf, PATH_MAX, gccproc) != NULL) {
+       if (fgets (buf, PATH_MAX - 1, gccproc) != NULL) {
          ptr = strstr (buf, "libgcc.a");
-         if (ptr) strncpy (ptr, "include", 7);
+         if (ptr) strncpy (ptr, "include", 8);
        }
        (void) pclose (gccproc);
        break;
@@ -1662,6 +1717,6 @@ Strdup(const char *cp)
 {
        char *new = Emalloc(strlen(cp) + 1);
 
-       strncpy(new, cp, strlen(cp) + 1);
+       memcpy(new, cp, strlen(cp) + 1);
        return new;
 }