diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index 0bd84248..55412927 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -166,7 +166,7 @@ void AbstractDiskWriter::closeFile() #if defined(__MINGW32__) || defined(_MSC_VER) CloseHandle(fd_); #else // !__MINGW32__ - close(fd_); + a2_close(fd_); #endif // !__MINGW32__ fd_ = A2_BAD_FD; } @@ -319,7 +319,7 @@ ssize_t AbstractDiskWriter::readDataInternal(unsigned char* data, size_t len, } #else // !__MINGW32__ ssize_t ret = 0; - while ((ret = read(fd_, data, len)) == -1 && errno == EINTR) + while ((ret = a2_read(fd_, data, len)) == -1 && errno == EINTR) ; return ret; #endif // !__MINGW32__ diff --git a/src/AppleTLSSession.cc b/src/AppleTLSSession.cc index f4174a58..12bcb0e6 100644 --- a/src/AppleTLSSession.cc +++ b/src/AppleTLSSession.cc @@ -694,7 +694,7 @@ OSStatus AppleTLSSession::sockRead(void* data, size_t* len) uint8_t* buffer = static_cast(data); *len = 0; while (remain) { - ssize_t r = read(sockfd_, buffer, remain); + ssize_t r = a2_read(sockfd_, buffer, remain); if (r == 0) { return errSSLClosedGraceful; } diff --git a/src/BufferedFile.cc b/src/BufferedFile.cc index d1735bac..6ad21a59 100644 --- a/src/BufferedFile.cc +++ b/src/BufferedFile.cc @@ -53,12 +53,12 @@ BufferedFile::BufferedFile(const char* filename, const char* mode) a2fopen(filename, mode) #endif // !__MINGW32__ ), - supportsColor_(fp_ ? isatty(fileno(fp_)) : false) + supportsColor_(fp_ ? a2_isatty(a2_fileno(fp_)) : false) { } BufferedFile::BufferedFile(FILE* fp) - : fp_(fp), supportsColor_(fp_ ? isatty(fileno(fp_)) : false) + : fp_(fp), supportsColor_(fp_ ? a2_isatty(a2_fileno(fp_)) : false) { } @@ -82,9 +82,9 @@ int BufferedFile::onClose() if (fp_) { fflush(fp_); #if !defined(__MINGW32__) && !defined(_MSC_VER) - fsync(fileno(fp_)); + fsync(a2_fileno(fp_)); #else // __MINGW32__ - _commit(fileno(fp_)); + _commit(a2_fileno(fp_)); #endif // __MINGW32__ rv = fclose(fp_); fp_ = nullptr; diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc index 09a85ad5..b7fe8224 100644 --- a/src/ConsoleStatCalc.cc +++ b/src/ConsoleStatCalc.cc @@ -277,7 +277,7 @@ ConsoleStatCalc::ConsoleStatCalc(std::chrono::seconds summaryInterval, #if defined(__MINGW32__) || defined(_MSC_VER) isTTY_(true), #else // !__MINGW32__ - isTTY_(isatty(STDOUT_FILENO) == 1), + isTTY_(a2_isatty(STDOUT_FILENO) == 1), #endif // !__MINGW32__ colorOutput_(colorOutput) { diff --git a/src/EpollEventPoll.cc b/src/EpollEventPoll.cc index 340400dd..c507bb42 100644 --- a/src/EpollEventPoll.cc +++ b/src/EpollEventPoll.cc @@ -91,7 +91,7 @@ EpollEventPoll::EpollEventPoll() EpollEventPoll::~EpollEventPoll() { if (epfd_ != -1) { - int r = close(epfd_); + int r = a2_close(epfd_); int errNum = errno; if (r == -1) { A2_LOG_ERROR(fmt("Error occurred while closing epoll file descriptor" diff --git a/src/File.cc b/src/File.cc index a9670634..a34e664c 100644 --- a/src/File.cc +++ b/src/File.cc @@ -55,11 +55,11 @@ #include "fmt.h" #if defined(_MSC_VER) -# if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +# if !defined(S_ISREG) && defined(_S_IFMT) && defined(_S_IFREG) +# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) # endif -# if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR) -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +# if !defined(S_ISDIR) && defined(_S_IFMT) && defined(_S_IFDIR) +# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) # endif #endif diff --git a/src/GZipFile.cc b/src/GZipFile.cc index b85665d8..b2e23c34 100644 --- a/src/GZipFile.cc +++ b/src/GZipFile.cc @@ -57,7 +57,7 @@ GZipFile::GZipFile(const char* filename, const char* mode) #endif // !__MINGW32__ ; if (fp) { - int fd = dup(fileno(fp)); + int fd = a2_dup(a2_fileno(fp)); if (fd != -1) { fp_ = gzdopen(fd, mode); if (fp_) { @@ -70,7 +70,7 @@ GZipFile::GZipFile(const char* filename, const char* mode) #endif } else { - ::close(fd); + ::a2_close(fd); } } fclose(fp); diff --git a/src/GenericParser.h b/src/GenericParser.h index 7373b066..ace91e28 100644 --- a/src/GenericParser.h +++ b/src/GenericParser.h @@ -101,11 +101,11 @@ typename Parser::ResultType parseFile(Parser& parser, if (fd == -1) { return Parser::ParserStateMachineType::noResult(); } - auto fdclose = defer(fd, close); + auto fdclose = defer(fd, a2_close); std::array buf; ssize_t nread; ssize_t nproc; - while ((nread = read(fd, buf.data(), buf.size())) > 0) { + while ((nread = a2_read(fd, buf.data(), buf.size())) > 0) { nproc = parser.parseUpdate(buf.data(), nread); if (nproc < 0) { break; diff --git a/src/OptionParser.cc b/src/OptionParser.cc index b4a66e75..63b5c4b4 100644 --- a/src/OptionParser.cc +++ b/src/OptionParser.cc @@ -198,7 +198,7 @@ void OptionParser::parseArg(std::ostream& out, // option is ambiguous. int ambiguous = 0; for (int i = 1, len = option::countOption(); i < len; ++i) { - PrefPtr pref = option::i2p(i); + PrefPtr pref = aria2::option::i2p(i); const OptionHandler* h = find(pref); if (h && !h->isHidden()) { if (strcmp(pref->k, optstr) == 0) { diff --git a/src/PortEventPoll.cc b/src/PortEventPoll.cc index ecd7fbfa..39f5a1fe 100644 --- a/src/PortEventPoll.cc +++ b/src/PortEventPoll.cc @@ -85,7 +85,7 @@ PortEventPoll::PortEventPoll() PortEventPoll::~PortEventPoll() { if (port_ != -1) { - int r = close(port_); + int r = a2_sclose(port_); int errNum = errno; if (r == -1) { A2_LOG_ERROR(fmt("Error occurred while closing port %d: %s", port_, diff --git a/src/XmlParser.cc b/src/XmlParser.cc index 15b273d7..4eb95c46 100644 --- a/src/XmlParser.cc +++ b/src/XmlParser.cc @@ -58,12 +58,12 @@ bool parseFile(const std::string& filename, ParserStateMachine* psm) return false; } } - auto fdclose = defer(fd, close); + auto fdclose = defer(fd, a2_close); XmlParser ps(psm); std::array buf; ssize_t nread; bool retval = true; - while ((nread = read(fd, buf.data(), buf.size())) > 0) { + while ((nread = a2_read(fd, buf.data(), buf.size())) > 0) { if (ps.parseUpdate(buf.data(), nread) < 0) { retval = false; break; diff --git a/test/FileTest.cc b/test/FileTest.cc index e4c2f01a..b3773d36 100644 --- a/test/FileTest.cc +++ b/test/FileTest.cc @@ -88,7 +88,7 @@ void FileTest::testRemove() if ((fd = creat(name.c_str(), S_IRUSR | S_IWUSR)) < 0) { CPPUNIT_FAIL("cannot create test file"); } - close(fd); + a2_close(fd); File f(name); CPPUNIT_ASSERT(f.isFile()); CPPUNIT_ASSERT(f.remove());