🔧 C, Makefile
🌍 MacOs
This is a reinterpretation of the fgets() function. Its purpose is to code a function that opens a file, reads a predetermined number (buffer) of characters, and returns the text in the standard output, read from a file descriptor, separated by line breaks. It works with concepts such as the use of data buffers, static variables, file descriptors, as well as double pointer with different use of arrays.
🚧 project:
42Libft $ make
🚿 Clean Obj files:
42Libft $ make clean
🚿 🚿 Clean All (obj files + binary):
42Libft $ make fclean
🚿 🚿 🚧 Clean All + build:
42Libft $ make re
See Makefile
Here, a simple drawning about the main idea: copy buffer until find a '\n', keeping the residual for the next call.
Below, a get_next_line's flowchart - Before final version: (Note: This diagram is not complete. After reading the file, there is no residue, that is, when EOF is reached, the buffer is still checked by repeating the buffer breaking process if there is '/ n'. This diagram served more for an initial understanding. The final version, below in this document, is more detailed and assertive.)
The get_next_line's variables. Note that the bonus part (The part that treats with various files at same time), uses an string''s array, like shows the figure below, called by residual[fd]. Where each position referes to particular FD. On the simple get_next_line, the mandatory part, this is a simple string var.(residual).
Var list:
- buff: Read buffer (used on read function, to keep the read part)
- residual: residue buffer (has the same size of buff, and keep the residue of buff, after the buff is append on the line)
- oneline: Flag that indicates that function reach a line
(Note: As the buffer variable is only used within gnl_core, I chose to use a simple pointer, that is, I don't need its reference outside the scope of this function. So, the correct thing in this diagram is just buf and * buf. Like the diagram above, this was only used to understand the data structure.)
To according with moulinette, i had to split my function, because it had more than 70 lines. So, i've created a "gnl_core", that resumes the main logic of the code. Some functions, had your names changed to seem more useful to understanding.