Added common macros for linked lists

Linked lists are used a various places, so common macros have been added
to avoid code duplication and thus (as it just was the case) so we don't
have to crawl around the place looking for copies of the same code with
the same error in it after finding one.