Ejemplo n.º 1
0
Archivo: cgdb.c Proyecto: i4fumi/cgdb
static int cgdb_resize_term(int fd)
{
    int c, result;

    if (read(resize_pipe[0], &c, sizeof (int)) < sizeof (int)) {
        logger_write_pos(logger, __FILE__, __LINE__, "read from resize pipe");
        return -1;
    }

    /* If there is more input in the pipe, that means another resize has
     * been recieved, and we still have not handled this one. So, skip this
     * one and only handle the next one.
     */
    result = io_data_ready(resize_pipe[0], 0);
    if (result == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "io_data_ready");
        return -1;
    }

    if (result)
        return 0;

    if (if_resize_term() == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "if_resize_term error");
        return -1;
    }

    return 0;
}
Ejemplo n.º 2
0
Archivo: io.cpp Proyecto: cgdb/cgdb
int io_getchar(int fd, unsigned int ms, int *key)
{
    char c;
    int ret;
    int flag = 0;
    int val;

    if (!key)
        return -1;

    val = io_data_ready(fd, ms);
    if (val == -1) {
        logger_write_pos(logger, __FILE__, __LINE__, "Errno(%d)\n", errno);
        return -1;
    }

    if (val == 0)
        return 0;               /* Nothing to read. */

    /* Set nonblocking */
    flag = fcntl(fd, F_GETFL, 0);
    fcntl(fd, F_SETFL, flag | O_NONBLOCK);

  read_again:

    /* Read a char */
    ret = read(fd, &c, 1);

    if (ret == -1 && errno == EAGAIN)
        c = 0;                  /* No data available */
    else if (ret == -1 && errno == EINTR)
        goto read_again;
    else if (ret == -1) {
        c = 0;
        logger_write_pos(logger, __FILE__, __LINE__, "Errno(%d)\n", errno);
    } else if (ret == 0) {
        c = 0;
        ret = -1;
        logger_write_pos(logger, __FILE__, __LINE__, "Read returned nothing\n");
    }

    /* Set to original state */
    fcntl(fd, F_SETFL, flag);

    if (ret == -1)
        return -1;

    *key = c;
    return 1;
}
Ejemplo n.º 3
0
int kui_callback(const int fd, const unsigned int ms, const void *obj, int *key)
{

    struct kuictx *kctx = (struct kuictx *) obj;
    int result;

    if (!key)
        return -1;

    result = kui_cangetkey(kctx);
    if (result == -1)
        return -1;

    if (result == 1) {
        *key = kui_getkey(kctx);
        if (*key == -1)
            return -1;
    }

    /* If there is no data ready, check the I/O */
    if (result == 0) {
        result = io_data_ready(kctx->fd, ms);
        if (result == -1)
            return -1;

        if (result == 1) {
            *key = kui_getkey(kctx);
            if (*key == -1)
                return -1;
        }

        if (result == 0)
            return 0;
    }

    return 1;
}