1 /* 2 * Initial implementation: 3 * Copyright (c) 2002 Robert Drehmel 4 * All rights reserved. 5 * 6 * As long as the above copyright statement and this notice remain 7 * unchanged, you can do what ever you want with this file. 8 */ 9 #include <sys/cdefs.h> 10 #define _SEARCH_PRIVATE 11 #include <search.h> 12 #ifdef DEBUG 13 #include <stdio.h> 14 #else 15 #include <stdlib.h> /* for NULL */ 16 #endif 17 18 void 19 insque(void *element, void *pred) 20 { 21 struct que_elem *prev, *next, *elem; 22 23 elem = (struct que_elem *)element; 24 prev = (struct que_elem *)pred; 25 26 if (prev == NULL) { 27 elem->prev = elem->next = NULL; 28 return; 29 } 30 31 next = prev->next; 32 if (next != NULL) { 33 #ifdef DEBUG 34 if (next->prev != prev) { 35 fprintf(stderr, "insque: Inconsistency detected:" 36 " next(%p)->prev(%p) != prev(%p)\n", 37 next, next->prev, prev); 38 } 39 #endif 40 next->prev = elem; 41 } 42 prev->next = elem; 43 elem->prev = prev; 44 elem->next = next; 45 } 46