diff --git a/usr.bin/make/lst.h b/usr.bin/make/lst.h index bb08f2c1b610..e9c8f1ccb7ef 100644 --- a/usr.bin/make/lst.h +++ b/usr.bin/make/lst.h @@ -120,7 +120,7 @@ ReturnStatus Lst_Append(Lst *, LstNode *, void *); /* Place an element at the end of a lst. */ #define Lst_AtEnd(LST, D) (Lst_Append((LST), Lst_Last(LST), (D))) /* Remove an element */ -ReturnStatus Lst_Remove(Lst *, LstNode *); +void Lst_Remove(Lst *, LstNode *); /* Replace a node with a new value */ #define Lst_Replace(NODE, D) (((NODE) == NULL) ? FAILURE : \ (((NODE)->datum = (D)), SUCCESS)) diff --git a/usr.bin/make/lst.lib/lstRemove.c b/usr.bin/make/lst.lib/lstRemove.c index 035218d6225c..aa0fd996a8aa 100644 --- a/usr.bin/make/lst.lib/lstRemove.c +++ b/usr.bin/make/lst.lib/lstRemove.c @@ -64,42 +64,26 @@ __FBSDID("$FreeBSD$"); * *----------------------------------------------------------------------- */ -ReturnStatus +void Lst_Remove(Lst *list, LstNode *ln) { - if (!Lst_Valid(list) || !Lst_NodeValid(ln, list)) { - return (FAILURE); - } - /* * unlink it from the list */ - if (ln->nextPtr != NULL) { + if (ln->nextPtr != NULL) + /* unlink from the backward chain */ ln->nextPtr->prevPtr = ln->prevPtr; - } - if (ln->prevPtr != NULL) { - ln->prevPtr->nextPtr = ln->nextPtr; - } - - /* - * if either the firstPtr or lastPtr of the list point to this node, - * adjust them accordingly - */ - if (list->firstPtr == ln) { - list->firstPtr = ln->nextPtr; - } - if (list->lastPtr == ln) { + else + /* this was the last element */ list->lastPtr = ln->prevPtr; - } - /* - * the only way firstPtr can still point to ln is if ln is the last - * node on the list. The list is, therefore, empty and is marked as such - */ - if (list->firstPtr == ln) { - list->firstPtr = NULL; - } + if (ln->prevPtr != NULL) + /* unlink from the forward chain */ + ln->prevPtr->nextPtr = ln->nextPtr; + else + /* this was the first element */ + list->firstPtr = ln->nextPtr; /* * note that the datum is unmolested. The caller must free it as @@ -110,6 +94,4 @@ Lst_Remove(Lst *list, LstNode *ln) } else { ln->flags |= LN_DELETED; } - - return (SUCCESS); }