Commit c5c8eac4 authored by Dafydd Harries's avatar Dafydd Harries

readline()

darcs-hash:20070116051933-c9803-ac4be0259365978cf0e34bd52d13034af2af0ec9.gz
parent 33ec5679
......@@ -5,9 +5,13 @@ libagent_a_SOURCES = agent.h agent.c
noinst_LIBRARIES = libagent.a
noinst_PROGRAMS = test
noinst_PROGRAMS = test test-readline
test_LDADD = libagent.a $(GLIB_LIBS)
TESTS = test
test_readline_SOURCES = test-readline.c readline.h readline.c
test_readline_LDADD = $(GLIB_LIBS)
TESTS = test test-readline
#include <unistd.h>
#include <glib.h>
gchar *
readline (guint fileno)
{
gchar buf[1024];
guint i;
for (i = 0; i < sizeof (buf); i++)
{
guint ret;
ret = read (fileno, buf + i, 1);
if (ret == -1)
return NULL;
if (ret == 0 || buf[i] == '\n')
{
buf[i] = '\0';
return g_strdup (buf);
}
}
return NULL;
}
gchar *
readline (guint fileno);
#include <string.h>
#include <glib.h>
#include <readline.h>
/* this overrides libc read() -- is this reliable? */
int
read (int fd, void *buf, size_t count)
{
static int offset = 0;
gchar *line = "test\n";
g_assert (count == 1);
g_assert (offset < 5);
* (gchar *) buf = line[offset++];
return 1;
}
int
main (void)
{
gchar *line;
line = readline (0);
g_assert (0 == strcmp (line, "test"));
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