Deleted Added
full compact
arch.c (103503) arch.c (103508)
1/*
2 * Copyright (c) 1988, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1989 by Berkeley Softworks
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.

--- 25 unchanged lines hidden (view full) ---

34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)arch.c 8.2 (Berkeley) 1/2/94
39 */
40
41#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1988, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1989 by Berkeley Softworks
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.

--- 25 unchanged lines hidden (view full) ---

34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)arch.c 8.2 (Berkeley) 1/2/94
39 */
40
41#include <sys/cdefs.h>
42__FBSDID("$FreeBSD: head/usr.bin/make/arch.c 103503 2002-09-17 21:29:06Z jmallett $");
42__FBSDID("$FreeBSD: head/usr.bin/make/arch.c 103508 2002-09-17 22:31:26Z jmallett $");
43
44/*-
45 * arch.c --
46 * Functions to manipulate libraries, archives and their members.
47 *
48 * Once again, cacheing/hashing comes into play in the manipulation
49 * of archives. The first time an archive is referenced, all of its members'
50 * headers are read and hashed and the archive closed again. All hashed

--- 565 unchanged lines hidden (view full) ---

616 unsigned int elen = atoi(&memName[sizeof(AR_EFMT1)-1]);
617
618 if (elen > MAXPATHLEN)
619 goto badarch;
620 if (fread (memName, elen, 1, arch) != 1)
621 goto badarch;
622 memName[elen] = '\0';
623 fseek (arch, -elen, SEEK_CUR);
43
44/*-
45 * arch.c --
46 * Functions to manipulate libraries, archives and their members.
47 *
48 * Once again, cacheing/hashing comes into play in the manipulation
49 * of archives. The first time an archive is referenced, all of its members'
50 * headers are read and hashed and the archive closed again. All hashed

--- 565 unchanged lines hidden (view full) ---

616 unsigned int elen = atoi(&memName[sizeof(AR_EFMT1)-1]);
617
618 if (elen > MAXPATHLEN)
619 goto badarch;
620 if (fread (memName, elen, 1, arch) != 1)
621 goto badarch;
622 memName[elen] = '\0';
623 fseek (arch, -elen, SEEK_CUR);
624 /* XXX Multiple levels may be asked for, make this conditional
625 * on one, and use DEBUGF.
626 */
624 if (DEBUG(ARCH) || DEBUG(MAKE)) {
627 if (DEBUG(ARCH) || DEBUG(MAKE)) {
625 printf("ArchStat: Extended format entry for %s\n", memName);
628 fprintf(stderr, "ArchStat: Extended format entry for %s\n", memName);
626 }
627 }
628#endif
629
630 he = Hash_CreateEntry (&ar->members, memName, NULL);
631 Hash_SetValue (he, (void *)emalloc (sizeof (struct ar_hdr)));
632 memcpy (Hash_GetValue (he), &arh,
633 sizeof (struct ar_hdr));

--- 57 unchanged lines hidden (view full) ---

691#define ARLONGNAMES2 "/ARFILENAMES"
692 size_t entry;
693 char *ptr, *eptr;
694
695 if (strncmp(name, ARLONGNAMES1, sizeof(ARLONGNAMES1) - 1) == 0 ||
696 strncmp(name, ARLONGNAMES2, sizeof(ARLONGNAMES2) - 1) == 0) {
697
698 if (ar->fnametab != NULL) {
629 }
630 }
631#endif
632
633 he = Hash_CreateEntry (&ar->members, memName, NULL);
634 Hash_SetValue (he, (void *)emalloc (sizeof (struct ar_hdr)));
635 memcpy (Hash_GetValue (he), &arh,
636 sizeof (struct ar_hdr));

--- 57 unchanged lines hidden (view full) ---

