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) ...@@ -18,7 +18,12 @@ readline (guint fileno)
if (ret == -1) if (ret == -1)
return NULL; 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'; buf[i] = '\0';
return g_strdup (buf); return g_strdup (buf);
......
...@@ -13,9 +13,16 @@ read (int fd, void *buf, size_t count) ...@@ -13,9 +13,16 @@ read (int fd, void *buf, size_t count)
gchar *line = "test\n"; gchar *line = "test\n";
g_assert (count == 1); g_assert (count == 1);
g_assert (offset < 5);
if (offset < 5)
{
* (gchar *) buf = line[offset++]; * (gchar *) buf = line[offset++];
return 1; return 1;
}
else
{
return 0;
}
} }
int int
...@@ -25,6 +32,8 @@ main (void) ...@@ -25,6 +32,8 @@ main (void)
line = readline (0); line = readline (0);
g_assert (0 == strcmp (line, "test")); g_assert (0 == strcmp (line, "test"));
line = readline (0);
g_assert (line == NULL);
return 0; 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