mirror of https://github.com/aria2/aria2
Use MSVC CRT equivalents without conflicting with posix names
parent
b66d981ffc
commit
d0b282385b
|
@ -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__
|
||||
|
|
|
@ -694,7 +694,7 @@ OSStatus AppleTLSSession::sockRead(void* data, size_t* len)
|
|||
uint8_t* buffer = static_cast<uint8_t*>(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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<char, 4_k> 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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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_,
|
||||
|
|
|
@ -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<char, 4_k> 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;
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue