[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



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.

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

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.

-- 
==============================================================================
Erwin Andreasen   Herlev, Denmark <sslug@sslug>          UNIX System Programmer
<URL:http://www.andreasen.org>              <*>         (not speaking for) DDE
==============================================================================










 
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] *