summaryrefslogtreecommitdiff
path: root/push.c
blob: d31de5eb6416b5f0a80a2667f00f98ede76ebc64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "prv.h"
#include <stdlib.h>

int push(const struct pos *pos, struct prv *p)
{
    size_t n = p->n + 1;
    struct pos *npos = realloc(p->pos, n * sizeof *npos);

    if (!npos)
    {
        perror("realloc(3)");
        return -1;
    }
    else if (p->n)
    {
        struct pos *prev = &npos[p->n - 1];

        prev->seq = prev->stseq;
        prev->step = prev->seq->steps;
        p->i++;
    }

    npos[p->n++] = *pos;
    p->pos = npos;
    return 0;
}