linelen and nread should be ssize_t.