1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #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;
- }
- weak_alias(__getdelim,getdelim);
|