stdio.h defines BUFSIZ
[unix-history] / usr / src / usr.bin / make / arch.c
index af5fa88..9ee3750 100644 (file)
@@ -7,21 +7,11 @@
  * This code is derived from software contributed to Berkeley by
  * Adam de Boor.
  *
  * This code is derived from software contributed to Berkeley by
  * Adam de Boor.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)arch.c     5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)arch.c     5.7 (Berkeley) %G%";
 #endif /* not lint */
 
 /*-
 #endif /* not lint */
 
 /*-
@@ -70,12 +60,13 @@ static char sccsid[] = "@(#)arch.c  5.2 (Berkeley) %G%";
  *     Arch_Init               Initialize this module.
  */
 
  *     Arch_Init               Initialize this module.
  */
 
-#include    <stdio.h>
 #include    <sys/types.h>
 #include    <sys/stat.h>
 #include    <sys/time.h>
 #include    <ctype.h>
 #include    <ar.h>
 #include    <sys/types.h>
 #include    <sys/stat.h>
 #include    <sys/time.h>
 #include    <ctype.h>
 #include    <ar.h>
+#include <ranlib.h>
+#include    <stdio.h>
 #include    "make.h"
 #include    "hash.h"
 
 #include    "make.h"
 #include    "hash.h"
 
@@ -88,7 +79,7 @@ typedef struct Arch {
 } Arch;
 
 static FILE *ArchFindMember();
 } Arch;
 
 static FILE *ArchFindMember();
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_ParseArchive --
 /*-
  *-----------------------------------------------------------------------
  * Arch_ParseArchive --
@@ -237,7 +228,7 @@ Arch_ParseArchive (linePtr, nodeLst, ctxt)
             * variables and multi-word variable values.... The results
             * are just placed at the end of the nodeLst we're returning.
             */
             * variables and multi-word variable values.... The results
             * are just placed at the end of the nodeLst we're returning.
             */
-           buf=sacrifice=(char *)malloc(strlen(memName)+strlen(libName)+3);
+           buf = sacrifice = emalloc(strlen(memName)+strlen(libName)+3);
 
            sprintf(buf, "%s(%s)", libName, memName);
 
 
            sprintf(buf, "%s(%s)", libName, memName);
 
@@ -337,7 +328,7 @@ Arch_ParseArchive (linePtr, nodeLst, ctxt)
     *linePtr = cp;
     return (SUCCESS);
 }
     *linePtr = cp;
     return (SUCCESS);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * ArchFindArchive --
 /*-
  *-----------------------------------------------------------------------
  * ArchFindArchive --
@@ -359,7 +350,7 @@ ArchFindArchive (ar, archName)
 {
     return (strcmp (archName, ar->name));
 }
 {
     return (strcmp (archName, ar->name));
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * ArchStatMember --
 /*-
  *-----------------------------------------------------------------------
  * ArchStatMember --
@@ -426,7 +417,7 @@ ArchStatMember (archive, member, hash)
     if (ln != NILLNODE) {
        ar = (Arch *) Lst_Datum (ln);
 
     if (ln != NILLNODE) {
        ar = (Arch *) Lst_Datum (ln);
 
-       he = Hash_FindEntry (&ar->members, (Address) member);
+       he = Hash_FindEntry (&ar->members, member);
 
        if (he != (Hash_Entry *) NULL) {
            return ((struct ar_hdr *) Hash_GetValue (he));
 
        if (he != (Hash_Entry *) NULL) {
            return ((struct ar_hdr *) Hash_GetValue (he));
@@ -474,9 +465,9 @@ ArchStatMember (archive, member, hash)
            return ((struct ar_hdr *) NULL);
     }
 
            return ((struct ar_hdr *) NULL);
     }
 
-    ar = (Arch *) malloc (sizeof (Arch));
-    ar->name = Str_New (archive);
-    Hash_InitTable (&ar->members, -1, HASH_STRING_KEYS);
+    ar = (Arch *)emalloc (sizeof (Arch));
+    ar->name = strdup (archive);
+    Hash_InitTable (&ar->members, -1);
     memName[AR_MAX_NAME_LEN] = '\0';
     
     while (fread ((char *)&arh, sizeof (struct ar_hdr), 1, arch) == 1) {
     memName[AR_MAX_NAME_LEN] = '\0';
     
     while (fread ((char *)&arh, sizeof (struct ar_hdr), 1, arch) == 1) {
@@ -496,9 +487,9 @@ ArchStatMember (archive, member, hash)
            }
            cp[1] = '\0';
 
            }
            cp[1] = '\0';
 
-           he = Hash_CreateEntry (&ar->members, Str_New (memName),
+           he = Hash_CreateEntry (&ar->members, strdup (memName),
                                   (Boolean *)NULL);
                                   (Boolean *)NULL);
-           Hash_SetValue (he, (ClientData)malloc (sizeof (struct ar_hdr)));
+           Hash_SetValue (he, (ClientData)emalloc (sizeof (struct ar_hdr)));
            bcopy ((Address)&arh, (Address)Hash_GetValue (he), 
                sizeof (struct ar_hdr));
        }
            bcopy ((Address)&arh, (Address)Hash_GetValue (he), 
                sizeof (struct ar_hdr));
        }
@@ -521,7 +512,7 @@ ArchStatMember (archive, member, hash)
      * Now that the archive has been read and cached, we can look into
      * the hash table to find the desired member's header.
      */
      * Now that the archive has been read and cached, we can look into
      * the hash table to find the desired member's header.
      */
