getline(3) Library Functions Manual getline(3) getline, getdelim - (libc -lc) #include ssize_t getline(char **restrict lineptr, size_t *restrict n, FILE *restrict stream); ssize_t getdelim(char **restrict lineptr, size_t *restrict n, int delim, FILE *restrict stream); glibc ( feature_test_macros(7)): getline(), getdelim(): glibc 2.10: _POSIX_C_SOURCE >= 200809L glibc 2.10: _GNU_SOURCE getline() stream *lineptr. . *lineptr NULL getline() . getline(). getline() *lineptr malloc(3) *n . getline() realloc(3) *lineptr *n . *lineptr *n . getdelim() getline() delimiter. getline() . getline() getdelim() ('\0'). . -1 . -1 errno . *lineptr NULL . EINVAL (n lineptr NULL stream ). ENOMEM . attributes(7). +------------+------------------------------------+--------------------+ || | | +------------+------------------------------------+--------------------+ |getline(), | | MT-Safe | |getdelim() | | | +------------+------------------------------------+--------------------+ POSIX.1-2008. POSIX.1-2008. #define _GNU_SOURCE #include #include int main(int argc, char *argv[]) { FILE *stream; char *line = NULL; size_t size = 0; ssize_t nread; if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } stream = fopen(argv[1], "r"); if (stream == NULL) { perror("fopen"); exit(EXIT_FAILURE); } while ((nread = getline(&line, &size, stream)) != -1) { printf("Retrieved line of length %zd:\n", nread); fwrite(line, nread, 1, stdout); } free(line); fclose(stream); exit(EXIT_SUCCESS); } read(2), fgets(3), fopen(3), fread(3), scanf(3) 3 . . : . 6.18 8 2026 getline(3)