aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/arch.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bmake/arch.c')
-rw-r--r--contrib/bmake/arch.c104
1 files changed, 56 insertions, 48 deletions
diff --git a/contrib/bmake/arch.c b/contrib/bmake/arch.c
index e5c0a5e4ac0f..6d9dd60dfbe9 100644
--- a/contrib/bmake/arch.c
+++ b/contrib/bmake/arch.c
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.197 2021/02/05 05:15:12 rillig Exp $ */
+/* $NetBSD: arch.c,v 1.200 2021/05/30 21:16:54 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -147,7 +147,7 @@ struct ar_hdr {
#include "dir.h"
/* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: arch.c,v 1.197 2021/02/05 05:15:12 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.200 2021/05/30 21:16:54 rillig Exp $");
typedef struct List ArchList;
typedef struct ListNode ArchListNode;
@@ -216,6 +216,19 @@ ArchFree(void *ap)
}
#endif
+/* Return "archive(member)". */
+static char *
+FullName(const char *archive, const char *member)
+{
+ size_t len1 = strlen(archive);
+ size_t len3 = strlen(member);
+ char *result = bmake_malloc(len1 + 1 + len3 + 1 + 1);
+ memcpy(result, archive, len1);
+ memcpy(result + len1, "(", 1);
+ memcpy(result + len1 + 1, member, len3);
+ memcpy(result + len1 + 1 + len3, ")", 1 + 1);
+ return result;
+}
/*
* Parse an archive specification such as "archive.a(member1 member2.${EXT})",
@@ -228,10 +241,10 @@ ArchFree(void *ap)
* scope The scope in which to expand variables.
*
* Output:
- * return TRUE if it was a valid specification.
+ * return True if it was a valid specification.
* *pp Points to the first non-space after the archive spec.
*/
-Boolean
+bool
Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
{
char *cp; /* Pointer into line */
@@ -239,12 +252,12 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
MFStr libName; /* Library-part of specification */
char *memName; /* Member-part of specification */
char saveChar; /* Ending delimiter of member-name */
- Boolean expandLibName; /* Whether the parsed libName contains
+ bool expandLibName; /* Whether the parsed libName contains
* variable expressions that need to be
* expanded */
libName = MFStr_InitRefer(*pp);
- expandLibName = FALSE;
+ expandLibName = false;
for (cp = libName.str; *cp != '(' && *cp != '\0';) {
if (*cp == '$') {
@@ -252,18 +265,18 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
/* XXX: This code can probably be shortened. */
const char *nested_p = cp;
FStr result;
- Boolean isError;
+ bool isError;
/* XXX: is expanded twice: once here and once below */
(void)Var_Parse(&nested_p, scope,
- VARE_WANTRES | VARE_UNDEFERR, &result);
+ VARE_UNDEFERR, &result);
/* TODO: handle errors */
isError = result.str == var_Error;
FStr_Done(&result);
if (isError)
- return FALSE;
+ return false;
- expandLibName = TRUE;
+ expandLibName = true;
cp += nested_p - cp;
} else
cp++;
@@ -272,8 +285,7 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
*cp++ = '\0';
if (expandLibName) {
char *expanded;
- (void)Var_Subst(libName.str, scope,
- VARE_WANTRES | VARE_UNDEFERR, &expanded);
+ (void)Var_Subst(libName.str, scope, VARE_UNDEFERR, &expanded);
/* TODO: handle errors */
libName = MFStr_InitOwn(expanded);
}
@@ -285,7 +297,7 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
* place and skip to the end of it (either white-space or
* a close paren).
*/
- Boolean doSubst = FALSE;
+ bool doSubst = false;
pp_skip_whitespace(&cp);
@@ -295,20 +307,19 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
/* Expand nested variable expressions. */
/* XXX: This code can probably be shortened. */
FStr result;
- Boolean isError;
+ bool isError;
const char *nested_p = cp;
(void)Var_Parse(&nested_p, scope,
- VARE_WANTRES | VARE_UNDEFERR,
- &result);
+ VARE_UNDEFERR, &result);
/* TODO: handle errors */
isError = result.str == var_Error;
FStr_Done(&result);
if (isError)
- return FALSE;
+ return false;
- doSubst = TRUE;
+ doSubst = true;
cp += nested_p - cp;
} else {
cp++;
@@ -325,7 +336,7 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
Parse_Error(PARSE_FATAL,
"No closing parenthesis "
"in archive specification");
- return FALSE;
+ return false;
}
/*
@@ -355,16 +366,15 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
char *p;
char *unexpandedMemName = memName;
- (void)Var_Subst(memName, scope,
- VARE_WANTRES | VARE_UNDEFERR,
- &memName);
+ (void)Var_Subst(memName, scope, VARE_UNDEFERR,
+ &memName);
/* TODO: handle errors */
/*
* Now form an archive spec and recurse to deal with
* nested variables and multi-word variable values.
*/
- fullName = str_concat4(libName.str, "(", memName, ")");
+ fullName = FullName(libName.str, memName);
p = fullName;
if (strchr(memName, '$') != NULL &&
@@ -383,7 +393,7 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
/* Error in nested call. */
free(fullName);
/* XXX: does unexpandedMemName leak? */
- return FALSE;
+ return false;
}
free(fullName);
/* XXX: does unexpandedMemName leak? */
@@ -394,8 +404,7 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
while (!Lst_IsEmpty(&members)) {
char *member = Lst_Dequeue(&members);
- char *fullname = str_concat4(libName.str, "(",
- member, ")");
+ char *fullname = FullName(libName.str, member);
free(member);
gn = Targ_GetNode(fullname);
@@ -407,8 +416,7 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
Lst_Done(&members);
} else {
- char *fullname = str_concat4(libName.str, "(", memName,
- ")");
+ char *fullname = FullName(libName.str, memName);
gn = Targ_GetNode(fullname);
free(fullname);
@@ -434,7 +442,7 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
/* We promised that pp would be set up at the next non-space. */
pp_skip_whitespace(&cp);
*pp = cp;
- return TRUE;
+ return true;
}
/*
@@ -444,7 +452,7 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
* Input:
* archive Path to the archive
* member Name of member; only its basename is used.
- * addToCache TRUE if archive should be cached if not already so.
+ * addToCache True if archive should be cached if not already so.
*
* Results:
* The ar_hdr for the member, or NULL.
@@ -452,7 +460,7 @@ Arch_ParseArchive(char **pp, GNodeList *gns, GNode *scope)
* See ArchFindMember for an almost identical copy of this code.
*/
static struct ar_hdr *
-ArchStatMember(const char *archive, const char *member, Boolean addToCache)
+ArchStatMember(const char *archive, const char *member, bool addToCache)
{
#define AR_MAX_NAME_LEN (sizeof arh.ar_name - 1)
FILE *arch;
@@ -713,7 +721,7 @@ ArchSVR4Entry(Arch *ar, char *inout_name, size_t size, FILE *arch)
#endif
-static Boolean
+static bool
ArchiveMember_HasName(const struct ar_hdr *hdr,
const char *name, size_t namelen)
{
@@ -721,22 +729,22 @@ ArchiveMember_HasName(const struct ar_hdr *hdr,
const char *ar_name = hdr->AR_NAME;
if (strncmp(ar_name, name, namelen) != 0)
- return FALSE;
+ return false;
if (namelen >= ar_name_len)
return namelen == ar_name_len;
/* hdr->AR_NAME is space-padded to the right. */
if (ar_name[namelen] == ' ')
- return TRUE;
+ return true;
/* In archives created by GNU binutils 2.27, the member names end with
* a slash. */
if (ar_name[namelen] == '/' &&
(namelen == ar_name_len || ar_name[namelen + 1] == ' '))
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
/*
@@ -951,7 +959,7 @@ Arch_UpdateMTime(GNode *gn)
{
struct ar_hdr *arh;
- arh = ArchStatMember(GNode_VarArchive(gn), GNode_VarMember(gn), TRUE);
+ arh = ArchStatMember(GNode_VarArchive(gn), GNode_VarMember(gn), true);
if (arh != NULL)
gn->mtime = (time_t)strtol(arh->ar_date, NULL, 10);
else
@@ -1058,26 +1066,26 @@ Arch_FindLib(GNode *gn, SearchPath *path)
* since this is used by 'ar' rules that affect the data contents of the
* archive, not by ranlib rules, which affect the TOC.
*/
-Boolean
+bool
Arch_LibOODate(GNode *gn)
{
- Boolean oodate;
+ bool oodate;
if (gn->type & OP_PHONY) {
- oodate = TRUE;
+ oodate = true;
} else if (!GNode_IsTarget(gn) && Lst_IsEmpty(&gn->children)) {
- oodate = FALSE;
+ oodate = false;
} else if ((!Lst_IsEmpty(&gn->children) && gn->youngestChild == NULL) ||
(gn->mtime > now) ||
(gn->youngestChild != NULL &&
gn->mtime < gn->youngestChild->mtime)) {
- oodate = TRUE;
+ oodate = true;
} else {
#ifdef RANLIBMAG
struct ar_hdr *arh; /* Header for __.SYMDEF */
int modTimeTOC; /* The table-of-contents' mod time */
- arh = ArchStatMember(gn->path, RANLIBMAG, FALSE);
+ arh = ArchStatMember(gn->path, RANLIBMAG, false);
if (arh != NULL) {
modTimeTOC = (int)strtol(arh->ar_date, NULL, 10);
@@ -1094,10 +1102,10 @@ Arch_LibOODate(GNode *gn)
*/
if (DEBUG(ARCH) || DEBUG(MAKE))
debug_printf("no toc...");
- oodate = TRUE;
+ oodate = true;
}
#else
- oodate = FALSE;
+ oodate = false;
#endif
}
return oodate;
@@ -1119,7 +1127,7 @@ Arch_End(void)
#endif
}
-Boolean
+bool
Arch_IsLib(GNode *gn)
{
static const char armag[] = "!<arch>\n";
@@ -1127,11 +1135,11 @@ Arch_IsLib(GNode *gn)
int fd;
if ((fd = open(gn->path, O_RDONLY)) == -1)
- return FALSE;
+ return false;
if (read(fd, buf, sizeof buf) != sizeof buf) {
(void)close(fd);
- return FALSE;
+ return false;
}
(void)close(fd);