-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject_notes.txt
39 lines (36 loc) · 2.04 KB
/
project_notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Use standard library functions only for prototypes and for 42 replace them with your own.
// Todo: Add edge case handling.
// What if the file doesn't exist?
// What if the file is empty?
// What if the file is only one line?
// What if the file is only one line and it doesn't end with a new line?
// What if the file is only one line and it ends with a new line?
// What if the file is multiple lines?
// What if the file is multiple lines and it doesn't end with a new line?
// What if the file is multiple lines and it ends with a new line?
// What if the file is multiple lines and it ends with multiple new lines?
// What if the file is multiple lines and it ends with multiple new lines and the last line is empty?
// What if the file is multiple lines and it ends with multiple new lines and the last line is not empty?
// What if the file is multiple lines and it ends with multiple new lines and the last line is not empty and it doesn't end with a new line?
// Todo: Add error handling.
// Check mallocs.
// Check read.
// Check close.
// Check fd.
// Check buffer size.
// Null all pointers after free.
// Todo: Add support for multiple file descriptors.
// Steps:
// 0. Caller calls get_next_line with a file descriptor and expects a line from the file or NULL.
// 1. function entry - is buffer NULL?
// 1.1 if it is, allocate memory, read to buf, set trailing \0 to the buffer
// do all the checks including EOF and continue to 2.1 (if EOF return NULL)
// 1.2 if it is not, continue to 2.1
// 2.1 check if the buffer contains a new line.
// 2.1.1 if it does, it appends the chars including the new line and (manually add \0)
// // into a new_string var, shifts the buffer to the
// left and returns the new string var to the caller (continues to 0)
// 2.1.2 if it doesn't, it moves (strjoin)? the buffer into
// a new_line var, reads to the buffer, sets trailing \0 to the buffer
// and it contines until if either finds a new line or EOF (continues to 0)
// 3. caller receives a NULL pointer and knows that there is no more data to read.