694#define ARLONGNAMES2 "/ARFILENAMES"
695 size_t entry;
696 char *ptr, *eptr;
697
698 if (strncmp(name, ARLONGNAMES1, sizeof(ARLONGNAMES1) - 1) == 0 ||
699 strncmp(name, ARLONGNAMES2, sizeof(ARLONGNAMES2) - 1) == 0) {
700
701 if (ar->fnametab != NULL) {
699 if (DEBUG(ARCH)) {
700 printf("Attempted to redefine an SVR4 name table\n");
701 }
702 DEBUGF(ARCH, "Attempted to redefine an SVR4 name table\n");
702 return -1;
703 }
704
705 /*
706 * This is a table of archive names, so we build one for
707 * ourselves
708 */
709 ar->fnametab = emalloc(size);
710 ar->fnamesize = size;
711
712 if (fread(ar->fnametab, size, 1, arch) != 1) {
703 return -1;
704 }
705
706 /*
707 * This is a table of archive names, so we build one for
708 * ourselves
709 */
710 ar->fnametab = emalloc(size);
711 ar->fnamesize = size;
712
713 if (fread(ar->fnametab, size, 1, arch) != 1) {
713 if (DEBUG(ARCH)) {
714 printf("Reading an SVR4 name table failed\n");
715 }
714 DEBUGF(ARCH, "Reading an SVR4 name table failed\n");
716 return -1;
717 }
718 eptr = ar->fnametab + size;
719 for (entry = 0, ptr = ar->fnametab; ptr < eptr; ptr++)
720 switch (*ptr) {
721 case '/':
722 entry++;
723 *ptr = '\0';
724 break;
725
726 case '\n':
727 break;
728
729 default:
730 break;
731 }
715 return -1;
716 }
717 eptr = ar->fnametab + size;
718 for (entry = 0, ptr = ar->fnametab; ptr < eptr; ptr++)
719 switch (*ptr) {
720 case '/':
721 entry++;
722 *ptr = '\0';
723 break;
724
725 case '\n':
726 break;
727
728 default:
729 break;
730 }
732 if (DEBUG(ARCH)) {
733 printf("Found svr4 archive name table with %zu entries\n", entry);
734 }
731 DEBUGF(ARCH, "Found svr4 archive name table with %zu entries\n", entry);
735 return 0;
736 }
737
738 if (name[1] == ' ' || name[1] == '\0')
739 return 2;
740
741 entry = (size_t) strtol(&name[1], &eptr, 0);
742 if ((*eptr != ' ' && *eptr != '\0') || eptr == &name[1]) {
732 return 0;
733 }
734
735 if (name[1] == ' ' || name[1] == '\0')
736 return 2;
737
738 entry = (size_t) strtol(&name[1], &eptr, 0);
739 if ((*eptr != ' ' && *eptr != '\0') || eptr == &name[1]) {
743 if (DEBUG(ARCH)) {
744 printf("Could not parse SVR4 name %s\n", name);
745 }
740 DEBUGF(ARCH, "Could not parse SVR4 name %s\n", name);
746 return 2;
747 }
748 if (entry >= ar->fnamesize) {
741 return 2;
742 }
743 if (entry >= ar->fnamesize) {
749 if (DEBUG(ARCH)) {
750 printf("SVR4 entry offset %s is greater than %zu\n",
751 name, ar->fnamesize);
752 }
744 DEBUGF(ARCH, "SVR4 entry offset %s is greater than %zu\n",
745 name, ar->fnamesize);
753 return 2;
754 }
755
746 return 2;
747 }
748
756 if (DEBUG(ARCH)) {
757 printf("Replaced %s with %s\n", name, &ar->fnametab[entry]);
758 }
749 DEBUGF(ARCH, "Replaced %s with %s\n", name, &ar->fnametab[entry]);
759
760 (void) strncpy(name, &ar->fnametab[entry], MAXPATHLEN);
761 name[MAXPATHLEN] = '\0';
762 return 1;
763}
764#endif
765
766

--- 104 unchanged lines hidden (view full) ---

871 fclose (arch);
872 return NULL;
873 }
874 if (fread (ename, elen, 1, arch) != 1) {
875 fclose (arch);
876 return NULL;
877 }
878 ename[elen] = '\0';
750
751 (void) strncpy(name, &ar->fnametab[entry], MAXPATHLEN);
752 name[MAXPATHLEN] = '\0';
753 return 1;
754}
755#endif
756
757

--- 104 unchanged lines hidden (view full) ---

862 fclose (arch);
863 return NULL;
864 }
865 if (fread (ename, elen, 1, arch) != 1) {
866 fclose (arch);
867 return NULL;
868 }
869 ename[elen] = '\0';
870 /*
871 * XXX choose one.
872 */
879 if (DEBUG(ARCH) || DEBUG(MAKE)) {
880 printf("ArchFind: Extended format entry for %s\n", ename);
881 }
882 if (strncmp(ename, member, len) == 0) {
883 /* Found as extended name */
884 fseek (arch, -sizeof(struct ar_hdr) - elen, SEEK_CUR);
885 return (arch);
886 }

--- 289 unchanged lines hidden (view full) ---

1176 struct ar_hdr *arhPtr; /* Header for __.SYMDEF */
1177 int modTimeTOC; /* The table-of-contents's mod time */
1178
1179 arhPtr = ArchStatMember (gn->path, RANLIBMAG, FALSE);
1180
1181 if (arhPtr != NULL) {
1182 modTimeTOC = (int) strtol(arhPtr->ar_date, NULL, 10);
1183
873 if (DEBUG(ARCH) || DEBUG(MAKE)) {
874 printf("ArchFind: Extended format entry for %s\n", ename);
875 }
876 if (strncmp(ename, member, len) == 0) {
877 /* Found as extended name */
878 fseek (arch, -sizeof(struct ar_hdr) - elen, SEEK_CUR);
879 return (arch);
880 }

--- 289 unchanged lines hidden (view full) ---

1170 struct ar_hdr *arhPtr; /* Header for __.SYMDEF */
1171 int modTimeTOC; /* The table-of-contents's mod time */
1172
1173 arhPtr = ArchStatMember (gn->path, RANLIBMAG, FALSE);
1174
1175 if (arhPtr != NULL) {
1176 modTimeTOC = (int) strtol(arhPtr->ar_date, NULL, 10);
1177
1178 /* XXX choose one. */
1184 if (DEBUG(ARCH) || DEBUG(MAKE)) {
1185 printf("%s modified %s...", RANLIBMAG, Targ_FmtTime(modTimeTOC));
1186 }
1187 oodate = (gn->cmtime > modTimeTOC);
1188 } else {
1189 /*
1190 * A library w/o a table of contents is out-of-date
1191 */

--- 51 unchanged lines hidden ---
1179 if (DEBUG(ARCH) || DEBUG(MAKE)) {
1180 printf("%s modified %s...", RANLIBMAG, Targ_FmtTime(modTimeTOC));
1181 }
1182 oodate = (gn->cmtime > modTimeTOC);
1183 } else {
1184 /*
1185 * A library w/o a table of contents is out-of-date
1186 */

--- 51 unchanged lines hidden ---