[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