Quellcode durchsuchen

Rewritten NsCookieParser using BufferedFile

Tatsuhiro Tsujikawa vor 14 Jahren
Ursprung
Commit
c553d92f45
1 geänderte Dateien mit 3 neuen und 7 gelöschten Zeilen
  1. 3 7
      src/NsCookieParser.cc

+ 3 - 7
src/NsCookieParser.cc

@@ -44,6 +44,7 @@
 #include "fmt.h"
 #include "Cookie.h"
 #include "cookie_helper.h"
+#include "BufferedFile.h"
 
 namespace aria2 {
 
@@ -95,22 +96,17 @@ bool parseNsCookie
 std::vector<Cookie> NsCookieParser::parse
 (const std::string& filename, time_t creationTime)
 {
-  FILE* fp = a2fopen(utf8ToWChar(filename).c_str(), "rb");
+  BufferedFile fp(filename, BufferedFile::READ);
   if(!fp) {
     throw DL_ABORT_EX(fmt("Failed to open file %s",
                           utf8ToNative(filename).c_str()));
   }
-  auto_delete_r<FILE*, int> deleter(fp, fclose);
   std::vector<Cookie> cookies;
   char buf[8192];
   while(1) {
-    if(!fgets(buf, sizeof(buf), fp)) {
+    if(!fp.getsn(buf, sizeof(buf))) {
       break;
     }
-    size_t len = strlen(buf);
-    if(buf[len-1] == '\n') {
-      buf[len-1] = '\0';
-    }
     std::string line(buf);
     if(util::startsWith(line, A2STR::SHARP_C)) {
       continue;