github.com/afumu/libc@v0.0.6/musl/src/stdio/fgetln.c (about)

     1  #define _GNU_SOURCE
     2  #include "stdio_impl.h"
     3  #include <string.h>
     4  
     5  char *fgetln(FILE *f, size_t *plen)
     6  {
     7  	char *ret = 0, *z;
     8  	ssize_t l;
     9  	FLOCK(f);
    10  	ungetc(getc_unlocked(f), f);
    11  	if (f->rend && (z=memchr(f->rpos, '\n', f->rend - f->rpos))) {
    12  		ret = (char *)f->rpos;
    13  		*plen = ++z - ret;
    14  		f->rpos = (void *)z;
    15  	} else if ((l = getline(&f->getln_buf, (size_t[]){0}, f)) > 0) {
    16  		*plen = l;
    17  		ret = f->getln_buf;
    18  	}
    19  	FUNLOCK(f);
    20  	return ret;
    21  }