C getline() implementation
Your getline function looks more like a variant of fgets than getline.
If size == 0, size - 1 == SIZE_MAX, a very large number.
Your getline reads up to size bytes from the stream even though it only places only up to size - 1 into the buffer. It simply drops the last byte silently. You should switch the order of the loop condition:

while (count &lt; size &amp;&amp; (c = (char)getc(stream)) != '\n') { ... }

Your getline also writes to memory outside the range defined by its parameters if size is 0, when it writes the terminating null byte.
If getc(stream) == EOF, which is an error condition, your getline function will keep trying to read from the stream, always "reading" EOF, placing (char) EOF (usually '\xff') into the buffer until the end of the buffer is reached.

You can try this by pointing stdin at an empty file.
Use a for loop instead of a while loop, if you're using an iteration counter. It'll be much clearer, what is incremented where and how.


This is how I would rewrite your function considering the above points:

ssize_t fgets(FILE *stream, char *buf, size_t size)
{
  if (size == 0)
    return 0;

  size_t count;
  int c = 0;
  for (count = 0; c != '\n' &amp;&amp; count &lt; size - 1; count++) 
  {
    c = getc(stream);

    if (c == EOF) {
      if (count == 0)
        return -1;
      break;
    }

    buf[count] = (char) c;
  }

  buf[count] = '\0';
  return (ssize_t) count;
}