sprintf(): Fix a serious bug; snprintf(): New function.
[bertos.git] / mware / list.h
index 8989728edefa09afec6b3296cbec3568c7f37db3..a0451eb5794308febaa48d49003708ccf40f1c9f 100755 (executable)
@@ -1,8 +1,8 @@
 /*!
  * \file
+ * Copyright (C) 2003,2004 Develer S.r.l. (http://www.develer.com/)
  * Copyright (C) 2001 Bernardo Innocenti <bernie@develer.com>
- * Copyright (C) 2003 Develer S.r.l. (http://www.develer.com/)
- * All Rights Reserved.
+ * This file is part of DevLib - See devlib/README for information.
  *
  * \version $Id$
  *
  * \brief General pourpose double-linked lists
  */
 
-/*
- * $Log$
- * Revision 1.1  2004/05/23 15:43:16  bernie
- * Import mware modules.
- *
- */
+/*#*
+ *#* $Log$
+ *#* Revision 1.7  2004/08/25 14:12:09  rasky
+ *#* Aggiornato il comment block dei log RCS
+ *#*
+ *#* Revision 1.6  2004/07/30 14:34:10  rasky
+ *#* Vari fix per documentazione e commenti
+ *#* Aggiunte PP_CATn e STATIC_ASSERT
+ *#*
+ *#* Revision 1.5  2004/07/20 23:45:01  bernie
+ *#* Finally remove redundant protos.
+ *#*
+ *#* Revision 1.4  2004/07/18 22:12:53  bernie
+ *#* Fix warnings with GCC 3.3.2.
+ *#*
+ *#* Revision 1.3  2004/07/18 22:01:43  bernie
+ *#* REMHEAD(), REMTAIL(): Move to list.h as inline functions.
+ *#*
+ *#* Revision 1.2  2004/06/03 11:27:09  bernie
+ *#* Add dual-license information.
+ *#*
+ *#* Revision 1.1  2004/05/23 15:43:16  bernie
+ *#* Import mware modules.
+ *#*
+ *#*/
 #ifndef MWARE_LIST_H
 #define MWARE_LIST_H
 
@@ -108,15 +127,38 @@ typedef struct _List
 /*! Tell whether a list is empty */
 #define ISLISTEMPTY(l)  ( (l)->head == (Node *)(&(l)->null) )
 
-/*! \name Extract an element from the head/tail of the list. If the list empty, return NULL. */
-/*\{*/
-#define REMHEAD(l) _list_rem_head(l)
-#define REMTAIL(l) _list_rem_tail(l)
-/*\}*/
+/*!
+ * Unlink a node from the head of the list \a l.
+ * \return Pointer to node, or NULL if the list was empty.
+ */
+INLINE Node *REMHEAD(List *l)
+{
+       Node *n;
+
+       if (ISLISTEMPTY(l))
+               return (Node *)0;
+
+       n = l->head;
+       l->head = n->succ;
+       n->succ->pred = (Node *)l;
+       return n;
+}
+
+/*!
+ * Unlink a node from the tail of the list \a l.
+ * \return Pointer to node, or NULL if the list was empty.
+ */
+INLINE Node *REMTAIL(List *l)
+{
+       Node *n;
 
-/* Prototypes for out-of-line functions */
-Node *_list_rem_head(List *l);
-Node *_list_rem_tail(List *l);
+       if (ISLISTEMPTY(l))
+               return (Node *)0;
 
+       n = l->tail;
+       l->tail = n->pred;
+       n->pred->succ = (Node *)&l->null;
+       return n;
+}
 
 #endif /* MWARE_LIST_H */