clemedon / get_next_line

[documented code / -pedantic -std=c89] - Get the next line of text available on a file descriptor. Can be used within a loop to read a file line by line.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GNL - GET_NEXT_LINE 42

Summary

Get the next line of text available on a file descriptor. Calling get_next_line in a loop will allow us to read the text available on the file descriptor one line at a time until the end of it.

"May it be a file, stdin, or even later a network connection, you will always need a way to read content line by line. It is time to start working on this function, which will be essential for your future projects." - Subject

External functions: read, malloc, free

Code written in accordance with 42 C coding style, ANSI C89 compliant and entirely documented with docstrings.

Usage

Add get_next_line.h to your project header to access the function.

To test the function run make from within the test directory and launch as follows: ./get_next_line <path_to_file>

For example: ./get_next_line main.c

Tester

First of all cd test && make.

  • Gnltester check if the number of characters returned by get_next_line call on multiple pre defined input files with a set of different BUFFER_SIZE is correct. Uses valgrind.

Usage: make test or bash gnltester.sh

  • Gnldiff is a simple tester that check get_next_line output accuracy and create a diff.log file if something went wrong.

Usage: bash gnldiff.sh <file_path>

Example:

cat Makefile > file; bash gnldiff.sh file

cat ../*.[ch] > file; bash gnldiff.sh file

Make sure to use a BUFFER_SIZE of 1 if your <file> parameter contains multi byte characters like those from binary file or /dev/urandom like:

cat /bin/cat > file; bash gnldiff.sh file

head -4242 /dev/urandom > file; bash gnldiff.sh file

Tools

Check with different arguments (ft_mallocator/config.sh:ARGS) and buffer size (get_next_line.h:BUFFER_SIZE).

  • valgrind: valgrind -q --leak-check=yes --show-leak-kinds=all

  • sanitizer: -fsanitize=address

Add -g flag when compiling with -fsanitize=address to print errors line numbers instead of addresses in hexadecimal.

About

[documented code / -pedantic -std=c89] - Get the next line of text available on a file descriptor. Can be used within a loop to read a file line by line.


Languages

Language:C 68.0%Language:Shell 18.6%Language:Makefile 13.4%