-    he = Hash_FindEntry (&ar->members, (Address) member);
+    he = Hash_FindEntry (&ar->members, member);
 
     if (he != (Hash_Entry *) NULL) {
        return ((struct ar_hdr *) Hash_GetValue (he));
 
     if (he != (Hash_Entry *) NULL) {
        return ((struct ar_hdr *) Hash_GetValue (he));
@@ -529,7 +520,7 @@ ArchStatMember (archive, member, hash)
        return ((struct ar_hdr *) NULL);
     }
 }
        return ((struct ar_hdr *) NULL);
     }
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * ArchFindMember --
 /*-
  *-----------------------------------------------------------------------
  * ArchFindMember --
@@ -641,7 +632,7 @@ ArchFindMember (archive, member, arhPtr, mode)
     fclose (arch);
     return ((FILE *) NULL);
 }
     fclose (arch);
     return ((FILE *) NULL);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_Touch --
 /*-
  *-----------------------------------------------------------------------
  * Arch_Touch --
@@ -674,7 +665,7 @@ Arch_Touch (gn)
        fclose (arch);
     }
 }
        fclose (arch);
     }
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_TouchLib --
 /*-
  *-----------------------------------------------------------------------
  * Arch_TouchLib --
@@ -685,7 +676,7 @@ Arch_Touch (gn)
  *     None.
  *
  * Side Effects:
  *     None.
  *
  * Side Effects:
- *     Both the modification time of the library and of the LIBTOC
+ *     Both the modification time of the library and of the RANLIBMAG
  *     member are set to 'now'.
  *
  *-----------------------------------------------------------------------
  *     member are set to 'now'.
  *
  *-----------------------------------------------------------------------
@@ -698,7 +689,7 @@ Arch_TouchLib (gn)
     struct ar_hdr   arh;       /* Header describing table of contents */
     struct timeval  times[2];  /* Times for utimes() call */
 
     struct ar_hdr   arh;       /* Header describing table of contents */
     struct timeval  times[2];  /* Times for utimes() call */
 
