Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. list.c
  5. Abstract:
  6. List Entry manipulation functions
  7. Author:
  8. Based on code by Mike Tsang (MikeTs)
  9. Stephane Plante (Splante)
  10. Environment:
  11. User mode only
  12. Revision History:
  13. --*/
  14. #include "pch.h"
  15. VOID
  16. EXPORT
  17. ListRemoveEntry(
  18. PLIST List,
  19. PPLIST ListHead
  20. )
  21. /*++
  22. Routine Description:
  23. Remove an Entry from the list
  24. Arguments:
  25. List - Entry to be removed
  26. ListHead - List to be removed from
  27. Return Value:
  28. None
  29. --*/
  30. {
  31. ASSERT(ListHead);
  32. ASSERT(List != NULL);
  33. if (List->plistNext == List) {
  34. //
  35. // This is the only object in the list, it must be the head too.
  36. //
  37. ASSERT(List == *ListHead);
  38. *ListHead = NULL;
  39. } else {
  40. if (List == *ListHead) {
  41. //
  42. // The entry is at the head, so the next one becomes the new
  43. // head.
  44. //
  45. *ListHead = (*ListHead)->plistNext;
  46. }
  47. List->plistNext->plistPrev = List->plistPrev;
  48. List->plistPrev->plistNext = List->plistNext;
  49. }
  50. }
  51. PLIST
  52. EXPORT
  53. ListRemoveHead(
  54. PPLIST ListHead
  55. )
  56. /*++
  57. Routine Description:
  58. Remove the head entry of the list
  59. Arguments:
  60. ListHead - List to remove entry from
  61. Return Value:
  62. PLIST - Removed Item
  63. --*/
  64. {
  65. PLIST list;
  66. list = *ListHead;
  67. if ( list != NULL) {
  68. ListRemoveEntry(list, ListHead);
  69. }
  70. return list;
  71. }
  72. PLIST
  73. EXPORT
  74. ListRemoveTail(
  75. PPLIST ListHead
  76. )
  77. /*++
  78. Routine Description:
  79. Remove the tail entry from the list
  80. Arguments:
  81. ListHead - List to remove entry from
  82. Return Value:
  83. PLIST - Removed Item
  84. --*/
  85. {
  86. PLIST list;
  87. if (*ListHead == NULL) {
  88. list = NULL;
  89. } else {
  90. //
  91. // List is not empty, so find the tail.
  92. //
  93. list = (*ListHead)->plistPrev;
  94. ListRemoveEntry(list, ListHead);
  95. }
  96. return list;
  97. }
  98. VOID
  99. EXPORT
  100. ListInsertHead(
  101. PLIST List,
  102. PPLIST ListHead
  103. )
  104. /*++
  105. Routine Description:
  106. Insert an Entry at the head of the list
  107. Arguments:
  108. List List object to be inserted
  109. ListHead The list where to insert the object
  110. Return Value:
  111. None
  112. --*/
  113. {
  114. ListInsertTail(List, ListHead);
  115. *ListHead = List;
  116. }
  117. VOID
  118. EXPORT
  119. ListInsertTail(
  120. PLIST List,
  121. PPLIST ListHead
  122. )
  123. /*++
  124. Routine Description:
  125. Insert an Entry at the tail of the list
  126. Arguments:
  127. List List object to be inserted
  128. ListHead The list where to insert the object
  129. Return Value:
  130. None
  131. --*/
  132. {
  133. if (*ListHead == NULL) {
  134. //
  135. // List is empty, so this becomes the head.
  136. //
  137. *ListHead = List;
  138. List->plistPrev = List->plistNext = List;
  139. } else {
  140. List->plistNext = *ListHead;
  141. List->plistPrev = (*ListHead)->plistPrev;
  142. (*ListHead)->plistPrev->plistNext = List;
  143. (*ListHead)->plistPrev = List;
  144. }
  145. }