コード例 #1
0
ファイル: txt.c プロジェクト: JDsolution/ipnc
static int make_sure_fits_in(TXTRecordInternal *t, size_t size) {
    uint8_t *n;
    size_t nsize;
    
    assert(t);

    if (t->size + size <= t->max_size)
        return 0;

    nsize = t->size + size + 100;

    if (nsize > 0xFFFF)
        return -1;
    
    if (!(n = avahi_realloc(t->malloc_buffer, nsize)))
        return -1;

    if (!t->malloc_buffer && t->size)
        memcpy(n, t->buffer, t->size);
    
    t->buffer = t->malloc_buffer = n;
    t->max_size = nsize;

    return 0;
}
コード例 #2
0
static int rebuild(AvahiSimplePoll *s) {
    AvahiWatch *w;
    int idx;

    assert(s);

    if (s->n_watches+1 > s->max_pollfds) {
        struct pollfd *n;

        s->max_pollfds = s->n_watches + 10;

        if (!(n = avahi_realloc(s->pollfds, sizeof(struct pollfd) * s->max_pollfds)))
            return -1;

        s->pollfds = n;
    }


    s->pollfds[0].fd = s->wakeup_pipe[0];
    s->pollfds[0].events = POLLIN;
    s->pollfds[0].revents = 0;

    idx = 1;

    for (w = s->watches; w; w = w->watches_next) {

        if(w->dead)
            continue;

        assert(w->idx < s->max_pollfds);
        s->pollfds[w->idx = idx++] = w->pollfd;
    }

    s->n_pollfds = idx;
    s->events_valid = 0;
    s->rebuild_pollfds = 0;

    return 0;
}