Commit c23d5285 authored by Dafydd Harries's avatar Dafydd Harries

readline(): fix EOF handling

darcs-hash:20070121024148-c9803-75bac581c823605e337cb9222c0dd68d337338b0.gz
parent 0cd549c9
......@@ -18,7 +18,12 @@ readline (guint fileno)
if (ret == -1)
return NULL;
if (ret == 0 || buf[i] == '\n')
if (ret == 0 && i == 0)
{
/* EOF on first read */
return NULL;
}
else if (ret == 0 || buf[i] == '\n')
{
buf[i] = '\0';
return g_strdup (buf);
......
......@@ -13,9 +13,16 @@ read (int fd, void *buf, size_t count)
gchar *line = "test\n";
g_assert (count == 1);
g_assert (offset < 5);
* (gchar *) buf = line[offset++];
return 1;
if (offset < 5)
{
* (gchar *) buf = line[offset++];
return 1;
}
else
{
return 0;
}
}
int
......@@ -25,6 +32,8 @@ main (void)
line = readline (0);
g_assert (0 == strcmp (line, "test"));
line = readline (0);
g_assert (line == NULL);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment