[En-Nut-Discussion] Reading from file
Maciek
arrenn at poczta.onet.pl
Thu Oct 4 00:30:09 CEST 2007
Hi!
Here we go... I want to read from a file. It is html file and it contains:
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-2">
<meta http-equiv="Refresh" content="0; URL=cgi-bin/funkcja.cgi">
</head>
</html>
In order to do this I get the file descriptor in that way:
char *filename = "FLASH:index.html";
int fd = _open(filename, _O_BINARY | _O_RDONLY);
Then, having that decriptor I want to read from this file and print its contain on a screen:
FILE *stronka = NULL;
char *data;
int size = 12;
int n;
if ((data = NutHeapAlloc(size)) != 0) {
while (dlugoscpliku > 0L) {
if (dlugoscpliku < 12L)
size = (int) dlugoscpliku;
n = _read(fd, data, size);
if((n == 0) || (n == -1))
break;
else
{
fprintf_P(stdout, PSTR("%s"), data);
// fwrite(data, 1, n, stronka);
dlugoscpliku -= (long) n;
}
}
NutHeapFree(data);
}
_close(fd);
It is a code form httpd.c file, but a little modified. But in fact it doesn't matter whether I modfy it or not, there is still an annoying problem. If I set size variable on 12, thing like that are displayed on my console:
<html>
<heaďľŢ.d>
<meta htďľŢ.tp-equiv="CoďľŢ.ntent-type" ďľŢ.content="texďľŢ.
t/html; charďľŢ.set=iso-8859ďľŢ.-2">
<meta ďľŢ.http-equiv="ďľŢ.Refresh" conďľŢ.tent="0; URLďľŢ.=c
gi-bin/funďľŢ.kcja.cgi">
ďľŢ.</head>
</hďľŢ.tml>ad>
</hďľŢ.
It looks like after 12 characters (including "\n" and "\r") there are extra added characters like these: ďľŢ.
What is it? Where are they come from?
Thanks for any help!
Maciek
More information about the En-Nut-Discussion
mailing list