30 static int iofreadiconv(
void *chan,
char *buf,
int bufsize)
32 #define CHARBUFSIZE 30
33 static char charbuf[CHARBUFSIZE];
34 static iconv_t cd =
NULL;
35 char *inbuf, *outbuf, *readbuf;
36 size_t inbytesleft, outbytesleft, readbytesleft, resbytes, result;
40 cd = iconv_open(nl_langinfo(CODESET),
"UTF-8");
42 fd = fileno((FILE *) chan);
43 readbuf = inbuf = charbuf;
44 readbytesleft = CHARBUFSIZE;
47 outbytesleft = bufsize - 1;
49 if ((result =
read(fd, readbuf++, 1)) != 1)
53 result = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
55 readbuf = inbuf = charbuf;
56 readbytesleft = CHARBUFSIZE;
58 }
else if (errno != EINVAL)
62 resbytes = bufsize - 1 - outbytesleft;
69 static int iofread(
void *chan,
char *buf,
int bufsize)
71 if (fgets(buf, bufsize, (FILE*)chan))
80 static int ioputstr(
void *chan,
const char *
str)
82 return fputs(str, (FILE *) chan);
85 static int ioflush(
void *chan)
87 return fflush((FILE *) chan);
100 memiofread(
void *chan,
char *buf,
int bufsize)
108 if (bufsize == 0)
return 0;
124 }
while ((c !=
'\n') && (l < bufsize) && (c = *ptr++));
129 static Agiodisc_t memIoDisc = {memiofread, 0, 0};
140 rdr.
len = strlen(cp);
145 disc.
io = &memIoDisc;
CGRAPH_API Agmemdisc_t AgMemDisc
CGRAPH_API Agiodisc_t AgIoDisc
CGRAPH_API void agsetfile(char *)
CGRAPH_API Agraph_t * agread(void *chan, Agdisc_t *disc)
CGRAPH_API Agiddisc_t AgIdDisc
CGRAPH_API Agraph_t * agmemread(const char *cp)
int(* putstr)(void *chan, const char *str)