by l24ztj · 7y ago · 0 comments
yesssssssssss
The reason why this is (and also why the lines should not be longer than LINE_MAX or contain \0) is that when you simply call fgets() in a loop with LINE_MAX sized buffer, all of these things cause perfectly logical, but wrong/surprising behavior. This is the reason why almost any modern small unix tool contains something called myfgets(), getline() or whatever which wraps fgets() in loop with realloc() and correctly distinguishes eof from other errors.
No, they’re not correct, since they make files without the newline.
(I was actually very surprised when vscode _didn't_ do this!)
Edit: Which is to say, I don't think l24ztj is using "expect" in the sense of "anticipate" but rather, y'know, the other sense. (Using Wiktionary's definitions: "To consider obligatory or required" or "To consider reasonably due".)
This is also why tools that have a Unix heritage tend to complain if there is no terminator/separator at the end of the file (even in Windows), like most C compilers.
echo 'this is a test' > test\n
and then echo was adding the newline because you didn't specify -n. echo 'this is a test\n'
doesn't produce an additional new line because -e wasn't specified.