fix bug 24516, cookies file was being read one byte at a time, r=neeti

This commit is contained in:
morse%netscape.com 2000-01-22 20:24:48 +00:00
Родитель 664cb8a7b7
Коммит e2f4de2d3c
1 изменённых файлов: 24 добавлений и 11 удалений

Просмотреть файл

@ -342,15 +342,31 @@ cookie_Put(nsOutputFileStream strm, const nsString& aLine)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
/* output each character */ /* output entire line */
char* p = cp; strm.write(cp, aLine.Length());
while (*p) {
strm.put(*(p++));
}
nsCRT::free(cp); nsCRT::free(cp);
return NS_OK; return NS_OK;
} }
nsresult cookie_Get(nsInputFileStream strm, char& c) {
#define BUFSIZE 128
static char buffer[BUFSIZE];
static PRInt32 next = BUFSIZE, count = BUFSIZE;
if (next == count) {
if (count < BUFSIZE) {
return NS_ERROR_FAILURE;
}
count = strm.read(buffer, BUFSIZE);
next = 0;
if (count == 0) {
return NS_ERROR_FAILURE;
}
}
c = buffer[next++];
return NS_OK;
}
/* /*
* get a line from a file * get a line from a file
* return -1 if end of file reached * return -1 if end of file reached
@ -363,18 +379,15 @@ cookie_GetLine(nsInputFileStream strm, nsAutoString& aLine) {
aLine.Truncate(); aLine.Truncate();
char c; char c;
for (;;) { for (;;) {
c = strm.get(); if NS_FAILED(cookie_Get(strm, c)) {
return -1;
}
if (c == '\n') { if (c == '\n') {
break; break;
} }
/* note that eof is not set until we read past the end of the file */
if (strm.eof()) {
return -1;
}
if (c != '\r') { if (c != '\r') {
aLine.Append(c); aLine.Append(c);
// aLine += c;
} }
} }
return 0; return 0;