mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-10 20:00:27 +00:00
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:
parent
44cb3056bc
commit
c16171349c
1 changed files with 15 additions and 0 deletions
|
@ -34,6 +34,21 @@
|
||||||
c; \
|
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.
|
* String / file / stream decoder.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue