(file) Return to list.c CVS log (file) (dir) Up to [OMI] / omi / base

  1 mike  1.1 /*
  2           **==============================================================================
  3           **
  4           ** Open Management Infrastructure (OMI)
  5           **
  6           ** Copyright (c) Microsoft Corporation
  7           ** 
  8           ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  9           ** use this file except in compliance with the License. You may obtain a copy 
 10           ** of the License at 
 11           **
 12           **     http://www.apache.org/licenses/LICENSE-2.0 
 13           **
 14           ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15           ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
 16           ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
 17           ** MERCHANTABLITY OR NON-INFRINGEMENT. 
 18           **
 19           ** See the Apache 2 License for the specific language governing permissions 
 20           ** and limitations under the License.
 21           **
 22 mike  1.1 **==============================================================================
 23           */
 24           
 25           #include "list.h"
 26           
 27           void List_Prepend(
 28               ListElem** head_,
 29               ListElem** tail_,
 30               ListElem* elem)
 31           {
 32               ListElem* head = *head_;
 33               ListElem* tail = *tail_;
 34           
 35               elem->prev = NULL;
 36           
 37               if (head)
 38               {
 39                   head->prev = elem;
 40                   elem->next = head;
 41                   head = elem;
 42               }
 43 mike  1.1     else
 44               {
 45                   elem->next = NULL;
 46                   head = elem;
 47                   tail = elem;
 48               }
 49           
 50               *head_ = head;
 51               *tail_ = tail;
 52           }
 53           
 54           void List_Append(
 55               ListElem** head_,
 56               ListElem** tail_,
 57               ListElem* elem)
 58           {
 59               ListElem* head = *head_;
 60               ListElem* tail = *tail_;
 61           
 62               elem->next = NULL;
 63           
 64 mike  1.1     if (tail)
 65               {
 66                   tail->next = elem;
 67                   elem->prev = tail;
 68                   tail = elem;
 69               }
 70               else
 71               {
 72                   elem->next = NULL;
 73                   head = elem;
 74                   tail = elem;
 75               }
 76           
 77               *head_ = head;
 78               *tail_ = tail;
 79           }
 80           
 81           void List_Remove(
 82               ListElem** head_,
 83               ListElem** tail_,
 84               ListElem* elem)
 85 mike  1.1 {
 86               ListElem* head = *head_;
 87               ListElem* tail = *tail_;
 88           
 89               if (elem->next)
 90                   elem->next->prev = elem->prev;
 91               else
 92                   tail = elem->prev;
 93           
 94               if (elem->prev)
 95                   elem->prev->next = elem->next;
 96               else
 97                   head = elem->next;
 98           
 99               *head_ = head;
100               *tail_ = tail;
101           }

ViewCVS 0.9.2