tgrekov-get_next_line
HIVE gnl Nov 2023
Loading...
Searching...
No Matches
get_next_line_bonus.c File Reference

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/28 02:23:33 by tgrekov #+# #+# */
/* Updated: 2023/12/12 07:48:20 by tgrekov ### ########.fr */
/* */
/* ************************************************************************** */

Definition in file get_next_line_bonus.c.

Include dependency graph for get_next_line_bonus.c:

Go to the source code of this file.

Functions

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.
 

Function Documentation

◆ 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
s1Pointer to address of string to consume from
lenNumber of characters to consume
Return values
char*Allocated consumed section of *s1

Definition at line 32 of file get_next_line_bonus.c.

Here is the caller graph for this function:

◆ 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]fdInteger file descriptor to read from
[in,out]line_bufPointer to address of allocated memory to fill. Address at *line_buf may be NULL
[in,out]first_line_lenPointer to size_t integer into which the length of the first line is written
Return values
size_tfirst_line_len

Definition at line 94 of file get_next_line_bonus.c.

References BUFFER_SIZE, and find_line_end().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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]sNull-terminated string to search
[out]lenPointer to size_t integer into which the position index of the newline + 1 is written
Return values
size_tlen

Definition at line 69 of file get_next_line_bonus.c.

Here is the caller graph for this function:

◆ 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]fdInteger 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_bonus.c.

References BUFFER_SIZE, consume_and_resize(), fill_line_buf(), and MAX_FD.

Here is the call graph for this function: