# \[C\] Vider un fifo

**URL:** <https://www.debian-fr.org/t/c-vider-un-fifo/58276>\
**Category:** Programmation\
**Created:** [Février 21, 2016, 5:39 UTC](https://www.debian-fr.org/t/c-vider-un-fifo/58276 "2016-02-21T17:39:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thuban](https://www.debian-fr.org/user_avatar/www.debian-fr.org/thuban/32/4177_2.png) [@thuban](https://www.debian-fr.org/u/thuban)\
**Post date:** [Février 21, 2016, 5:39 UTC](https://www.debian-fr.org/t/c-vider-un-fifo/58276/1 "2016-02-21T17:39:37Z")

</div>

Entre chaques fois où le programme lis le contenu du fifo, il semble qu’il n’est pas vidé, puisqu’à chaque fois que je fais un

```auto

```

Ce qui était dedans avant n’est pas totalement effacé.

Comment vider un fifo?

Le code :

```auto

    #define FIFO "/home/xavier/mon_fifo"

    int ret = 0;
    ret = mkfifo(FIFO, ACCESSPERMS);
    if (ret == -1) perror("fifo creation")
    char buf[BUFSIZ];
    buf[0] = '\0';

    int f = open(FIFO, O_NONBLOCK);
    if (f == -1){
        perror("fifo opening");
        return smprintf("%s","");
    }

    if (read(f, buf, sizeof(buf) ) == -1){
        perror("fifo read");
        return smprintf("%s","");
    }
    close(f);
    buf[strlen(buf)-1] = '\0';
    printf("%s",buf);

```
