[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] HTTP-Server



"Erwin S. Andreasen" wrote:
> 
> On Thu, 9 Dec 1999, Joachim Holst wrote:
> 
> >       FILE *outfile = fopen("index.html","wt");
> 
> Du åbner filen som tekst -- det betyder der sker noget snavset
> autokonvertering af newlines og sådan noget. Måske giver det problemer.
> 
> >               UINT nRead = pFile->Read(szBuff, 1023);
> 
> Put det 1023 ind i en eller anden konstant eller brug sizeof(szBuff)-1.

Kanske ingen dum ide nej. Sastte konstanten manuellt eftersom den
beskriver hur pass stor bufferten är och enligt dokumentationen, så
skall den läsas så många bytes som ajg skriver där. Programmet ligger
även på test stadie så jag orkade inte riktigt bry mig just då. Skall
fixa det nu däremot :-)

> 
> Er denne Read defineret til at sætte en NUL karakter til sidst i det den
> henter?

Det har jag inte lyckats tyda ur dokumentationen. Jag använde memset för
att manuellt sätta '\0' i hela bufferten om ifall Read inte satte
slutnolla..

> 
> Hvis ikke var det nok en god ide at lave noget i stil med:
> 
> if (nRead > 0) {
>         szBuff[nRead] = '\0';
> } else {
>         // Fejl?
> }
> 
> eller endnu bedre, bruge fwrite.
> 
> Her er hvordan jeg ville skrive det (uden at kende til biblioteket)
> 
> UINT nRead;
> 
> nRead = pFile->Read(szBuff, sizeof(szBuff) - 1);
> 
> // jeg gaar ud fra at den returnerer <= ved fejl/EOF
> while (nRead > 0) {
>         // fwrite er ligeglad med NUL-termineringen
>         fwrite(szBuff, 1, nRead, outfile);
>         nRead = pFile->Read(szBuff, sizeof(szBuff) - 1);
> }
> 
> fclose(outfile);
> 
> For at være rigtig stabil bør du checke fejl fra fwrite og fclose.

Tack för tipset. Skall göra så istället.
Återkommer med resultatet..

/Jocke!


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *