示例#1
0
文件: zfile.c 项目: evoskuil/czmq
zchunk_t *
zfile_read (zfile_t *self, size_t bytes, off_t offset)
{
    assert (self);
    assert (self->handle);

    self->eof = false;
    //  Calculate real number of bytes to read
    if (offset > self->cursize) {
        // if we tried to read 'after' the cursise, then we are at the end
        bytes = 0;
        self->eof = true;
    }
    else
    if (bytes > (size_t) (self->cursize - offset)) {
        // if we are trying to read more than there is, we are at the end
        self->eof = true;
        bytes = (size_t) (self->cursize - offset);
    }

    if (fseek (self->handle, (long) offset, SEEK_SET) == -1) {
        return NULL;
    }

    return zchunk_read (self->handle, bytes);
}
示例#2
0
文件: zchunk.c 项目: HunterChen/czmq
zchunk_t *
zchunk_slurp (const char *filename, size_t maxsize)
{
    size_t size = zsys_file_size (filename);
    if ((ssize_t) size == -1)
        return NULL;

    if (size > maxsize && maxsize != 0)
        size = maxsize;

    FILE *handle = fopen (filename, "r");
    zchunk_t *chunk = zchunk_read (handle, size);
    assert (chunk);
    fclose (handle);
    return chunk;
}
示例#3
0
文件: zfile.c 项目: dadavita/stalk
zchunk_t *
zfile_read (zfile_t *self, size_t bytes, off_t offset)
{
    assert (self);
    assert (self->handle);

    //  Calculate real number of bytes to read
    if (offset > self->cursize)
        bytes = 0;
    else if (bytes > (size_t) (self->cursize - offset))
        bytes = (size_t) (self->cursize - offset);

    if (fseek (self->handle, (long) offset, SEEK_SET) == -1)
        return NULL;

    self->eof = false;
    zchunk_t *chunk = zchunk_read (self->handle, bytes);
    if (chunk)
        self->eof = zchunk_size (chunk) < bytes;
    return chunk;
}
示例#4
0
文件: qzchunk.cpp 项目: sphaero/czmq
///
//  Read chunk from an open file descriptor
QZchunk * QZchunk::read (FILE *handle, size_t bytes)
{
    QZchunk *rv = new QZchunk (zchunk_read (handle, bytes));
    return rv;
}