summaryrefslogtreecommitdiff
path: root/src/Netrc.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-08-06 21:57:38 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-08-06 21:57:38 +0900
commitf38c2d20129e893aaf37f5126882754b9664b346 (patch)
tree8f4d7f9aff44e8f05e54c65ec228df4180980c6e /src/Netrc.cc
parentc9f8cf75bf72eb44b77736b0678b9a5094d7f5f5 (diff)
Rewritten Netrc using BufferedFile.
Diffstat (limited to 'src/Netrc.cc')
-rw-r--r--src/Netrc.cc15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/Netrc.cc b/src/Netrc.cc
index edb83d5c..5f559617 100644
--- a/src/Netrc.cc
+++ b/src/Netrc.cc
@@ -42,6 +42,7 @@
#include "fmt.h"
#include "A2STR.h"
#include "util.h"
+#include "BufferedFile.h"
namespace aria2 {
@@ -119,11 +120,11 @@ void Netrc::addAuthenticator(const SharedHandle<Authenticator>& authenticator)
}
namespace {
-void skipMacdef(FILE* fp)
+void skipMacdef(BufferedFile& fp)
{
char buf[4096];
while(1) {
- if(!fgets(buf, sizeof(buf), fp)) {
+ if(!fp.gets(buf, sizeof(buf))) {
break;
}
if(buf[0] == '\n' || buf[0] == '\r') {
@@ -136,12 +137,10 @@ void skipMacdef(FILE* fp)
void Netrc::parse(const std::string& path)
{
authenticators_.clear();
- FILE* fp = a2fopen(utf8ToWChar(path).c_str(), "rb");
+ BufferedFile fp(path, BufferedFile::READ);
if(!fp) {
throw DL_ABORT_EX(fmt("Cannot open file: %s", utf8ToNative(path).c_str()));
}
- auto_delete_r<FILE*, int> deleter(fp, fclose);
-
enum STATE {
GET_TOKEN,
SET_MACHINE,
@@ -154,13 +153,9 @@ void Netrc::parse(const std::string& path)
STATE state = GET_TOKEN;
char buf[4096];
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, "#")) {
continue;