kfile_fifo.c
Go to the documentation of this file.00001
00039 #include "kfile_fifo.h"
00040 #include "fifobuf.h"
00041
00042 #include <kern/kfile.h>
00043
00044 #include <string.h>
00045
00046 static size_t kfilefifo_read(struct KFile *_fd, void *_buf, size_t size)
00047 {
00048 KFileFifo *fd = KFILEFIFO_CAST(_fd);
00049 uint8_t *buf = (uint8_t *)_buf;
00050
00051 while (size-- && !fifo_isempty_locked(fd->fifo))
00052 *buf++ = fifo_pop_locked(fd->fifo);
00053
00054 return buf - (uint8_t *)_buf;
00055 }
00056
00057 static size_t kfilefifo_write(struct KFile *_fd, const void *_buf, size_t size)
00058 {
00059 KFileFifo *fd = KFILEFIFO_CAST(_fd);
00060 const uint8_t *buf = (const uint8_t *)_buf;
00061
00062 while (size-- && !fifo_isfull_locked(fd->fifo))
00063 fifo_push_locked(fd->fifo, *buf++);
00064
00065 return buf - (const uint8_t *)_buf;
00066 }
00067
00068 void kfilefifo_init(KFileFifo *kf, FIFOBuffer *fifo)
00069 {
00070 memset(kf, 0, sizeof(*kf));
00071
00072 kf->fifo = fifo;
00073 kf->fd.read = kfilefifo_read;
00074 kf->fd.write = kfilefifo_write;
00075 DB(kf->fd._type = KFT_KFILEFIFO);
00076 }