Use MSVC CRT equivalents without conflicting with posix names

pull/2045/head
Rachel Powers 2023-03-26 00:13:23 -07:00
parent b66d981ffc
commit d0b282385b
12 changed files with 22 additions and 22 deletions

View File

@ -166,7 +166,7 @@ void AbstractDiskWriter::closeFile()
#if defined(__MINGW32__) || defined(_MSC_VER) #if defined(__MINGW32__) || defined(_MSC_VER)
CloseHandle(fd_); CloseHandle(fd_);
#else // !__MINGW32__ #else // !__MINGW32__
close(fd_); a2_close(fd_);
#endif // !__MINGW32__ #endif // !__MINGW32__
fd_ = A2_BAD_FD; fd_ = A2_BAD_FD;
} }
@ -319,7 +319,7 @@ ssize_t AbstractDiskWriter::readDataInternal(unsigned char* data, size_t len,
} }
#else // !__MINGW32__ #else // !__MINGW32__
ssize_t ret = 0; 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; return ret;
#endif // !__MINGW32__ #endif // !__MINGW32__

View File

@ -694,7 +694,7 @@ OSStatus AppleTLSSession::sockRead(void* data, size_t* len)
uint8_t* buffer = static_cast<uint8_t*>(data); uint8_t* buffer = static_cast<uint8_t*>(data);
*len = 0; *len = 0;
while (remain) { while (remain) {
ssize_t r = read(sockfd_, buffer, remain); ssize_t r = a2_read(sockfd_, buffer, remain);
if (r == 0) { if (r == 0) {
return errSSLClosedGraceful; return errSSLClosedGraceful;
} }

View File

@ -53,12 +53,12 @@ BufferedFile::BufferedFile(const char* filename, const char* mode)
a2fopen(filename, mode) a2fopen(filename, mode)
#endif // !__MINGW32__ #endif // !__MINGW32__
), ),
supportsColor_(fp_ ? isatty(fileno(fp_)) : false) supportsColor_(fp_ ? a2_isatty(a2_fileno(fp_)) : false)
{ {
} }
BufferedFile::BufferedFile(FILE* fp) 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_) { if (fp_) {
fflush(fp_); fflush(fp_);
#if !defined(__MINGW32__) && !defined(_MSC_VER) #if !defined(__MINGW32__) && !defined(_MSC_VER)
fsync(fileno(fp_)); fsync(a2_fileno(fp_));
#else // __MINGW32__ #else // __MINGW32__
_commit(fileno(fp_)); _commit(a2_fileno(fp_));
#endif // __MINGW32__ #endif // __MINGW32__
rv = fclose(fp_); rv = fclose(fp_);
fp_ = nullptr; fp_ = nullptr;

View File

@ -277,7 +277,7 @@ ConsoleStatCalc::ConsoleStatCalc(std::chrono::seconds summaryInterval,
#if defined(__MINGW32__) || defined(_MSC_VER) #if defined(__MINGW32__) || defined(_MSC_VER)
isTTY_(true), isTTY_(true),
#else // !__MINGW32__ #else // !__MINGW32__
isTTY_(isatty(STDOUT_FILENO) == 1), isTTY_(a2_isatty(STDOUT_FILENO) == 1),
#endif // !__MINGW32__ #endif // !__MINGW32__
colorOutput_(colorOutput) colorOutput_(colorOutput)
{ {

View File

@ -91,7 +91,7 @@ EpollEventPoll::EpollEventPoll()
EpollEventPoll::~EpollEventPoll() EpollEventPoll::~EpollEventPoll()
{ {
if (epfd_ != -1) { if (epfd_ != -1) {
int r = close(epfd_); int r = a2_close(epfd_);
int errNum = errno; int errNum = errno;
if (r == -1) { if (r == -1) {
A2_LOG_ERROR(fmt("Error occurred while closing epoll file descriptor" A2_LOG_ERROR(fmt("Error occurred while closing epoll file descriptor"

View File

@ -55,11 +55,11 @@
#include "fmt.h" #include "fmt.h"
#if defined(_MSC_VER) #if defined(_MSC_VER)
# if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) # if !defined(S_ISREG) && defined(_S_IFMT) && defined(_S_IFREG)
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
# endif # endif
# if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR) # if !defined(S_ISDIR) && defined(_S_IFMT) && defined(_S_IFDIR)
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) # define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
# endif # endif
#endif #endif

View File

@ -57,7 +57,7 @@ GZipFile::GZipFile(const char* filename, const char* mode)
#endif // !__MINGW32__ #endif // !__MINGW32__
; ;
if (fp) { if (fp) {
int fd = dup(fileno(fp)); int fd = a2_dup(a2_fileno(fp));
if (fd != -1) { if (fd != -1) {
fp_ = gzdopen(fd, mode); fp_ = gzdopen(fd, mode);
if (fp_) { if (fp_) {
@ -70,7 +70,7 @@ GZipFile::GZipFile(const char* filename, const char* mode)
#endif #endif
} }
else { else {
::close(fd); ::a2_close(fd);
} }
} }
fclose(fp); fclose(fp);

View File

@ -101,11 +101,11 @@ typename Parser::ResultType parseFile(Parser& parser,
if (fd == -1) { if (fd == -1) {
return Parser::ParserStateMachineType::noResult(); return Parser::ParserStateMachineType::noResult();
} }
auto fdclose = defer(fd, close); auto fdclose = defer(fd, a2_close);
std::array<char, 4_k> buf; std::array<char, 4_k> buf;
ssize_t nread; ssize_t nread;
ssize_t nproc; 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); nproc = parser.parseUpdate(buf.data(), nread);
if (nproc < 0) { if (nproc < 0) {
break; break;

View File

@ -198,7 +198,7 @@ void OptionParser::parseArg(std::ostream& out,
// option is ambiguous. // option is ambiguous.
int ambiguous = 0; int ambiguous = 0;
for (int i = 1, len = option::countOption(); i < len; ++i) { 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); const OptionHandler* h = find(pref);
if (h && !h->isHidden()) { if (h && !h->isHidden()) {
if (strcmp(pref->k, optstr) == 0) { if (strcmp(pref->k, optstr) == 0) {

View File

@ -85,7 +85,7 @@ PortEventPoll::PortEventPoll()
PortEventPoll::~PortEventPoll() PortEventPoll::~PortEventPoll()
{ {
if (port_ != -1) { if (port_ != -1) {
int r = close(port_); int r = a2_sclose(port_);
int errNum = errno; int errNum = errno;
if (r == -1) { if (r == -1) {
A2_LOG_ERROR(fmt("Error occurred while closing port %d: %s", port_, A2_LOG_ERROR(fmt("Error occurred while closing port %d: %s", port_,

View File

@ -58,12 +58,12 @@ bool parseFile(const std::string& filename, ParserStateMachine* psm)
return false; return false;
} }
} }
auto fdclose = defer(fd, close); auto fdclose = defer(fd, a2_close);
XmlParser ps(psm); XmlParser ps(psm);
std::array<char, 4_k> buf; std::array<char, 4_k> buf;
ssize_t nread; ssize_t nread;
bool retval = true; 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) { if (ps.parseUpdate(buf.data(), nread) < 0) {
retval = false; retval = false;
break; break;

View File

@ -88,7 +88,7 @@ void FileTest::testRemove()
if ((fd = creat(name.c_str(), S_IRUSR | S_IWUSR)) < 0) { if ((fd = creat(name.c_str(), S_IRUSR | S_IWUSR)) < 0) {
CPPUNIT_FAIL("cannot create test file"); CPPUNIT_FAIL("cannot create test file");
} }
close(fd); a2_close(fd);
File f(name); File f(name);
CPPUNIT_ASSERT(f.isFile()); CPPUNIT_ASSERT(f.isFile());
CPPUNIT_ASSERT(f.remove()); CPPUNIT_ASSERT(f.remove());