insremque.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. see <http://www.gnu.org/licenses/>. */
  14. #include <features.h>
  15. #include <stddef.h>
  16. #include <search.h>
  17. #ifdef L_insque
  18. /* Insert ELEM into a doubly-linked list, after PREV. */
  19. void
  20. insque (void *elem, void *prev)
  21. {
  22. if (prev == NULL)
  23. {
  24. ((struct qelem *) elem)->q_forw = NULL;
  25. ((struct qelem *) elem)->q_back = NULL;
  26. }
  27. else
  28. {
  29. struct qelem *next = ((struct qelem *) prev)->q_forw;
  30. ((struct qelem *) prev)->q_forw = (struct qelem *) elem;
  31. if (next != NULL)
  32. next->q_back = (struct qelem *) elem;
  33. ((struct qelem *) elem)->q_forw = next;
  34. ((struct qelem *) elem)->q_back = (struct qelem *) prev;
  35. }
  36. }
  37. #endif
  38. #ifdef L_remque
  39. /* Unlink ELEM from the doubly-linked list that it is in. */
  40. void
  41. remque (void *elem)
  42. {
  43. struct qelem *next = ((struct qelem *) elem)->q_forw;
  44. struct qelem *prev = ((struct qelem *) elem)->q_back;
  45. if (next != NULL)
  46. next->q_back = prev;
  47. if (prev != NULL)
  48. prev->q_forw = (struct qelem *) next;
  49. }
  50. #endif