Definition in file get_next_line.c.
Go to the source code of this file.
|
static char * | consume_and_resize (char **s1, size_t len) |
| Allocate and return a new string of size len + 1 containing len characters from string pointed to by s1 , allocate a new string containing the remainder of the string pointed to by s1 , free the original, and set address at s1 to point to the remainder string.
|
|
static size_t | find_line_end (char *s, size_t *len) |
| Find the first newline in string s and write its index + 1 into len .
|
|
static size_t | fill_line_buf (int fd, char **line_buf, size_t *first_line_len) |
| Reading from fd , fill and / or allocate line buffer at line_buf , set first_line_len to the length of the first segment ending with a newline or EOF.
|
|
char * | get_next_line (int fd) |
| Return the next segment of text ending in a newline or EOF from file descriptor fd .
|
|
◆ consume_and_resize()
static char * consume_and_resize |
( |
char ** |
s1, |
|
|
size_t |
len |
|
) |
| |
|
static |
Allocate and return a new string of size len + 1
containing len
characters from string pointed to by s1
, allocate a new string containing the remainder of the string pointed to by s1
, free the original, and set address at s1
to point to the remainder string.
- Parameters
-
s1 | Pointer to address of string to consume from |
len | Number of characters to consume |
- Return values
-
char* | Allocated consumed section of *s1 |
Definition at line 32 of file get_next_line.c.
◆ fill_line_buf()
static size_t fill_line_buf |
( |
int |
fd, |
|
|
char ** |
line_buf, |
|
|
size_t * |
first_line_len |
|
) |
| |
|
static |
Reading from fd
, fill and / or allocate line buffer at line_buf
, set first_line_len
to the length of the first segment ending with a newline or EOF.
- Parameters
-
[in] | fd | Integer file descriptor to read from |
[in,out] | line_buf | Pointer to address of allocated memory to fill. Address at *line_buf may be NULL |
[in,out] | first_line_len | Pointer to size_t integer into which the length of the first line is written |
- Return values
-
Definition at line 94 of file get_next_line.c.
References BUFFER_SIZE, and find_line_end().
◆ find_line_end()
static size_t find_line_end |
( |
char * |
s, |
|
|
size_t * |
len |
|
) |
| |
|
static |
Find the first newline in string s
and write its index + 1 into len
.
- Parameters
-
[in] | s | Null-terminated string to search |
[out] | len | Pointer to size_t integer into which the position index of the newline + 1 is written |
- Return values
-
Definition at line 69 of file get_next_line.c.
◆ get_next_line()
char * get_next_line |
( |
int |
fd | ) |
|
Return the next segment of text ending in a newline or EOF from file descriptor fd
.
- Parameters
-
[in] | fd | Integer file descriptor to read from |
- Return values
-
char* | Freeable, null-terminated string on success, or NULL if error or nothing to read |
Definition at line 131 of file get_next_line.c.
References BUFFER_SIZE, consume_and_resize(), fill_line_buf(), and MAX_FD.