vcscanf: define BUFFER macro

This is similar to the READ macro.
READs a character and places it in the buffer.
Automatically maintains the NUL terminator.
If the end is reached, reallocate the buffer.
This commit is contained in:
Matheus Afonso Martins Moreira 2023-11-02 06:07:44 -03:00
parent 44cb3056bc
commit c16171349c

View file

@ -34,6 +34,21 @@
c; \
})
#define BUFFER_GROW 48
#define BUFFER \
({ \
int c = READ; \
if (bufcur >= bufsize - 1) { \
bufsize = bufsize + BUFFER_GROW; \
buf = realloc(buf, bufsize); \
} \
if (c != -1) { \
buf[bufcur++] = c; \
buf[bufcur] = '\0'; \
} \
c; \
})
/**
* String / file / stream decoder.
*