Read from File Descriptor.
Function returning a line read from a file descriptor developed with the C programming language.
This is a project developed in the cursus of 42Madrid.
Function name | get_next_line |
Prototype | char *get_next_line(int fd); |
Files to be delivered | get_next_line.c, get_next_line_utils.c, get_next_line.h |
Parameters | fd: File descriptor to read from |
Value returned | If all goes well: the read line In case of failure or if reading ends: NULL |
Allowed functions | read, malloc, free |
Description | Writes a function that returns the line read from a file descriptor. |
Calling the get_next_line function repeatedly (for example, using a loop) will allow you to read the contents of the file to which the file descriptor points, line by line, all the way to the end.
Bonus: Your get_next_line has to be able to handle multiple fd at once.
To develop the project you must know what a File descriptor is, which is more than
A number that uniquely identifies an open file in a computer's operating system. It describes a data resource, and how that resource may be accessed.
On a Unix-like operating system, the first three file descriptors, by default:
Name | File descriptor | Description | Abbreviation |
Standard input | 0 | The default data stream for input, for example in a command pipeline. In the terminal, this defaults to keyboard input from the user. | stdin |
Standard output | 1 | The default data stream for output, for example when a command prints text. In the terminal, this defaults to the user’s screen. | stdout |
Standard error | 2 | The default data stream for output that relates to an error occurring. In the terminal, this defaults to the user’s screen. | stderr |
In addition, it would not hurt to study the open() read() c functions.
The buffer parameter is a pointer to the memory area where the transfer is to take place. That is, where the data will be read from in the read function.
Knowing this I have developed the function, see the source code here
Project completed
Rating: