12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include <features.h>
- #ifdef __USE_GNU
- #include "_stdio.h"
- #define GETDELIM_GROWBY 64
- ssize_t getdelim(char **__restrict lineptr, size_t *__restrict n,
- int delimiter, register FILE *__restrict stream)
- {
- register char *buf;
- ssize_t pos = -1;
- int c;
- __STDIO_AUTO_THREADLOCK_VAR;
- if (!lineptr || !n || !stream) {
- __set_errno(EINVAL);
- } else {
- __STDIO_AUTO_THREADLOCK(stream);
- if (!(buf = *lineptr)) {
- *n = 0;
- }
-
- pos = 1;
- do {
- if (pos >= *n) {
- if (!(buf = realloc(buf, *n + GETDELIM_GROWBY))) {
- pos = -1;
- break;
- }
- *n += GETDELIM_GROWBY;
- *lineptr = buf;
- }
- if ((c = __GETC_UNLOCKED(stream)) != EOF) {
- buf[++pos - 2] = c;
- if (c != delimiter) {
- continue;
- }
- }
-
- if ((pos -= 2) >= 0) {
- buf[++pos] = 0;
- }
- break;
- } while (1);
- __STDIO_AUTO_THREADUNLOCK(stream);
- }
- return pos;
- }
- libc_hidden_def(getdelim)
- #endif
|