1 /* 2 * ldelete.c 3 * al_ldelete() 4 */ 5 6 7 /* 8 This file is part of Atclib. 9 10 Atclib is Copyright � 1995-1999 Andr� Majorel. 11 12 This library is free software; you can redistribute it and/or 13 modify it under the terms of the GNU Library General Public 14 License as published by the Free Software Foundation; either 15 version 2 of the License, or (at your option) any later version. 16 17 This library is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 Library General Public License for more details. 21 22 You should have received a copy of the GNU Library General Public 23 License along with this library; if not, write to the Free 24 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 25 02111-1307, USA. 26 */ 27 28 29 #include <stdlib.h> 30 31 #define AL_AILLEGAL_ACCESS 32 #include "atclib.h" 33 34 al_ldelete(al_llist_t * l)35int al_ldelete (al_llist_t *l) 36 { 37 al_lelt_t *elt_to_delete; 38 39 al_lcheckmagic (l); 40 if (l->current == NULL || l->ateol) 41 { 42 al_aerrno = AL_AEOL; 43 return AL_AEOL; 44 } 45 46 elt_to_delete = l->current; 47 if (l->current == l->first) 48 { 49 l->first = l->current->next; 50 l->current = l->first; 51 } 52 else 53 { 54 l->prev->next = l->current->next; 55 if (l->current->next == NULL) 56 l->ateol = 1; 57 else 58 l->current = l->current->next; 59 } 60 /* to help being immune from stale pointers and detect the following 61 error: al_lgetpos() al_ldelete() al_lsetpos() */ 62 elt_to_delete->next = AL_AINVALIDPOINTER; 63 free (elt_to_delete); 64 l->total--; 65 66 return 0; 67 } 68 69