-    arch = ArchFindMember (gn->path, LIBTOC, &arh, "r+");
+    arch = ArchFindMember (gn->path, RANLIBMAG, &arh, "r+");
     sprintf(arh.ar_date, "%-12d", now);
 
     if (arch != (FILE *) NULL) {
     sprintf(arh.ar_date, "%-12d", now);
 
     if (arch != (FILE *) NULL) {
@@ -710,7 +701,7 @@ Arch_TouchLib (gn)
        utimes(gn->path, times);
     }
 }
        utimes(gn->path, times);
     }
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_MTime --
 /*-
  *-----------------------------------------------------------------------
  * Arch_MTime --
@@ -744,7 +735,7 @@ Arch_MTime (gn)
     gn->mtime = modTime;
     return (modTime);
 }
     gn->mtime = modTime;
     return (modTime);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_MemMTime --
 /*-
  *-----------------------------------------------------------------------
  * Arch_MemMTime --
@@ -804,7 +795,7 @@ Arch_MemMTime (gn)
 
     return (gn->mtime);
 }
 
     return (gn->mtime);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_FindLib --
 /*-
  *-----------------------------------------------------------------------
  * Arch_FindLib --
@@ -832,7 +823,7 @@ Arch_FindLib (gn, path)
 {
     char           *libName;   /* file name for archive */
 
 {
     char           *libName;   /* file name for archive */
 
-    libName = (char *)malloc (strlen (gn->name) + 6 - 2);
+    libName = (char *)emalloc (strlen (gn->name) + 6 - 2);
     sprintf(libName, "lib%s.a", &gn->name[2]);
 
     gn->path = Dir_FindFile (libName, path);
     sprintf(libName, "lib%s.a", &gn->name[2]);
 
     gn->path = Dir_FindFile (libName, path);
@@ -845,7 +836,7 @@ Arch_FindLib (gn, path)
     Var_Set (TARGET, gn->path == (char *) NULL ? gn->name : gn->path, gn);
 #endif LIBRARIES
 }
     Var_Set (TARGET, gn->path == (char *) NULL ? gn->name : gn->path, gn);
 #endif LIBRARIES
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_LibOODate --
 /*-
  *-----------------------------------------------------------------------
  * Arch_LibOODate --
@@ -866,7 +857,7 @@ Arch_FindLib (gn, path)
  *               make began (i.e. it's been modified in the course
  *               of the make, probably by archiving).
  *         Its modification time doesn't agree with the modification
  *               make began (i.e. it's been modified in the course
  *               of the make, probably by archiving).
  *         Its modification time doesn't agree with the modification
- *               time of its LIBTOC member (i.e. its table of contents
+ *               time of its RANLIBMAG member (i.e. its table of contents
  *               is out-of-date).
  *
  *
  *               is out-of-date).
  *
  *
@@ -892,13 +883,13 @@ Arch_LibOODate (gn)
        struct ar_hdr   *arhPtr;    /* Header for __.SYMDEF */
        int             modTimeTOC; /* The table-of-contents's mod time */
 
        struct ar_hdr   *arhPtr;    /* Header for __.SYMDEF */
        int             modTimeTOC; /* The table-of-contents's mod time */
 
-       arhPtr = ArchStatMember (gn->path, LIBTOC, FALSE);
+       arhPtr = ArchStatMember (gn->path, RANLIBMAG, FALSE);
 
        if (arhPtr != (struct ar_hdr *)NULL) {
            (void)sscanf (arhPtr->ar_date, "%12d", &modTimeTOC);
 
            if (DEBUG(ARCH) || DEBUG(MAKE)) {
 
        if (arhPtr != (struct ar_hdr *)NULL) {
            (void)sscanf (arhPtr->ar_date, "%12d", &modTimeTOC);
 
            if (DEBUG(ARCH) || DEBUG(MAKE)) {
-               printf("%s modified %s...", LIBTOC, Targ_FmtTime(modTimeTOC));
+               printf("%s modified %s...", RANLIBMAG, Targ_FmtTime(modTimeTOC));
            }
            oodate = (gn->mtime > modTimeTOC);
        } else {
            }
            oodate = (gn->mtime > modTimeTOC);
        } else {
@@ -913,7 +904,7 @@ Arch_LibOODate (gn)
     }
     return (oodate);
 }
     }
     return (oodate);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_Init --
 /*-
  *-----------------------------------------------------------------------
  * Arch_Init --