コード例 #1
0
ssize_t esparser_write(struct file *file,
                       struct stream_buf_s *stbuf,
                       const char __user *buf, size_t count)
{
    s32 r;
    u32 len = count;
    if (buf == NULL || count == 0) {
        return -EINVAL;
    }

    if (stbuf_space(stbuf) < count) {
        if (file->f_flags & O_NONBLOCK) {
            return -EAGAIN;
        }

        len = min(stbuf_size(stbuf) / 8, len);

        if (stbuf_space(stbuf) < len) {
            r = stbuf_wait_space(stbuf, len);
            if (r < 0) {
                return r;
            }
        }
    }
    mutex_lock(&esparser_mutex);
    r = _esparser_write(buf, len, stbuf->type);
    mutex_unlock(&esparser_mutex);

    return r;
}