title: getline() vs. fgets(): Control memory allocation
body: <p>To read lines from a file there are the <code>getline()</code> and <code>fgets()</code> POSIX functions (ignoring the dreaded <code>gets()</code>). It is common sense that <code>getline()</code> is preferred over <code>fgets()</code> because it allocates the line buffer as needed.</p>
  
  <p>My question is: Isn’t that dangerous? What if by accident or malicious intent someone creates a 100GB file with no <code>'\n'</code> byte in it – won’t that make my <code>getline()</code> call allocate an insane amount of memory?</p>