Exemplo n.º 1
0
int
rs_read_uint(FILE *inf, unsigned int *i)
{
    unsigned char bytes[4];
    int  input;
    unsigned char *buf = (unsigned char *)&input;
    
    if (read_error || format_error)
        return(READSTAT);

    rs_read(inf, &input, 4);

    if (big_endian)
    {
        bytes[3] = buf[0];
        bytes[2] = buf[1];
        bytes[1] = buf[2];
        bytes[0] = buf[3];
        buf = bytes;
    }
    
    *i = *((unsigned int *) buf);

    return(READSTAT);
}
Exemplo n.º 2
0
LOCAL WORD rs_load (WORD *global, CONST BYTE *fname)
{
    if (!rs_read (global, fname))
        return (FALSE);

    rs_fixindex (global);

    return (TRUE);
}
Exemplo n.º 3
0
int
rs_read_char(FILE *inf, char *c)
{
    if (read_error || format_error)
        return(READSTAT);

    rs_read(inf, c, 1);

    return(READSTAT);
}
Exemplo n.º 4
0
int
rs_read_boolean(FILE *inf, bool *i)
{
    unsigned char buf = 0;
    
    if (read_error || format_error)
        return(READSTAT);

    rs_read(inf, &buf, 1);

    *i = (buf != 0);
    
    return(READSTAT);
}
Exemplo n.º 5
0
int
rs_read_chars(FILE *inf, char *i, int count)
{
    int value = 0;
    
    if (read_error || format_error)
        return(READSTAT);

    rs_read_int(inf, &value);
    
    if (value != count)
        format_error = TRUE;

    rs_read(inf, i, count);
    
    return(READSTAT);
}
Exemplo n.º 6
0
int
rs_read_short(FILE *inf, short *i)
{
    unsigned char bytes[2];
    short  input;
    unsigned char *buf = (unsigned char *)&input;
    
    if (read_error || format_error)
        return(READSTAT);

    rs_read(inf, &input, 2);

    if (big_endian)
    {
        bytes[1] = buf[0];
        bytes[0] = buf[1];
        buf = bytes;
    }
    
    *i = *((short *) buf);

    return(READSTAT);
} 
Exemplo n.º 7
0
int rs_eof_read_binlog2(rs_reqdump_data_t *rd, void *buf, size_t size) 
{
    int         wd1, wd2, err, r;
    size_t      ms, n, ls, tl; 
    ssize_t     l;
    struct      inotify_event *e;
    char        eb[1024], *p, *f;

    n = 0;
    wd1 = -1;
    wd2 = -2;
    f = buf;
    r = RS_ERR;
    ms = rs_min((uint32_t) (rd->io_buf->last - rd->io_buf->pos), size);

    /* use io_buf */
    if(ms > 0) {
        f = rs_cpymem(f, rd->io_buf->pos, ms);
        rd->io_buf->pos += ms;
    }

    while(ms < size) {

        /* feed io_buf */
        n = fread(rd->io_buf->start, 1, rd->io_buf->size, rd->binlog_fp);

        if(n > 0) {
            ls = rs_min(n, size - ms);

            f = rs_cpymem(f, rd->io_buf->start, ls);

            rd->io_buf->pos = rd->io_buf->start + ls; 
            rd->io_buf->last = rd->io_buf->start + n;

            ms += ls;
        } else {

            if(feof(rd->binlog_fp) == 0) {
                if((err = ferror(rd->binlog_fp)) != 0) {
                    /* file error */
                    rs_log_error(RS_LOG_ERR, err, "ferror(\"%s\") failed", 
                            rd->dump_file);
                    goto free;
                }
            }

            /* set inotify */
            if(rd->notify_fd == -1) {
                rd->notify_fd = rs_init_io_watch();

                if(rd->notify_fd < 0) {
                    goto free;
                }

                wd1 = rs_add_io_watch(rd->notify_fd, rd->dump_file, 
                        RS_IN_MODIFY);

                wd2 = inotify_add_watch(rd->notify_fd, 
                        rs_master_info->binlog_idx_file, RS_IN_MODIFY);

                if(wd1 < 0 || wd2 < 0) {
                    goto free;
                }
            }

            /* test has binlog */
            if((err = rs_has_next_binlog(rd)) == RS_OK) {
                r = RS_HAS_BINLOG;
                goto free;
            }

            if(err == RS_ERR) {
                goto free;
            }

            /* sleep wait, release cpu */
            err = rs_timed_select(rd->notify_fd, RS_BINLOG_EOF_WAIT_SEC, 0);

            if(err == RS_ERR) {
                goto free;
            } else if(err == RS_TIMEDOUT) {
                continue;
            }

            l = rs_read(rd->notify_fd, eb, 1024);

            if(l <= 0) {
                goto free;
            }

            p = eb;

            e = (struct inotify_event *) eb;
            if(e == NULL) {
                goto free;
            }

            while (((char *) e - eb) < l) {
                if (e->wd == wd1 && e->mask & RS_IN_MODIFY) {
                    break;
                } else if(e->wd == wd2 && e->mask & RS_IN_MODIFY) {
                    break;
                }

                tl = sizeof(struct inotify_event) + e->len;
                e = (struct inotify_event *) (p + tl); 

                if(e == NULL) {
                    break;
                }

                p += tl;
            } // end while
        }
    }

    r = RS_OK; 
    clearerr(rd->binlog_fp);

free:

    if(rd->notify_fd != -1) {
        if(close(rd->notify_fd) != 0) {
            rs_log_error(RS_LOG_ERR, rs_errno, "close() failed"); 
            r = RS_ERR;
        }

        rd->notify_fd = -1;
    }

    return r;
}