src/utils.c

00001 /***************************************************************************
00002  *            utils.c
00003  *
00004  *  Wed Feb 23 14:15:36 2005
00005  *  Copyright  2005  Simon Morlat
00006  *  Email simon.morlat@linphone.org
00007  ****************************************************************************/
00008 /*
00009   The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
00010   Copyright (C) 2001  Simon MORLAT simon.morlat@linphone.org
00011 
00012   This library is free software; you can redistribute it and/or
00013   modify it under the terms of the GNU Lesser General Public
00014   License as published by the Free Software Foundation; either
00015   version 2.1 of the License, or (at your option) any later version.
00016 
00017   This library is distributed in the hope that it will be useful,
00018   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020   Lesser General Public License for more details.
00021 
00022   You should have received a copy of the GNU Lesser General Public
00023   License along with this library; if not, write to the Free Software
00024   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 */
00026 
00027 #include "ortp/port.h"
00028 #include "utils.h"
00029 
00030 OList *o_list_new(void *data){
00031         OList *new_elem=(OList*)ortp_new0(OList,1);
00032         new_elem->data=data;
00033         return new_elem;
00034 }
00035 
00036 OList * o_list_append(OList *elem, void * data){
00037         OList *new_elem=o_list_new(data);
00038         OList *it=elem;
00039         if (elem==NULL) return new_elem;
00040         while (it->next!=NULL) it=o_list_next(it);
00041         it->next=new_elem;
00042         new_elem->prev=it;
00043         return elem;
00044 }
00045 
00046 OList * o_list_free(OList *list){
00047         OList *elem = list;
00048         OList *tmp;
00049         return_val_if_fail(list, list);
00050         while(elem->next!=NULL) {
00051                 tmp = elem;
00052                 elem = elem->next;
00053                 ortp_free(tmp);
00054         }
00055         ortp_free(elem);
00056         return NULL;
00057 }
00058 
00059 OList *o_list_remove_link(OList *list, OList *elem){
00060         OList *ret;
00061         if (elem==list){
00062                 ret=elem->next;
00063                 elem->prev=NULL;
00064                 elem->next=NULL;
00065                 if (ret!=NULL) ret->prev=NULL;
00066                 ortp_free(elem);
00067                 return ret;
00068         }
00069         elem->prev->next=elem->next;
00070         if (elem->next!=NULL) elem->next->prev=elem->prev;
00071         elem->next=NULL;
00072         elem->prev=NULL;
00073         ortp_free(elem);
00074         return list;
00075 }
00076 
00077 OList * o_list_remove(OList *list, void *data){
00078         OList *it;
00079         for(it=list;it!=NULL;it=it->next){
00080                 if (it->data==data){
00081                         return o_list_remove_link(list,it);
00082                 }
00083         }
00084         return list;
00085 }
00086 

Generated on Fri Feb 15 00:06:03 2008 for oRTP by  doxygen 1.5.4