Back to index

avfs  1.0.1
Defines | Functions
filebuf.h File Reference
#include "avfs.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define FILEBUF_NONBLOCK   (1 << 0)
#define FILEBUF_WRITE   (1 << 1)

Functions

struct filebufav_filebuf_new (int fd, int flags)
int av_filebuf_eof (struct filebuf *fb)
int av_filebuf_check (struct filebuf *fbs[], unsigned int numfbs, long timeoutms)
int av_filebuf_readline (struct filebuf *fb, char **linep)
int av_filebuf_getline (struct filebuf *fb, char **linep, long timeoutms)
avssize_t av_filebuf_read (struct filebuf *fb, char *buf, avsize_t nbytes)
avssize_t av_filebuf_write (struct filebuf *fb, const char *buf, avsize_t nbytes)

Define Documentation

#define FILEBUF_NONBLOCK   (1 << 0)

Definition at line 11 of file filebuf.h.

#define FILEBUF_WRITE   (1 << 1)

Definition at line 12 of file filebuf.h.


Function Documentation

int av_filebuf_check ( struct filebuf fbs[],
unsigned int  numfbs,
long  timeoutms 
)

Definition at line 100 of file filebuf.c.

{
    int res;
    struct pollfd *pf;

    pf = (struct pollfd *) av_malloc(sizeof(*pf) * numfbs);
    filebuf_fill_poll(fbs, pf, numfbs);
    res = poll(pf, numfbs, timeoutms);
    if(res == -1) {
        av_log(AVLOG_ERROR, "filebuf: poll error: %s", strerror(errno));
        res = -EIO;
    }
    else if(res > 0) {
        filebuf_check_poll(fbs, pf, numfbs);
        res = 1;
    }
    av_free(pf);

    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int av_filebuf_eof ( struct filebuf fb)

Definition at line 62 of file filebuf.c.

{
    return fb->eof;
}

Here is the caller graph for this function:

int av_filebuf_getline ( struct filebuf fb,
char **  linep,
long  timeoutms 
)

Definition at line 240 of file filebuf.c.

{
    int res;
    char *line;

    *linep = NULL;
    while(1) {
        res = av_filebuf_readline(fb, &line);
        if(res < 0)
            return res;
        if(res == 1)
            break;

        if(av_filebuf_eof(fb))
            return 1;

        res = av_filebuf_check(&fb, 1, timeoutms);
        if(res < 0)
            return res;

        if(res == 0) 
            return 0;
    }

    *linep = line;

    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct filebuf* av_filebuf_new ( int  fd,
int  flags 
) [read]

Definition at line 37 of file filebuf.c.

{
    struct filebuf *fb;
    int oflags;

    AV_NEW_OBJ(fb, free_filebuf);

    if(flags & FILEBUF_NONBLOCK) {
        oflags = fcntl(fd, F_GETFL);
        oflags = oflags == -1 ? 0 : oflags;
        fcntl(fd, F_SETFL, oflags | O_NONBLOCK);
    }

    fb->flags = flags;
    fb->fd = fd;
    fb->size = 0;
    fb->nbytes = 0;
    fb->ptr = 0;
    fb->buf = NULL;
    fb->eof = 0;
    fb->avail = 0;

    return fb;
}

Here is the call graph for this function:

Here is the caller graph for this function:

avssize_t av_filebuf_read ( struct filebuf fb,
char *  buf,
avsize_t  nbytes 
)

Definition at line 142 of file filebuf.c.

{
    if(fb->nbytes > 0) {
        avsize_t nact = AV_MIN(fb->nbytes, nbytes);
        
        memcpy(buf, fb->buf + fb->ptr, nact);
        fb->ptr += nact;
        fb->nbytes -= nact;

        return nact;
    }

    return  filebuf_real_read(fb, buf, nbytes);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int av_filebuf_readline ( struct filebuf fb,
char **  linep 
)

Definition at line 222 of file filebuf.c.

{
    avssize_t nbytes;

    *resp = NULL;

    nbytes = filebuf_lineend(fb);
    if(nbytes <= 0)
        return nbytes;
    
    *resp = av_strndup(fb->buf + fb->ptr, nbytes);

    fb->ptr += nbytes;
    fb->nbytes -= nbytes;

    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

avssize_t av_filebuf_write ( struct filebuf fb,
const char *  buf,
avsize_t  nbytes 
)

Definition at line 157 of file filebuf.c.

{
    avssize_t res;

    if(!fb->avail)
        return 0;

    fb->avail = 0;
    res = write(fb->fd, buf, nbytes);
    if(res < 0) {
        av_log(AVLOG_ERROR, "filebuf: write error: %s", strerror(errno));
        return -EIO;
    }

    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function: