title: How to read a line from stdin, blocking until the newline is found?
body: <p>I'm trying to read one line at a time, of arbitrary length, from stdin at the command line. I'm not sure if I'll be able to include GNU readline and would prefer to use a library function.</p>
  
  <p>The documentation I've read suggests that <code>getline</code> ought to work, but in my experiments it doesn't block. My sample program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main()
  {
      char *line = NULL;
      if (getline(&amp;line, NULL, stdin) == -1) {
          printf("No line\n");
      } else {
          printf("%s\n", line);
      }
      return 0;
  }
  </code></pre>
  
  <p>produces <code>No line</code>, which makes it unsuitable for accepting user input.</p>
  
  <p>How do I do this? I know it should be trivial, but I haven't been able to figure it out.</p>