stdio.h defines BUFSIZ
[unix-history] / usr / src / usr.bin / make / arch.c
index 8ca6183..9ee3750 100644 (file)
@@ -1,18 +1,22 @@
-/*-
- * arch.c --
- *     Functions to manipulate libraries, archives and their members.
- *
- * Copyright (c) 1988, 1989 by the Regents of the University of California
+/*
+ * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
  * Copyright (c) 1988, 1989 by Adam de Boor
  * Copyright (c) 1989 by Berkeley Softworks
  * Copyright (c) 1988, 1989 by Adam de Boor
  * Copyright (c) 1989 by Berkeley Softworks
+ * All rights reserved.
  *
  *
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any non-commercial purpose
- * and without fee is hereby granted, provided that the above copyright
- * notice appears in all copies.  The University of California,
- * Berkeley Softworks and Adam de Boor make no representations about
- * the suitability of this software for any purpose.  It is provided
- * "as is" without express or implied warranty.
+ * This code is derived from software contributed to Berkeley by
+ * Adam de Boor.
+ *
+ * %sccs.include.redist.c%
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)arch.c     5.7 (Berkeley) %G%";
+#endif /* not lint */
+
+/*-
+ * arch.c --
+ *     Functions to manipulate libraries, archives and their members.
  *
  *     Once again, cacheing/hashing comes into play in the manipulation
  * of archives. The first time an archive is referenced, all of its members'
  *
  *     Once again, cacheing/hashing comes into play in the manipulation
  * of archives. The first time an archive is referenced, all of its members'
  *
  *     Arch_Init               Initialize this module.
  */
  *
  *     Arch_Init               Initialize this module.
  */
-#ifndef lint
-static char *rcsid = "$Id: arch.c,v 1.20 89/11/14 13:43:37 adam Exp $ SPRITE (Berkeley)";
-#endif lint
 
 
-#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"
 
@@ -77,7 +79,7 @@ typedef struct Arch {
 } Arch;
 
 static FILE *ArchFindMember();
 } Arch;
 
 static FILE *ArchFindMember();
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_ParseArchive --
 /*-
  *-----------------------------------------------------------------------
  * Arch_ParseArchive --
@@ -226,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);
 
@@ -326,7 +328,7 @@ Arch_ParseArchive (linePtr, nodeLst, ctxt)
     *linePtr = cp;
     return (SUCCESS);
 }
     *linePtr = cp;
     return (SUCCESS);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * ArchFindArchive --
 /*-
  *-----------------------------------------------------------------------
  * ArchFindArchive --
@@ -348,7 +350,7 @@ ArchFindArchive (ar, archName)
 {
     return (strcmp (archName, ar->name));
 }
 {
     return (strcmp (archName, ar->name));
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * ArchStatMember --
 /*-
  *-----------------------------------------------------------------------
  * ArchStatMember --
@@ -415,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));
@@ -463,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) {
@@ -485,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));
        }
@@ -510,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));
@@ -518,7 +520,7 @@ ArchStatMember (archive, member, hash)
        return ((struct ar_hdr *) NULL);
     }
 }
        return ((struct ar_hdr *) NULL);
     }
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * ArchFindMember --
 /*-
  *-----------------------------------------------------------------------
  * ArchFindMember --
@@ -630,7 +632,7 @@ ArchFindMember (archive, member, arhPtr, mode)
     fclose (arch);
     return ((FILE *) NULL);
 }
     fclose (arch);
     return ((FILE *) NULL);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_Touch --
 /*-
  *-----------------------------------------------------------------------
  * Arch_Touch --
@@ -663,7 +665,7 @@ Arch_Touch (gn)
        fclose (arch);
     }
 }
        fclose (arch);
     }
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_TouchLib --
 /*-
  *-----------------------------------------------------------------------
  * Arch_TouchLib --
@@ -674,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'.
  *
  *-----------------------------------------------------------------------
@@ -687,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) {
@@ -699,7 +701,7 @@ Arch_TouchLib (gn)
        utimes(gn->path, times);
     }
 }
        utimes(gn->path, times);
     }
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_MTime --
 /*-
  *-----------------------------------------------------------------------
  * Arch_MTime --
@@ -733,7 +735,7 @@ Arch_MTime (gn)
     gn->mtime = modTime;
     return (modTime);
 }
     gn->mtime = modTime;
     return (modTime);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_MemMTime --
 /*-
  *-----------------------------------------------------------------------
  * Arch_MemMTime --
@@ -793,7 +795,7 @@ Arch_MemMTime (gn)
 
     return (gn->mtime);
 }
 
     return (gn->mtime);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_FindLib --
 /*-
  *-----------------------------------------------------------------------
  * Arch_FindLib --
@@ -821,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);
@@ -834,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 --
@@ -855,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).
  *
  *
@@ -881,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 {
@@ -902,7 +904,7 @@ Arch_LibOODate (gn)
     }
     return (oodate);
 }
     }
     return (oodate);
 }
-\f
+
 /*-
  *-----------------------------------------------------------------------
  * Arch_Init --
 /*-
  *-----------------------------------------------------------------------
  * Arch_Init --