-#define LDAP_TAILQ_PREV(elm, headname, field) \
- (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+#define LDAP_TAILQ_PREV(elm, head, type, field) \
+ ((struct type *)((elm)->field.tqe_prev) == LDAP_TAILQ_FIRST(head) ? \
+ NULL : \
+ ((struct type *) \
+ ((char *)((elm)->field.tqe_prev) - offsetof(struct type, field))))