From b39ede01a7f1f90e6a8c2c38afe55d3c0d32eb1d Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 24 Jan 2010 13:49:07 +0000 Subject: [PATCH] 2010-01-24 Tatsuhiro Tsujikawa Fixed compile error with i586-mingw32msvc-g++. Always Cut console readout by 80 characters in mingw32 build. Catch exception in DHTMessageReceiver::receiveMessage(). * src/AbstractDiskWriter.cc * src/ConsoleStatCalc.cc * src/DHTMessageReceiver.cc * src/File.cc * src/RequestGroupMan.cc * src/a2io.h * test/FileTest.cc --- ChangeLog | 13 +++++++++++++ src/AbstractDiskWriter.cc | 2 +- src/ConsoleStatCalc.cc | 21 +++++++++++---------- src/DHTMessageReceiver.cc | 12 ++++++------ src/File.cc | 2 +- src/RequestGroupMan.cc | 9 +++++++-- src/a2io.h | 23 ++++++++++++++--------- test/FileTest.cc | 2 +- 8 files changed, 54 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3ca020b2..12f1b177 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-01-24 Tatsuhiro Tsujikawa + + Fixed compile error with i586-mingw32msvc-g++. Always Cut console + readout by 80 characters in mingw32 build. Catch exception in + DHTMessageReceiver::receiveMessage(). + * src/AbstractDiskWriter.cc + * src/ConsoleStatCalc.cc + * src/DHTMessageReceiver.cc + * src/File.cc + * src/RequestGroupMan.cc + * src/a2io.h + * test/FileTest.cc + 2010-01-24 Tatsuhiro Tsujikawa Fixed compile error with intel compiler diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index 84a5f3bd..cfadd8ef 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -139,7 +139,7 @@ ssize_t AbstractDiskWriter::readDataInternal(unsigned char* data, size_t len) void AbstractDiskWriter::seek(off_t offset) { - if(lseek(fd, offset, SEEK_SET) == (off_t)-1) { + if(a2lseek(fd, offset, SEEK_SET) == (off_t)-1) { throw DL_ABORT_EX (StringFormat(EX_FILE_SEEK, _filename.c_str(), strerror(errno)).str()); } diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc index 99d9d9ab..4ea7e976 100644 --- a/src/ConsoleStatCalc.cc +++ b/src/ConsoleStatCalc.cc @@ -42,6 +42,7 @@ #endif // HAVE_SYS_IOCTL_H #include +#include #include #include #include @@ -218,25 +219,25 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e) } _cp.reset(); const SizeFormatter& sizeFormatter = *_sizeFormatter.get(); + +#ifdef __MINGW32__ + bool isTTY = true; + // Windows terminal cannot handle at the end of line properly. + unsigned short int cols = 79; +#else // !__MINGW32__ bool isTTY = isatty(STDOUT_FILENO) == 1; unsigned short int cols = 80; -#ifdef __MINGW32__ - // Windows terminal cannot handle at the end of line properly. - --cols; -#endif // __MINGW32__ +#endif // !__MINGW32__ + if(isTTY) { +#ifndef __MINGW32__ #ifdef HAVE_TERMIOS_H struct winsize size; if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) == 0) { cols = size.ws_col; -#ifdef __MINGW32__ - if(cols > 0) { - // Windows terminal cannot handle at the end of line properly. - --cols; - } -#endif // __MINGW32__ } #endif // HAVE_TERMIOS_H +#endif // !__MINGW32__ std::cout << '\r' << std::setfill(' ') << std::setw(cols) << ' ' << '\r'; } std::ostringstream o; diff --git a/src/DHTMessageReceiver.cc b/src/DHTMessageReceiver.cc index d90b9126..391e6f58 100644 --- a/src/DHTMessageReceiver.cc +++ b/src/DHTMessageReceiver.cc @@ -66,13 +66,13 @@ SharedHandle DHTMessageReceiver::receiveMessage() std::string remoteAddr; uint16_t remotePort; unsigned char data[64*1024]; - ssize_t length = _connection->receiveMessage(data, sizeof(data), - remoteAddr, - remotePort); - if(length <= 0) { - return SharedHandle(); - } try { + ssize_t length = _connection->receiveMessage(data, sizeof(data), + remoteAddr, + remotePort); + if(length <= 0) { + return SharedHandle(); + } bool isReply = false; const BDE dict = bencode::decode(data, length); if(dict.isDict()) { diff --git a/src/File.cc b/src/File.cc index bc115bfa..b6fe6643 100644 --- a/src/File.cc +++ b/src/File.cc @@ -59,7 +59,7 @@ File::File(const std::string& name):name(name) {} File::~File() {} int File::fillStat(a2_struct_stat& fstat) { - return stat(name.c_str(), &fstat); + return a2stat(name.c_str(), &fstat); } bool File::exists() { diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index ba66655b..32293cf0 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -577,8 +577,13 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const o << "\n" <<_("Download Results:") << "\n" << "gid|stat|avg speed |path/URI" << "\n" - << "===+====+===========+===========================================================" << "\n"; - + << "===+====+===========+"; +#ifdef __MINGW32__ + int pathRowSize = 58; +#else // !__MINGW32__ + int pathRowSize = 59; +#endif // !__MINGW32__ + o << std::setfill('=') << std::setw(pathRowSize) << '=' << "\n"; int ok = 0; int err = 0; int inpr = 0; diff --git a/src/a2io.h b/src/a2io.h index 8559c687..11b2398c 100644 --- a/src/a2io.h +++ b/src/a2io.h @@ -113,22 +113,27 @@ #endif // HAVE_WINSOCK2_H #ifdef __MINGW32__ -# define lseek(fd, offset, origin) _lseeki64(fd, offset, origin) -# define fseek(fd, offset, origin) _fseeki64(fd, offset, origin) -# define fstat(fd, buf) _fstati64(fd, buf) -# define ftell(fd) _ftelli64(fd) -# define wstat(path, buf) _wstati64(path, buf) +# define a2lseek(fd, offset, origin) _lseeki64(fd, offset, origin) +# define a2fseek(fd, offset, origin) _fseeki64(fd, offset, origin) +# define a2fstat(fd, buf) _fstati64(fd, buf) +# define a2ftell(fd) _ftelli64(fd) +# define a2wstat(path, buf) _wstati64(path, buf) # ifdef stat # undef stat # endif // stat # define a2_struct_stat struct _stati64 -# define stat(path, buf) _stati64(path, buf) -# define tell(handle) _telli64(handle) +# define a2stat(path, buf) _stati64(path, buf) +# define a2tell(handle) _telli64(handle) # define a2mkdir(path, openMode) mkdir(path) -#else +#else // !__MINGW32__ +# define a2lseek(fd, offset, origin) lseek(fd, offset, origin) +# define a2fseek(fp, offset, origin) fseek(fp, offset, origin) +# define a2fstat(fp, buf) fstat(fp, buf) +# define a2ftell(fp) ftell(fp) # define a2_struct_stat struct stat +# define a2stat(path, buf) stat(path, buf) # define a2mkdir(path, openMode) mkdir(path, openMode) -#endif // __MINGW32__ +#endif // !__MINGW32__ #if defined HAVE_POSIX_MEMALIGN && defined O_DIRECT # define ENABLE_DIRECT_IO 1 diff --git a/test/FileTest.cc b/test/FileTest.cc index 2b2c8d4d..5808a79e 100644 --- a/test/FileTest.cc +++ b/test/FileTest.cc @@ -222,7 +222,7 @@ void FileTest::testUtime() CPPUNIT_ASSERT(f.utime(Time(atime), Time(mtime))); a2_struct_stat buf; - CPPUNIT_ASSERT(0 == stat(f.getPath().c_str(), &buf)); + CPPUNIT_ASSERT(0 == a2stat(f.getPath().c_str(), &buf)); CPPUNIT_ASSERT_EQUAL((time_t)atime, buf.st_atime); CPPUNIT_ASSERT_EQUAL((time_t)mtime, f.getModifiedTime().getTime());