Projet Informatique Théorique 2016
Instructions et Documentation
fifo.c
1 /*
2  * Ce fichier fait partie d'un projet de programmation donné en Licence 3
3  * à l'Université de Bordeaux.
4  *
5  * Copyright (C) 2014 Adrien Boussicault
6  *
7  * This Library is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This Library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this Library. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #include "outils.h"
23 #include "fifo.h"
24 
25 typedef struct List List;
26 
27 struct List {
28  List * next;
29  intptr_t element;
30 };
31 
32 struct Fifo {
33  List * list;
34 };
35 
36 List* allouer_list( List * next, intptr_t element ){
37  List* res = (List*) xmalloc( sizeof(List) );
38  res->next = next;
39  res->element = element;
40  return res;
41 }
42 
43 void liberer_list( List * list ){
44  xfree( list );
45 }
46 
47 void ajouter_fifo( Fifo* fifo, intptr_t element ){
48  fifo->list = allouer_list( fifo->list, element );
49 }
50 
51 intptr_t retirer_fifo( Fifo* fifo ){
52  intptr_t res = fifo->list->element;
53  List* tmp = fifo->list;
54  fifo->list = fifo->list->next;
55  liberer_list( tmp );
56  return res;
57 }
58 
59 intptr_t obtenir_fifo( Fifo* fifo ){
60  return fifo->list->element;
61 }
62 
63 int est_vide( Fifo* fifo ){
64  return fifo->list == NULL;
65 }
66 
67 Fifo* creer_fifo(){
68  Fifo* res = xmalloc( sizeof(Fifo) );
69  res->list = NULL;
70  return res;
71 }
72 
73 void vider_list( List * list ){
74  if( list ){
75  vider_list( list->next );
76  xfree( list );
77  }
78 }
79 
80 void liberer_fifo( Fifo* file ){
81  vider_list( file->list );
82  xfree( file );
83 }
Definition: fifo.c:32
Definition: fifo.c:27