1 I use getdelim(), but it is not the right function for me.
3 getdelim() takes four parameters:
4 1. a pointer to a pointer to a char, the buffer passed by reference;
5 2. a pointer to a size_t, the length of the buffer passed by reference;
6 3. a char, the delimiter;
7 4. a pointer to a FILE.
8 As I want getdelim() to allocate a new buffer,
9 the first two arguments are a pointer to a NULL pointer,
10 which I would like to be an out parameter instead of in-out,
11 and a pointer to 0u, which I later ignore.
12 The third argument is ␀.
14 I do not like how getdelim() returns values.
15 If there is an error while reading, it returns -1.
16 If the file ends while reading, it returns -1.
17 Otherwise, it returns the number of characters read, which can be 0:
18 read() too, can return 0 even if the file has not ended.
19 If the delimiter is '\0' and getdelim() reads it,
20 it counts as a read character.
21 It appends '\0' to the buffer even if it is the last character read,
22 so I do not know whether the number of read characters
23 is the length of the returned string or one more.
26 I assumed a returned 1 meant an empty string,
27 thinking the one character read was the delimiter,
28 but it actually was another character
29 and the delimiter was not present.
32 All that said, getdelim() is convenient.
34 I wanted files to be at most 100 lines long,
35 but maybe that is to little.
40 https://suckless.org/philosophy