[xml] xmlReaderForFilename / xmlReaderForFd have different behaviours on fifo
- From: philippe theveny <philippe theveny ens-lyon fr>
- To: xml gnome org
- Subject: [xml] xmlReaderForFilename / xmlReaderForFd have different behaviours on fifo
- Date: Thu, 29 Jul 2010 13:43:00 +0200
Hi,
I am experiencing a difference in reading in a fifo with
xmlReaderForFilename and with xmlReaderForFd. The former always fails
while the latter succeeds.
This seems not to be related with the system since I can reproduce the
same behaviors on Linux (kernel 2.6.32; glibc-2.11.1; libxml2-2.7.6) and
on FreeBSD (7.2-RELEASE-p7; libxml2-2.7.3).
Here are my experiments, where the binary 'reader' is compiled from the
source example http://xmlsoft.org/examples/reader1.c. Everything is fine
with a pipe, but not with a fifo:
$ echo "<a/>" | ./reader -
0 1 a 1 0
$ mkfifo fifo
$ echo "<a/>" >fifo&
[1] 13078
$ ./reader fifo
fifo:1: parser error : Extra content at the end of the document
^
fifo : failed to parse
[1]+ Done echo "<a/>" > fifo
And with a modified version using xmlReaderForFd:
$ diff -u reader1.c reader-fd.c
--- reader1.c 2010-07-29 11:36:14.000000000 +0200
+++ reader-fd.c 2010-07-29 12:40:16.000000000 +0200
@@ -11,6 +11,7 @@
* copy: see Copyright for the status of this software.
*/
+#include <fcntl.h>
#include <stdio.h>
#include <libxml/xmlreader.h>
@@ -61,8 +62,10 @@
{
xmlTextReaderPtr reader;
int ret;
+ int fd;
- reader = xmlReaderForFile (filename, NULL, 0);
+ fd = open (filename, O_RDONLY);
+ reader = xmlReaderForFd (fd, NULL, NULL, 0);
if (reader != NULL)
{
ret = xmlTextReaderRead (reader);
@@ -81,6 +84,7 @@
{
fprintf (stderr, "Unable to open %s\n", filename);
}
+ close (fd);
}
$ echo "<a/>" >fifo&
[1] 13083
$ ./reader-fd fifo
0 1 a 1 0
[1]+ Done echo "<a/>" > fifo
IMHO, this is quite unfortunate since it prevent to feed through a fifo
applications using xmlReaderForFilename. It is intended? Am I missing
something?
Best regards,
Philippe Theveny
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]