浏览代码

Use PRId64 for int64_t format specifier

Tatsuhiro Tsujikawa 13 年之前
父节点
当前提交
4b03634f36
共有 44 个文件被更改,包括 206 次插入213 次删除
  1. 15 15
      src/AbstractCommand.cc
  2. 2 2
      src/AbstractDiskWriter.cc
  3. 3 3
      src/AbstractHttpServerResponseCommand.cc
  4. 3 3
      src/BtDependency.cc
  5. 2 2
      src/BtPieceMessage.cc
  6. 1 1
      src/BtStopDownloadCommand.cc
  7. 1 1
      src/CheckIntegrityDispatcherCommand.cc
  8. 1 1
      src/Command.h
  9. 3 4
      src/DHTMessageFactoryImpl.cc
  10. 1 1
      src/DHTMessageTracker.cc
  11. 7 7
      src/DefaultBtAnnounce.cc
  12. 2 2
      src/DefaultBtInteractive.cc
  13. 3 3
      src/DefaultBtProgressInfoFile.cc
  14. 1 1
      src/DownloadCommand.cc
  15. 1 1
      src/FileAllocationCommand.cc
  16. 4 3
      src/FtpConnection.cc
  17. 3 3
      src/FtpFinishDownloadCommand.cc
  18. 5 6
      src/FtpNegotiationCommand.cc
  19. 4 7
      src/HttpHeader.cc
  20. 2 2
      src/HttpRequest.cc
  21. 7 7
      src/HttpResponse.cc
  22. 3 3
      src/HttpServerBodyCommand.cc
  23. 3 3
      src/HttpServerCommand.cc
  24. 1 1
      src/HttpServerResponseCommand.cc
  25. 2 2
      src/InitiatorMSEHandshakeCommand.cc
  26. 1 1
      src/IteratableChunkChecksumValidator.cc
  27. 21 21
      src/MSEHandshake.cc
  28. 7 7
      src/MultiDiskAdaptor.cc
  29. 4 7
      src/OptionHandlerImpl.cc
  30. 1 1
      src/PeerAbstractCommand.cc
  31. 1 1
      src/PeerConnection.cc
  32. 1 1
      src/PeerListenCommand.cc
  33. 7 7
      src/RequestGroup.cc
  34. 1 2
      src/RequestGroup.h
  35. 2 2
      src/RequestGroupMan.cc
  36. 13 13
      src/RpcMethodImpl.cc
  37. 4 4
      src/SegmentMan.cc
  38. 2 2
      src/TrackerWatcherCommand.cc
  39. 1 1
      src/WatchProcessCommand.cc
  40. 2 2
      src/WebSocketInteractionCommand.cc
  41. 2 4
      src/bittorrent_helper.cc
  42. 3 0
      src/common.h
  43. 52 52
      src/message.h
  44. 1 1
      src/util.cc

+ 15 - 15
src/AbstractCommand.cc

@@ -121,7 +121,7 @@ AbstractCommand::~AbstractCommand() {
 void AbstractCommand::useFasterRequest
 (const SharedHandle<Request>& fasterRequest)
 {
-  A2_LOG_INFO(fmt("CUID#%lld - Use faster Request hostname=%s, port=%u",
+  A2_LOG_INFO(fmt("CUID#%" PRId64 " - Use faster Request hostname=%s, port=%u",
                   getCuid(),
                   fasterRequest->getHost().c_str(),
                   fasterRequest->getPort()));
@@ -135,7 +135,7 @@ void AbstractCommand::useFasterRequest
 }
 
 bool AbstractCommand::execute() {
-  A2_LOG_DEBUG(fmt("CUID#%lld - socket: read:%d, write:%d, hup:%d, err:%d",
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - socket: read:%d, write:%d, hup:%d, err:%d",
                    getCuid(),
                    readEventEnabled(),
                    writeEventEnabled(),
@@ -146,7 +146,7 @@ bool AbstractCommand::execute() {
       return true;
     }
     if(req_ && req_->removalRequested()) {
-      A2_LOG_DEBUG(fmt("CUID#%lld - Discard original URI=%s because it is"
+      A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Discard original URI=%s because it is"
                        " requested.",
                        getCuid(), req_->getUri().c_str()));
       return prepareForRetry(0);
@@ -158,7 +158,7 @@ bool AbstractCommand::execute() {
         // This command previously has assigned segments, but it is
         // canceled. So discard current request chain.  Plus, if no
         // segment is available when http pipelining is used.
-        A2_LOG_DEBUG(fmt("CUID#%lld - It seems previously assigned segments"
+        A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - It seems previously assigned segments"
                          " are canceled. Restart.",
                          getCuid()));
         // Request::isPipeliningEnabled() == true means aria2
@@ -273,7 +273,7 @@ bool AbstractCommand::execute() {
         // empty.
         if(!req_->getConnectedAddr().empty()) {
           // Purging IP address cache to renew IP address.
-          A2_LOG_DEBUG(fmt("CUID#%lld - Marking IP address %s as bad",
+          A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Marking IP address %s as bad",
                            getCuid(),
                            req_->getConnectedAddr().c_str()));
           e_->markBadIPAddress(req_->getConnectedHostname(),
@@ -282,7 +282,7 @@ bool AbstractCommand::execute() {
         }
         if(e_->findCachedIPAddress
            (req_->getConnectedHostname(), req_->getConnectedPort()).empty()) {
-          A2_LOG_DEBUG(fmt("CUID#%lld - All IP addresses were marked bad."
+          A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - All IP addresses were marked bad."
                            " Removing Entry.",
                            getCuid()));
           e_->removeCachedIPAddress
@@ -370,14 +370,14 @@ void AbstractCommand::tryReserved() {
     // and there are no URI left. Because file length is unknown, we
     // can assume that there are no in-flight request object.
     if(entry->getLength() == 0 && entry->getRemainingUris().empty()) {
-      A2_LOG_DEBUG(fmt("CUID#%lld - Not trying next request."
+      A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Not trying next request."
                        " No reserved/pooled request is remaining and"
                        " total length is still unknown.",
                        getCuid()));
       return;
     }
   }
-  A2_LOG_DEBUG(fmt("CUID#%lld - Trying reserved/pooled request.",
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Trying reserved/pooled request.",
                    getCuid()));
   std::vector<Command*> commands;
   requestGroup_->createNextCommand(commands, e_, 1);
@@ -397,7 +397,7 @@ bool AbstractCommand::prepareForRetry(time_t wait) {
     req_->setMaxPipelinedRequest(1);
 
     fileEntry_->poolRequest(req_);
-    A2_LOG_DEBUG(fmt("CUID#%lld - Pooling request URI=%s",
+    A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Pooling request URI=%s",
                      getCuid(), req_->getUri().c_str()));
     if(getSegmentMan()) {
       getSegmentMan()->recognizeSegmentFor(fileEntry_);
@@ -422,7 +422,7 @@ void AbstractCommand::onAbort() {
     fileEntry_->removeIdenticalURI(req_->getUri());
     fileEntry_->removeRequest(req_);
   }
-  A2_LOG_DEBUG(fmt("CUID#%lld - Aborting download",
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Aborting download",
                    getCuid()));
   if(getPieceStorage()) {
     getSegmentMan()->cancelSegment(getCuid());
@@ -440,10 +440,10 @@ void AbstractCommand::onAbort() {
         // Local file exists, but given servers(or at least contacted
         // ones) doesn't support resume. Let's restart download from
         // scratch.
-        A2_LOG_NOTICE(fmt(_("CUID#%lld - Failed to resume download."
+        A2_LOG_NOTICE(fmt(_("CUID#%" PRId64 " - Failed to resume download."
                             " Download from scratch."),
                           getCuid()));
-        A2_LOG_DEBUG(fmt("CUID#%lld - Gathering URIs that has CANNOT_RESUME"
+        A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Gathering URIs that has CANNOT_RESUME"
                          " error",
                          getCuid()));
         // Set PREF_ALWAYS_RESUME to A2_V_TRUE to avoid repeating this
@@ -459,7 +459,7 @@ void AbstractCommand::onAbort() {
           uris.reserve(res.size());
           std::transform(res.begin(), res.end(), std::back_inserter(uris),
                          std::mem_fun_ref(&URIResult::getURI));
-          A2_LOG_DEBUG(fmt("CUID#%lld - %lu URIs found.",
+          A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - %lu URIs found.",
                            getCuid(),
                            static_cast<unsigned long int>(uris.size())));
           fileEntry_->addUris(uris.begin(), uris.end());
@@ -675,9 +675,9 @@ SharedHandle<Request> AbstractCommand::createProxyRequest() const
   if(!proxy.empty()) {
     proxyRequest.reset(new Request());
     if(proxyRequest->setUri(proxy)) {
-      A2_LOG_DEBUG(fmt("CUID#%lld - Using proxy", getCuid()));
+      A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Using proxy", getCuid()));
     } else {
-      A2_LOG_DEBUG(fmt("CUID#%lld - Failed to parse proxy string",
+      A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Failed to parse proxy string",
                        getCuid()));
       proxyRequest.reset();
     }

+ 2 - 2
src/AbstractDiskWriter.cc

@@ -215,9 +215,9 @@ void AbstractDiskWriter::ensureMmapWrite(size_t len, off_t offset)
         mapaddr_ = reinterpret_cast<unsigned char*>
           (mmap(0, size(), PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0));
         if(mapaddr_) {
-          A2_LOG_DEBUG(fmt("mmap for file %s succeeded, length=%lld",
+          A2_LOG_DEBUG(fmt("mmap for file %s succeeded, length=%" PRId64 "",
                            filename_.c_str(),
-                           static_cast<long long int>(filesize)));
+                           static_cast<uint64_t>(filesize)));
           maplen_ = filesize;
         } else {
           int errNum = errno;

+ 3 - 3
src/AbstractHttpServerResponseCommand.cc

@@ -75,19 +75,19 @@ bool AbstractHttpServerResponseCommand::execute()
     httpServer_->sendResponse();
   } catch(RecoverableException& e) {
     A2_LOG_INFO_EX
-      (fmt("CUID#%lld - Error occurred while transmitting response body.",
+      (fmt("CUID#%" PRId64 " - Error occurred while transmitting response body.",
            getCuid()),
        e);
     return true;
   }
   if(httpServer_->sendBufferIsEmpty()) {
-    A2_LOG_INFO(fmt("CUID#%lld - HttpServer: all response transmitted.",
+    A2_LOG_INFO(fmt("CUID#%" PRId64 " - HttpServer: all response transmitted.",
                     getCuid()));
     afterSend(httpServer_, e_);
     return true;
   } else {
     if(timeoutTimer_.difference(global::wallclock()) >= 10) {
-      A2_LOG_INFO(fmt("CUID#%lld - HttpServer: Timeout while trasmitting"
+      A2_LOG_INFO(fmt("CUID#%" PRId64 " - HttpServer: Timeout while trasmitting"
                       " response.",
                       getCuid()));
       return true;

+ 3 - 3
src/BtDependency.cc

@@ -155,11 +155,11 @@ bool BtDependency::resolve()
       }
     } catch(RecoverableException& e) {
       A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
-      A2_LOG_INFO(fmt("BtDependency for GID#%lld failed. Go without Bt.",
+      A2_LOG_INFO(fmt("BtDependency for GID#%" PRId64 " failed. Go without Bt.",
                       dependant_->getGID()));
       return true;
     }
-    A2_LOG_INFO(fmt("Dependency resolved for GID#%lld",
+    A2_LOG_INFO(fmt("Dependency resolved for GID#%" PRId64 "",
                     dependant_->getGID()));
     dependant_->setDownloadContext(context);
     return true;
@@ -167,7 +167,7 @@ bool BtDependency::resolve()
     // dependee_'s download failed.
     // cut reference here
     dependee_.reset();
-    A2_LOG_INFO(fmt("BtDependency for GID#%lld failed. Go without Bt.",
+    A2_LOG_INFO(fmt("BtDependency for GID#%" PRId64 " failed. Go without Bt.",
                     dependant_->getGID()));
     return true;
   } else {

+ 2 - 2
src/BtPieceMessage.cc

@@ -109,7 +109,7 @@ void BtPieceMessage::doReceivedAction()
                      static_cast<unsigned long>(index_),
                      begin_,
                      blockLength_,
-                     static_cast<long long int>(offset),
+                     static_cast<int64_t>(offset),
                      static_cast<unsigned long>(slot.getBlockIndex())));
     if(piece->hasBlock(slot.getBlockIndex())) {
       A2_LOG_DEBUG("Already have this block.");
@@ -133,7 +133,7 @@ void BtPieceMessage::doReceivedAction()
       }
     }
   } else {
-    A2_LOG_DEBUG(fmt("CUID#%lld - RequestSlot not found, index=%lu, begin=%d",
+    A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - RequestSlot not found, index=%lu, begin=%d",
                      getCuid(),
                      static_cast<unsigned long>(index_),
                      begin_));

+ 1 - 1
src/BtStopDownloadCommand.cc

@@ -61,7 +61,7 @@ void BtStopDownloadCommand::preProcess()
     enableExit();
   }
   if(checkPoint_.difference(global::wallclock()) >= timeout_) {
-    A2_LOG_NOTICE(fmt(_("GID#%lld Stop downloading torrent due to"
+    A2_LOG_NOTICE(fmt(_("GID#%" PRId64 " Stop downloading torrent due to"
                         " --bt-stop-timeout option."),
                       requestGroup_->getGID()));
     requestGroup_->setForceHaltRequested(true);

+ 1 - 1
src/CheckIntegrityDispatcherCommand.cc

@@ -56,7 +56,7 @@ Command* CheckIntegrityDispatcherCommand::createCommand
 (const SharedHandle<CheckIntegrityEntry>& entry)
 {
   cuid_t newCUID = getDownloadEngine()->newCUID();
-  A2_LOG_INFO(fmt("CUID#%lld - Dispatching CheckIntegrityCommand CUID#%lld.",
+  A2_LOG_INFO(fmt("CUID#%" PRId64 " - Dispatching CheckIntegrityCommand CUID#%" PRId64 ".",
                   getCuid(), newCUID));
   return new CheckIntegrityCommand
     (newCUID, entry->getRequestGroup(), getDownloadEngine(), entry);

+ 1 - 1
src/Command.h

@@ -39,7 +39,7 @@
 
 namespace aria2 {
 
-typedef long long int cuid_t;
+typedef int64_t cuid_t;
 
 class Command {
 public:

+ 3 - 4
src/DHTMessageFactoryImpl.cc

@@ -183,8 +183,7 @@ void DHTMessageFactoryImpl::validatePort(const Integer* port) const
 {
   if(!(0 < port->i() && port->i() < UINT16_MAX)) {
     throw DL_ABORT_EX
-      (fmt("Malformed DHT message. Invalid port=%lld",
-           static_cast<long long int>(port->i())));
+      (fmt("Malformed DHT message. Invalid port=%" PRId64 "", port->i()));
   }
 }
 
@@ -256,8 +255,8 @@ DHTMessageFactoryImpl::createResponseMessage
     // for now, just report error message arrived and throw exception.
     const List* e = getList(dict, DHTUnknownMessage::E);
     if(e->size() == 2) {
-      A2_LOG_INFO(fmt("Received Error DHT message. code=%lld, msg=%s",
-                      static_cast<long long int>(getInteger(e, 0)->i()),
+      A2_LOG_INFO(fmt("Received Error DHT message. code=%" PRId64 ", msg=%s",
+                      getInteger(e, 0)->i(),
                       util::percentEncode(getString(e, 1)->s()).c_str()));
     } else {
       A2_LOG_DEBUG("e doesn't have 2 elements.");

+ 1 - 1
src/DHTMessageTracker.cc

@@ -87,7 +87,7 @@ DHTMessageTracker::messageArrived
                                           targetNode->getPort());
 
         int64_t rtt = entry->getElapsedMillis();
-        A2_LOG_DEBUG(fmt("RTT is %lld", static_cast<long long int>(rtt)));
+        A2_LOG_DEBUG(fmt("RTT is %" PRId64 "", rtt));
         message->getRemoteNode()->updateRTT(rtt);
         SharedHandle<DHTMessageCallback> callback = entry->getCallback();
         if(!(*targetNode == *message->getRemoteNode())) {

+ 7 - 7
src/DefaultBtAnnounce.cc

@@ -142,7 +142,7 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
     numWant = 0;
   }
   TransferStat stat = peerStorage_->calculateStat();
-  off_t left =
+  int64_t left =
     pieceStorage_->getTotalLength()-pieceStorage_->getCompletedLength();
   // Use last 8 bytes of peer ID as a key
   const size_t keyLen = 8;
@@ -150,9 +150,9 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
   uri += uriHasQuery(uri) ? "&" : "?";
   uri += fmt("info_hash=%s&"
              "peer_id=%s&"
-             "uploaded=%lld&"
-             "downloaded=%lld&"
-             "left=%lld&"
+             "uploaded=%" PRId64 "&"
+             "downloaded=%" PRId64 "&"
+             "left=%" PRId64 "&"
              "compact=1&"
              "key=%s&"
              "numwant=%d&"
@@ -162,9 +162,9 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
               INFO_HASH_LENGTH).c_str(),
              util::torrentPercentEncode
              (bittorrent::getStaticPeerId(), PEER_ID_LENGTH).c_str(),
-             static_cast<long long int>(stat.getSessionUploadLength()),
-             static_cast<long long int>(stat.getSessionDownloadLength()),
-             static_cast<long long int>(left),
+             stat.getSessionUploadLength(),
+             stat.getSessionDownloadLength(),
+             left,
              util::torrentPercentEncode
              (bittorrent::getStaticPeerId()+PEER_ID_LENGTH-keyLen,
               keyLen).c_str(),

+ 2 - 2
src/DefaultBtInteractive.cc

@@ -117,7 +117,7 @@ BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) {
   if(memcmp(message->getPeerId(), bittorrent::getStaticPeerId(),
             PEER_ID_LENGTH) == 0) {
     throw DL_ABORT_EX
-      (fmt("CUID#%lld - Drop connection from the same Peer ID",
+      (fmt("CUID#%" PRId64 " - Drop connection from the same Peer ID",
            cuid_));
   }
   std::vector<SharedHandle<Peer> > activePeers;
@@ -126,7 +126,7 @@ BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) {
         eoi = activePeers.end(); i != eoi; ++i) {
     if(memcmp((*i)->getPeerId(), message->getPeerId(), PEER_ID_LENGTH) == 0) {
       throw DL_ABORT_EX
-        (fmt("CUID#%lld - Same Peer ID has been already seen.",
+        (fmt("CUID#%" PRId64 " - Same Peer ID has been already seen.",
              cuid_));
     }
   }

+ 3 - 3
src/DefaultBtProgressInfoFile.cc

@@ -276,9 +276,9 @@ void DefaultBtProgressInfoFile::load()
   }
   if(totalLength != static_cast<uint64_t>(dctx_->getTotalLength())) {
     throw DL_ABORT_EX
-      (fmt("total length mismatch. expected: %lld, actual: %lld",
-           static_cast<long long int>(dctx_->getTotalLength()),
-           static_cast<long long int>(totalLength)));
+      (fmt("total length mismatch. expected: %" PRId64 ", actual: %" PRId64 "",
+           static_cast<int64_t>(dctx_->getTotalLength()),
+           static_cast<int64_t>(totalLength)));
   }
   uint64_t uploadLength;
   READ_CHECK(fp, &uploadLength, sizeof(uploadLength));

+ 1 - 1
src/DownloadCommand.cc

@@ -361,7 +361,7 @@ void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
   } else {
     A2_LOG_INFO(fmt(EX_INVALID_CHUNK_CHECKSUM,
                     static_cast<unsigned long>(segment->getIndex()),
-                    static_cast<long long int>(segment->getPosition()),
+                    static_cast<int64_t>(segment->getPosition()),
                     util::toHex(expectedHash).c_str(),
                     util::toHex(actualHash).c_str()));
     segment->clear();

+ 1 - 1
src/FileAllocationCommand.cc

@@ -71,7 +71,7 @@ bool FileAllocationCommand::executeInternal()
     A2_LOG_DEBUG
       (fmt(MSG_ALLOCATION_COMPLETED,
            static_cast<long int>(timer_.difference(global::wallclock())),
-           static_cast<long long int>(getRequestGroup()->getTotalLength())));
+           static_cast<int64_t>(getRequestGroup()->getTotalLength())));
     getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();
     
     std::vector<Command*>* commands = new std::vector<Command*>();

+ 4 - 3
src/FtpConnection.cc

@@ -254,9 +254,10 @@ bool FtpConnection::sendRest(const SharedHandle<Segment>& segment)
 {
   if(socketBuffer_.sendBufferIsEmpty()) {
     std::string request =
-      fmt("REST %lld\r\n",
+      fmt("REST %" PRId64 "\r\n",
           segment ?
-          static_cast<long long int>(segment->getPositionToWrite()) : 0LL);
+          static_cast<int64_t>(segment->getPositionToWrite()) :
+          static_cast<int64_t>(0LL));
     A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
                     cuid_, request.c_str()));
     socketBuffer_.pushStr(request);
@@ -392,7 +393,7 @@ int FtpConnection::receiveResponse()
 # define LONGLONG_SCANF "%I64d"
 # define ULONGLONG_SCANF "%I64u"
 #else
-# define LONGLONG_PRINTF "%lld"
+# define LONGLONG_PRINTF "%" PRId64 ""
 # define ULONGLONG_PRINTF "%llu"
 # define LONGLONG_SCANF "%Ld"
 // Mac OSX uses "%llu" for 64bits integer.

+ 3 - 3
src/FtpFinishDownloadCommand.cc

@@ -92,18 +92,18 @@ bool FtpFinishDownloadCommand::execute()
              getSocket(), options);
         }
       } else {
-        A2_LOG_INFO(fmt("CUID#%lld - Bad status for transfer complete.",
+        A2_LOG_INFO(fmt("CUID#%" PRId64 " - Bad status for transfer complete.",
                         getCuid()));
       }
     } else if(getCheckPoint().difference(global::wallclock()) >= getTimeout()) {
-      A2_LOG_INFO(fmt("CUID#%lld - Timeout before receiving transfer complete.",
+      A2_LOG_INFO(fmt("CUID#%" PRId64 " - Timeout before receiving transfer complete.",
                       getCuid()));
     } else {
       getDownloadEngine()->addCommand(this);
       return false;
     }
   } catch(RecoverableException& e) {
-    A2_LOG_INFO_EX(fmt("CUID#%lld - Exception was thrown, but download was"
+    A2_LOG_INFO_EX(fmt("CUID#%" PRId64 " - Exception was thrown, but download was"
                        " finished, so we can ignore the exception.",
                        getCuid()),
                    e);

+ 5 - 6
src/FtpNegotiationCommand.cc

@@ -265,7 +265,7 @@ bool FtpNegotiationCommand::recvPwd()
                        error_code::FTP_PROTOCOL_ERROR);
   }
   ftp_->setBaseWorkingDir(pwd);
-  A2_LOG_INFO(fmt("CUID#%lld - base working directory is '%s'",
+  A2_LOG_INFO(fmt("CUID#%" PRId64 " - base working directory is '%s'",
                   getCuid(), pwd.c_str()));
   sequence_ = SEQ_SEND_CWD_PREP;
   return true;
@@ -350,7 +350,7 @@ bool FtpNegotiationCommand::recvMdtm()
                    " a time value as in specified in RFC3659.");
     }
   } else {
-    A2_LOG_INFO(fmt("CUID#%lld - MDTM command failed.",
+    A2_LOG_INFO(fmt("CUID#%" PRId64 " - MDTM command failed.",
                     getCuid()));
   }
   sequence_ = SEQ_SEND_SIZE;
@@ -502,9 +502,8 @@ bool FtpNegotiationCommand::recvSize() {
   }
   if(status == 213) {
     if(size > std::numeric_limits<off_t>::max()) {
-      throw DL_ABORT_EX2
-        (fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(size)),
-         error_code::FTP_PROTOCOL_ERROR);
+      throw DL_ABORT_EX2(fmt(EX_TOO_LARGE_FILE, size),
+                         error_code::FTP_PROTOCOL_ERROR);
     }
     if(!getPieceStorage()) {
 
@@ -516,7 +515,7 @@ bool FtpNegotiationCommand::recvSize() {
     }
 
   } else {
-    A2_LOG_INFO(fmt("CUID#%lld - The remote FTP Server doesn't recognize SIZE"
+    A2_LOG_INFO(fmt("CUID#%" PRId64 " - The remote FTP Server doesn't recognize SIZE"
                     " command. Continue.", getCuid()));
     // Even if one of the other servers waiting in the queue supports SIZE
     // command, resuming and segmented downloading are disabled when the first

+ 4 - 7
src/HttpHeader.cc

@@ -142,7 +142,7 @@ RangeHandle HttpHeader::getRange() const
         throw DL_ABORT_EX("Content-Length must be positive");
       } else if(contentLength > std::numeric_limits<off_t>::max()) {
         throw DOWNLOAD_FAILURE_EXCEPTION
-          (fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(contentLength)));
+          (fmt(EX_TOO_LARGE_FILE, contentLength));
       } else if(contentLength == 0) {
         return SharedHandle<Range>(new Range());
       } else {
@@ -187,16 +187,13 @@ RangeHandle HttpHeader::getRange() const
     throw DL_ABORT_EX("byte-range-spec must be positive");
   }
   if(startByte > std::numeric_limits<off_t>::max()) {
-    throw DOWNLOAD_FAILURE_EXCEPTION
-      (fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(startByte)));
+    throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, startByte));
   }
   if(endByte > std::numeric_limits<off_t>::max()) {
-    throw DOWNLOAD_FAILURE_EXCEPTION
-      (fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(endByte)));
+    throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, endByte));
   }
   if(entityLength > std::numeric_limits<off_t>::max()) {
-    throw DOWNLOAD_FAILURE_EXCEPTION
-      (fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(entityLength)));
+    throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, entityLength));
   }
   return SharedHandle<Range>(new Range(startByte, endByte, entityLength));
 }

+ 2 - 2
src/HttpRequest.cc

@@ -193,8 +193,8 @@ std::string HttpRequest::createRequest()
   }
   if(segment_ && segment_->getLength() > 0 && 
      (request_->isPipeliningEnabled() || getStartByte() > 0)) {
-    std::string rangeHeader(fmt("bytes=%lld-",
-                                static_cast<long long int>(getStartByte())));
+    std::string rangeHeader(fmt("bytes=%" PRId64 "-",
+                                static_cast<int64_t>(getStartByte())));
     if(request_->isPipeliningEnabled()) {
       rangeHeader += util::itos(getEndByte());
     } else if(getProtocol() != Request::PROTO_FTP && endOffsetOverride_ > 0) {

+ 7 - 7
src/HttpResponse.cc

@@ -100,12 +100,12 @@ void HttpResponse::validateResponse() const
       if(!httpRequest_->isRangeSatisfied(responseRange)) {
         throw DL_ABORT_EX2
           (fmt(EX_INVALID_RANGE_HEADER,
-               static_cast<long long int>(httpRequest_->getStartByte()),
-               static_cast<long long int>(httpRequest_->getEndByte()),
-               static_cast<long long int>(httpRequest_->getEntityLength()),
-               static_cast<long long int>(responseRange->getStartByte()),
-               static_cast<long long int>(responseRange->getEndByte()),
-               static_cast<long long int>(responseRange->getEntityLength())),
+               static_cast<int64_t>(httpRequest_->getStartByte()),
+               static_cast<int64_t>(httpRequest_->getEndByte()),
+               static_cast<int64_t>(httpRequest_->getEntityLength()),
+               static_cast<int64_t>(responseRange->getStartByte()),
+               static_cast<int64_t>(responseRange->getEndByte()),
+               static_cast<int64_t>(responseRange->getEntityLength())),
            error_code::CANNOT_RESUME);
       }
     }
@@ -170,7 +170,7 @@ void HttpResponse::processRedirect()
                     httpRequest_->getRequest()->getCurrentUri().c_str()));
   } else {
     throw DL_RETRY_EX
-      (fmt("CUID#%lld - Redirect to %s failed. It may not be a valid URI.",
+      (fmt("CUID#%" PRId64 " - Redirect to %s failed. It may not be a valid URI.",
            cuid_,
            httpRequest_->getRequest()->getCurrentUri().c_str()));
   }

+ 3 - 3
src/HttpServerBodyCommand.cc

@@ -195,7 +195,7 @@ bool HttpServerBodyCommand::execute()
             req = rpc::xmlParseMemory(body.c_str(), body.size());
           } catch(RecoverableException& e) {
             A2_LOG_INFO_EX
-              (fmt("CUID#%lld - Failed to parse XML-RPC request",
+              (fmt("CUID#%" PRId64 " - Failed to parse XML-RPC request",
                    getCuid()),
                e);
             httpServer_->feedResponse(400);
@@ -228,7 +228,7 @@ bool HttpServerBodyCommand::execute()
             }
           } catch(RecoverableException& e) {
             A2_LOG_INFO_EX
-              (fmt("CUID#%lld - Failed to parse JSON-RPC request",
+              (fmt("CUID#%" PRId64 " - Failed to parse JSON-RPC request",
                    getCuid()),
                e);
             rpc::RpcResponse res
@@ -283,7 +283,7 @@ bool HttpServerBodyCommand::execute()
     }
   } catch(RecoverableException& e) {
     A2_LOG_INFO_EX
-      (fmt("CUID#%lld - Error occurred while reading HTTP request body",
+      (fmt("CUID#%" PRId64 " - Error occurred while reading HTTP request body",
            getCuid()),
        e);
     return true;

+ 3 - 3
src/HttpServerCommand.cc

@@ -216,10 +216,10 @@ bool HttpServerCommand::execute()
         if(e_->getOption()->getAsInt(PREF_RPC_MAX_REQUEST_SIZE) <
            httpServer_->getContentLength()) {
           A2_LOG_INFO
-            (fmt("Request too long. ContentLength=%lld."
+            (fmt("Request too long. ContentLength=%" PRId64 "."
                  " See --rpc-max-request-size option to loose"
                  " this limitation.",
-                 static_cast<long long int>(httpServer_->getContentLength())));
+                 static_cast<int64_t>(httpServer_->getContentLength())));
           return true;
         }
         Command* command = new HttpServerBodyCommand(getCuid(), httpServer_, e_,
@@ -238,7 +238,7 @@ bool HttpServerCommand::execute()
       }
     }
   } catch(RecoverableException& e) {
-    A2_LOG_INFO_EX(fmt("CUID#%lld - Error occurred while reading HTTP request",
+    A2_LOG_INFO_EX(fmt("CUID#%" PRId64 " - Error occurred while reading HTTP request",
                        getCuid()),
                    e);
     return true;

+ 1 - 1
src/HttpServerResponseCommand.cc

@@ -60,7 +60,7 @@ void HttpServerResponseCommand::afterSend
  DownloadEngine* e)
 {
   if(httpServer->supportsPersistentConnection()) {
-    A2_LOG_INFO(fmt("CUID#%lld - Persist connection.",
+    A2_LOG_INFO(fmt("CUID#%" PRId64 " - Persist connection.",
                     getCuid()));
     e->addCommand
       (new HttpServerCommand(getCuid(), httpServer, e,

+ 2 - 2
src/InitiatorMSEHandshakeCommand.cc

@@ -217,14 +217,14 @@ bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait)
     tryNewPeer();
     return true;
   } else if(getOption()->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
-    A2_LOG_INFO(fmt("CUID#%lld - Establishing connection using legacy"
+    A2_LOG_INFO(fmt("CUID#%" PRId64 " - Establishing connection using legacy"
                     " BitTorrent handshake is disabled by preference.",
                     getCuid()));
     tryNewPeer();
     return true;
   } else {
     // try legacy BitTorrent handshake
-    A2_LOG_INFO(fmt("CUID#%lld - Retry using legacy BitTorrent handshake.",
+    A2_LOG_INFO(fmt("CUID#%" PRId64 " - Retry using legacy BitTorrent handshake.",
                     getCuid()));
     PeerInitiateConnectionCommand* command =
       new PeerInitiateConnectionCommand(getCuid(), requestGroup_, getPeer(),

+ 1 - 1
src/IteratableChunkChecksumValidator.cc

@@ -78,7 +78,7 @@ void IteratableChunkChecksumValidator::validateChunk()
         A2_LOG_INFO
           (fmt(EX_INVALID_CHUNK_CHECKSUM,
                static_cast<unsigned long>(currentIndex_),
-               static_cast<long long int>(getCurrentOffset()),
+               static_cast<int64_t>(getCurrentOffset()),
                util::toHex(dctx_->getPieceHashes()[currentIndex_]).c_str(),
                util::toHex(actualChecksum).c_str()));
         bitfield_->unsetBit(currentIndex_);

+ 21 - 21
src/MSEHandshake.cc

@@ -104,11 +104,11 @@ MSEHandshake::HANDSHAKE_TYPE MSEHandshake::identifyHandshakeType()
   }
   if(rbuf_[0] == BtHandshakeMessage::PSTR_LENGTH &&
      memcmp(BtHandshakeMessage::BT_PSTR, rbuf_+1, 19) == 0) {
-    A2_LOG_DEBUG(fmt("CUID#%lld - This is legacy BitTorrent handshake.",
+    A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - This is legacy BitTorrent handshake.",
                      cuid_));
     return HANDSHAKE_LEGACY;
   } else {
-    A2_LOG_DEBUG(fmt("CUID#%lld - This may be encrypted BitTorrent handshake.",
+    A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - This may be encrypted BitTorrent handshake.",
                      cuid_));
     return HANDSHAKE_ENCRYPTED;
   }
@@ -120,13 +120,13 @@ void MSEHandshake::initEncryptionFacility(bool initiator)
   dh_ = new DHKeyExchange();
   dh_->init(PRIME, PRIME_BITS, GENERATOR, 160);
   dh_->generatePublicKey();
-  A2_LOG_DEBUG(fmt("CUID#%lld - DH initialized.", cuid_));
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - DH initialized.", cuid_));
   initiator_ = initiator;
 }
 
 void MSEHandshake::sendPublicKey()
 {
-  A2_LOG_DEBUG(fmt("CUID#%lld - Sending public key.",
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Sending public key.",
                    cuid_));
   unsigned char* buf = new unsigned char[KEY_LENGTH+MAX_PAD_LENGTH];
   array_ptr<unsigned char> bufp(buf);
@@ -174,7 +174,7 @@ bool MSEHandshake::receivePublicKey()
     wantRead_ = true;
     return false;
   }
-  A2_LOG_DEBUG(fmt("CUID#%lld - public key received.", cuid_));
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - public key received.", cuid_));
   // TODO handle exception. in catch, resbufLength = 0;
   dh_->computeSecret(secret_, sizeof(secret_), rbuf_, KEY_LENGTH);
   // shift buffer
@@ -269,7 +269,7 @@ uint16_t MSEHandshake::decodeLength16(const unsigned char* buffer)
 
 void MSEHandshake::sendInitiatorStep2()
 {
-  A2_LOG_DEBUG(fmt("CUID#%lld - Sending negotiation step2.", cuid_));
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Sending negotiation step2.", cuid_));
   // Assuming no exception
   unsigned char* md = new unsigned char[20];
   createReq1Hash(md);
@@ -338,7 +338,7 @@ bool MSEHandshake::findInitiatorVCMarker()
     }
   }
   markerIndex_ = ptr-rbuf_;
-  A2_LOG_DEBUG(fmt("CUID#%lld - VC marker found at %lu",
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - VC marker found at %lu",
                    cuid_,
                    static_cast<unsigned long>(markerIndex_)));
   verifyVC(rbuf_+markerIndex_);
@@ -358,18 +358,18 @@ bool MSEHandshake::receiveInitiatorCryptoSelectAndPadDLength()
   decryptor_->encrypt(CRYPTO_BITFIELD_LENGTH, rbufptr, rbufptr);
   if(rbufptr[3]&CRYPTO_PLAIN_TEXT &&
      option_->get(PREF_BT_MIN_CRYPTO_LEVEL) == V_PLAIN) {
-    A2_LOG_DEBUG(fmt("CUID#%lld - peer prefers plaintext.",
+    A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - peer prefers plaintext.",
                      cuid_));
     negotiatedCryptoType_ = CRYPTO_PLAIN_TEXT;
   }
   if(rbufptr[3]&CRYPTO_ARC4) {
-    A2_LOG_DEBUG(fmt("CUID#%lld - peer prefers ARC4",
+    A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - peer prefers ARC4",
                      cuid_));
     negotiatedCryptoType_ = CRYPTO_ARC4;
   }
   if(negotiatedCryptoType_ == CRYPTO_NONE) {
     throw DL_ABORT_EX
-      (fmt("CUID#%lld - No supported crypto type selected.",
+      (fmt("CUID#%" PRId64 " - No supported crypto type selected.",
            cuid_));
   }
   // padD length
@@ -412,7 +412,7 @@ bool MSEHandshake::findReceiverHashMarker()
     }
   }
   markerIndex_ = ptr-rbuf_;
-  A2_LOG_DEBUG(fmt("CUID#%lld - Hash marker found at %lu.",
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Hash marker found at %lu.",
                    cuid_,
                    static_cast<unsigned long>(markerIndex_)));
   verifyReq1Hash(rbuf_+markerIndex_);
@@ -439,7 +439,7 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength
     const unsigned char* infohash = bittorrent::getInfoHash(*i);
     createReq23Hash(md, infohash);
     if(memcmp(md, rbufptr, sizeof(md)) == 0) {
-      A2_LOG_DEBUG(fmt("CUID#%lld - info hash found: %s",
+      A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - info hash found: %s",
                        cuid_,
                        util::toHex(infohash, INFO_HASH_LENGTH).c_str()));
       downloadContext = *i;
@@ -460,17 +460,17 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength
   // For now, choose ARC4.
   if(rbufptr[3]&CRYPTO_PLAIN_TEXT &&
      option_->get(PREF_BT_MIN_CRYPTO_LEVEL) == V_PLAIN) {
-    A2_LOG_DEBUG(fmt("CUID#%lld - peer provides plaintext.",
+    A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - peer provides plaintext.",
                      cuid_));
     negotiatedCryptoType_ = CRYPTO_PLAIN_TEXT;
   } else if(rbufptr[3]&CRYPTO_ARC4) {
-    A2_LOG_DEBUG(fmt("CUID#%lld - peer provides ARC4.",
+    A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - peer provides ARC4.",
                      cuid_));
     negotiatedCryptoType_ = CRYPTO_ARC4;
   }
   if(negotiatedCryptoType_ == CRYPTO_NONE) {
     throw DL_ABORT_EX
-      (fmt("CUID#%lld - No supported crypto type provided.",
+      (fmt("CUID#%" PRId64 " - No supported crypto type provided.",
            cuid_));
   }
   // decrypt PadC length
@@ -491,7 +491,7 @@ bool MSEHandshake::receiveReceiverIALength()
   if(iaLength_ > BtHandshakeMessage::MESSAGE_LENGTH) {
     throw DL_ABORT_EX(fmt("Too large IA length length: %u", iaLength_));
   }
-  A2_LOG_DEBUG(fmt("CUID#%lld - len(IA)=%u.", cuid_, iaLength_));
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - len(IA)=%u.", cuid_, iaLength_));
   // shift rbuf_
   shiftBuffer(2);
   return true;
@@ -509,7 +509,7 @@ bool MSEHandshake::receiveReceiverIA()
   delete [] ia_;
   ia_ = new unsigned char[iaLength_];
   decryptor_->encrypt(iaLength_, ia_, rbuf_);
-  A2_LOG_DEBUG(fmt("CUID#%lld - IA received.", cuid_));
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - IA received.", cuid_));
   // shift rbuf_
   shiftBuffer(iaLength_);
   return true;
@@ -548,10 +548,10 @@ void MSEHandshake::sendReceiverStep2()
 
 uint16_t MSEHandshake::verifyPadLength(const unsigned char* padlenbuf, const char* padName)
 {
-  A2_LOG_DEBUG(fmt("CUID#%lld - Verifying Pad length for %s",
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Verifying Pad length for %s",
                    cuid_, padName));
   uint16_t padLength = decodeLength16(padlenbuf);
-  A2_LOG_DEBUG(fmt("CUID#%lld - len(%s)=%u",
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - len(%s)=%u",
                    cuid_, padName, padLength));
   if(padLength > 512) {
     throw DL_ABORT_EX
@@ -562,7 +562,7 @@ uint16_t MSEHandshake::verifyPadLength(const unsigned char* padlenbuf, const cha
 
 void MSEHandshake::verifyVC(unsigned char* vcbuf)
 {
-  A2_LOG_DEBUG(fmt("CUID#%lld - Verifying VC.", cuid_));
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Verifying VC.", cuid_));
   decryptor_->encrypt(VC_LENGTH, vcbuf, vcbuf);
   if(memcmp(VC, vcbuf, VC_LENGTH) != 0) {
     throw DL_ABORT_EX
@@ -572,7 +572,7 @@ void MSEHandshake::verifyVC(unsigned char* vcbuf)
 
 void MSEHandshake::verifyReq1Hash(const unsigned char* req1buf)
 {
-  A2_LOG_DEBUG(fmt("CUID#%lld - Verifying req hash.", cuid_));
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Verifying req hash.", cuid_));
   unsigned char md[20];
   createReq1Hash(md);
   if(memcmp(md, req1buf, sizeof(md)) != 0) {

+ 7 - 7
src/MultiDiskAdaptor.cc

@@ -186,9 +186,9 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
           (fileEntry->getOffset()+fileEntry->getLength()-1)/
           pieceLength_*pieceLength_;
         A2_LOG_DEBUG(fmt("Checking adjacent backward file to %s"
-                         " whose lastPieceStartOffset+pieceLength_=%lld",
+                         " whose lastPieceStartOffset+pieceLength_=%" PRId64 "",
                          fileEntry->getPath().c_str(),
-                         static_cast<long long int>
+                         static_cast<int64_t>
                          (lastPieceStartOffset+pieceLength_)));
         ++itr;
         // adjacent backward files are not needed to be allocated. They
@@ -197,9 +197,9 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
               (!(*itr)->getFileEntry()->isRequested() ||
                (*itr)->getFileEntry()->getLength() == 0); ++itr) {
           A2_LOG_DEBUG
-            (fmt("file=%s, offset=%lld",
+            (fmt("file=%s, offset=%" PRId64 "",
                  (*itr)->getFileEntry()->getPath().c_str(),
-                 static_cast<long long int>
+                 static_cast<int64_t>
                  ((*itr)->getFileEntry()->getOffset())));
           if((*itr)->getFileEntry()->getOffset() <
              static_cast<off_t>(lastPieceStartOffset+pieceLength_)) {
@@ -348,7 +348,7 @@ DiskWriterEntries::const_iterator findFirstDiskWriterEntry
   // In case when offset is out-of-range
   if(!isInRange(*first, offset)) {
     throw DL_ABORT_EX
-      (fmt(EX_FILE_OFFSET_OUT_OF_RANGE, static_cast<long long int>(offset)));
+      (fmt(EX_FILE_OFFSET_OUT_OF_RANGE, static_cast<int64_t>(offset)));
   }
   return first;
 }
@@ -359,8 +359,8 @@ void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
                                 off_t offset)
 {
   throw DL_ABORT_EX
-    (fmt("DiskWriter for offset=%lld, filename=%s is not opened.",
-         static_cast<long long int>(offset),
+    (fmt("DiskWriter for offset=%" PRId64 ", filename=%s is not opened.",
+         static_cast<int64_t>(offset),
          e->getFilePath().c_str()));  
 }
 } // namespace

+ 4 - 7
src/OptionHandlerImpl.cc

@@ -165,15 +165,12 @@ void NumberOptionHandler::parseArg(Option& option, int64_t number)
     std::string msg = pref_->k;
     msg += " ";
     if(min_ == -1 && max_ != -1) {
-      msg += fmt(_("must be smaller than or equal to %lld."),
-                 static_cast<long long int>(max_));
+      msg += fmt(_("must be smaller than or equal to %" PRId64 "."), max_);
     } else if(min_ != -1 && max_ != -1) {
-      msg += fmt(_("must be between %lld and %lld."),
-                 static_cast<long long int>(min_),
-                 static_cast<long long int>(max_));
+      msg += fmt(_("must be between %" PRId64 " and %" PRId64 "."),
+                 min_, max_);
     } else if(min_ != -1 && max_ == -1) {
-      msg += fmt(_("must be greater than or equal to %lld."),
-                 static_cast<long long int>(min_));
+      msg += fmt(_("must be greater than or equal to %" PRId64 "."), min_);
     } else {
       msg += _("must be a number.");
     }

+ 1 - 1
src/PeerAbstractCommand.cc

@@ -78,7 +78,7 @@ PeerAbstractCommand::~PeerAbstractCommand()
 
 bool PeerAbstractCommand::execute()
 {
-  A2_LOG_DEBUG(fmt("CUID#%lld -"
+  A2_LOG_DEBUG(fmt("CUID#%" PRId64 " -"
                    " socket: read:%d, write:%d, hup:%d, err:%d, noCheck:%d",
                    getCuid(),
                    readEventEnabled(), writeEventEnabled(),

+ 1 - 1
src/PeerConnection.cc

@@ -201,7 +201,7 @@ bool PeerConnection::receiveHandshake(unsigned char* data, size_t& dataLength,
     if(remaining == 0 && !socket_->wantRead() && !socket_->wantWrite()) {
       // we got EOF
       A2_LOG_DEBUG
-        (fmt("CUID#%lld - In PeerConnection::receiveHandshake(), remain=%lu",
+        (fmt("CUID#%" PRId64 " - In PeerConnection::receiveHandshake(), remain=%lu",
              cuid_,
              static_cast<unsigned long>(temp)));
       peer_->setDisconnectedGracefully(true);

+ 1 - 1
src/PeerListenCommand.cc

@@ -124,7 +124,7 @@ bool PeerListenCommand::execute() {
       A2_LOG_DEBUG(fmt("Accepted the connection from %s:%u.",
                        peer->getIPAddress().c_str(),
                        peer->getPort()));
-      A2_LOG_DEBUG(fmt("Added CUID#%lld to receive BitTorrent/MSE handshake.",
+      A2_LOG_DEBUG(fmt("Added CUID#%" PRId64 " to receive BitTorrent/MSE handshake.",
                        cuid));
     } catch(RecoverableException& ex) {
       A2_LOG_DEBUG_EX(fmt(MSG_ACCEPT_FAILURE,

+ 7 - 7
src/RequestGroup.cc

@@ -396,9 +396,9 @@ void RequestGroup::createInitialCommand
           // truncate the file to downloadContext_->getTotalLength()
           A2_LOG_DEBUG
             (fmt("File size not match. File is opened in writable"
-                 " mode. Expected:%lld Actual:%lld",
-                 static_cast<long long int>(downloadContext_->getTotalLength()),
-                 static_cast<long long int>(actualFileSize)));
+                 " mode. Expected:%" PRId64 " Actual:%" PRId64 "",
+                 static_cast<int64_t>(downloadContext_->getTotalLength()),
+                 static_cast<int64_t>(actualFileSize)));
         }
       }
       // Call Load, Save and file allocation command here
@@ -906,8 +906,8 @@ void RequestGroup::validateTotalLength(off_t expectedTotalLength,
   if(expectedTotalLength != actualTotalLength) {
     throw DL_ABORT_EX
       (fmt(EX_SIZE_MISMATCH,
-           static_cast<long long int>(expectedTotalLength),
-           static_cast<long long int>(actualTotalLength)));
+           static_cast<int64_t>(expectedTotalLength),
+           static_cast<int64_t>(actualTotalLength)));
   }
 }
 
@@ -961,7 +961,7 @@ void RequestGroup::decreaseNumCommand()
 {
   --numCommand_;
   if(!numCommand_ && requestGroupMan_) {
-    A2_LOG_DEBUG(fmt("GID#%lld - Request queue check", gid_));
+    A2_LOG_DEBUG(fmt("GID#%" PRId64 " - Request queue check", gid_));
     requestGroupMan_->requestQueueCheck();
   }
 }
@@ -1156,7 +1156,7 @@ bool RequestGroup::needsFileAllocation() const
 
 DownloadResultHandle RequestGroup::createDownloadResult() const
 {
-  A2_LOG_DEBUG(fmt("GID#%lld - Creating DownloadResult.", gid_));
+  A2_LOG_DEBUG(fmt("GID#%" PRId64 " - Creating DownloadResult.", gid_));
   TransferStat st = calculateStat();
   SharedHandle<DownloadResult> res(new DownloadResult());
   res->gid = gid_;

+ 1 - 2
src/RequestGroup.h

@@ -73,8 +73,7 @@ class BtRuntime;
 class PeerStorage;
 #endif // ENABLE_BITTORRENT
 
-// To make %lld happy, we use long long int instead of int64_t.
-typedef long long int a2_gid_t;
+typedef int64_t a2_gid_t;
 
 class RequestGroup {
 public:

+ 2 - 2
src/RequestGroupMan.cc

@@ -207,7 +207,7 @@ size_t RequestGroupMan::changeReservedGroupPosition
   std::deque<SharedHandle<RequestGroup> >::iterator i =
     findByGID(reservedGroups_.begin(), reservedGroups_.end(), gid);
   if(i == reservedGroups_.end()) {
-    throw DL_ABORT_EX(fmt("GID#%lld not found in the waiting queue.", gid));
+    throw DL_ABORT_EX(fmt("GID#%" PRId64 " not found in the waiting queue.", gid));
   }
   SharedHandle<RequestGroup> rg = *i;
   const size_t maxPos = reservedGroups_.size()-1;
@@ -387,7 +387,7 @@ public:
 #endif // ENABLE_BITTORRENT
         } else {
           A2_LOG_NOTICE
-            (fmt(_("Download GID#%lld not complete: %s"),
+            (fmt(_("Download GID#%" PRId64 " not complete: %s"),
                  group->getGID(),
                  group->getDownloadContext()->getBasePath().c_str()));
           group->saveControlFile();

+ 13 - 13
src/RpcMethodImpl.cc

@@ -381,12 +381,12 @@ SharedHandle<ValueBase> removeDownload
   if(!group) {
     group = e->getRequestGroupMan()->findReservedGroup(gid);
     if(!group) {
-      throw DL_ABORT_EX(fmt("Active Download not found for GID#%lld", gid));
+      throw DL_ABORT_EX(fmt("Active Download not found for GID#%" PRId64 "", gid));
     }
     if(group->isDependencyResolved()) {
       e->getRequestGroupMan()->removeReservedGroup(gid);
     } else {
-      throw DL_ABORT_EX(fmt("GID#%lld cannot be removed now", gid));
+      throw DL_ABORT_EX(fmt("GID#%" PRId64 " cannot be removed now", gid));
     }
   } else {
     if(forceRemove) {
@@ -456,7 +456,7 @@ SharedHandle<ValueBase> pauseDownload
     e->setRefreshInterval(0);
     return createGIDResponse(gid);
   } else {
-    throw DL_ABORT_EX(fmt("GID#%lld cannot be paused now", gid));
+    throw DL_ABORT_EX(fmt("GID#%" PRId64 " cannot be paused now", gid));
   }
 }
 } // namespace
@@ -520,7 +520,7 @@ SharedHandle<ValueBase> UnpauseRpcMethod::process
   SharedHandle<RequestGroup> group =
     e->getRequestGroupMan()->findReservedGroup(gid);
   if(!group || !group->isPauseRequested()) {
-    throw DL_ABORT_EX(fmt("GID#%lld cannot be unpaused now", gid));
+    throw DL_ABORT_EX(fmt("GID#%" PRId64 " cannot be unpaused now", gid));
   } else {
     group->setPauseRequested(false);
     e->getRequestGroupMan()->requestQueueCheck();    
@@ -923,7 +923,7 @@ SharedHandle<ValueBase> GetFilesRpcMethod::process
     SharedHandle<DownloadResult> dr =
       e->getRequestGroupMan()->findDownloadResult(gid);
     if(!dr) {
-      throw DL_ABORT_EX(fmt("No file data is available for GID#%lld", gid));
+      throw DL_ABORT_EX(fmt("No file data is available for GID#%" PRId64 "", gid));
     } else {
       createFileEntry(files, dr->fileEntries.begin(), dr->fileEntries.end(),
                       dr->totalLength, dr->pieceLength, dr->bitfield);
@@ -950,7 +950,7 @@ SharedHandle<ValueBase> GetUrisRpcMethod::process
   SharedHandle<RequestGroup> group =
     findRequestGroup(e->getRequestGroupMan(), gid);
   if(!group) {
-    throw DL_ABORT_EX(fmt("No URI data is available for GID#%lld", gid));
+    throw DL_ABORT_EX(fmt("No URI data is available for GID#%" PRId64 "", gid));
   }
   SharedHandle<List> uriList = List::g();
   // TODO Current implementation just returns first FileEntry's URIs.
@@ -970,7 +970,7 @@ SharedHandle<ValueBase> GetPeersRpcMethod::process
   SharedHandle<RequestGroup> group =
     findRequestGroup(e->getRequestGroupMan(), gid);
   if(!group) {
-    throw DL_ABORT_EX(fmt("No peer data is available for GID#%lld", gid));
+    throw DL_ABORT_EX(fmt("No peer data is available for GID#%" PRId64 "", gid));
   }
   SharedHandle<List> peers = List::g();
   const SharedHandle<BtObject>& btObject =
@@ -1003,7 +1003,7 @@ SharedHandle<ValueBase> TellStatusRpcMethod::process
       SharedHandle<DownloadResult> ds =
         e->getRequestGroupMan()->findDownloadResult(gid);
       if(!ds) {
-        throw DL_ABORT_EX(fmt("No such download for GID#%lld", gid));
+        throw DL_ABORT_EX(fmt("No such download for GID#%" PRId64 "", gid));
       }
       gatherStoppedDownload(entryDict, ds, keys);
     } else {
@@ -1097,7 +1097,7 @@ SharedHandle<ValueBase> RemoveDownloadResultRpcMethod::process
 
   a2_gid_t gid = str2Gid(gidParam);
   if(!e->getRequestGroupMan()->removeDownloadResult(gid)) {
-    throw DL_ABORT_EX(fmt("Could not remove download result of GID#%lld", gid));
+    throw DL_ABORT_EX(fmt("Could not remove download result of GID#%" PRId64 "", gid));
   }
   return VLB_OK;
 }
@@ -1200,7 +1200,7 @@ SharedHandle<ValueBase> ChangeOptionRpcMethod::process
       gatherChangeableOptionForReserved(&option, optsParam);
       changeOption(group, option, e);
     } else {
-      throw DL_ABORT_EX(fmt("Cannot change option for GID#%lld", gid));
+      throw DL_ABORT_EX(fmt("Cannot change option for GID#%" PRId64 "", gid));
     }
   }
   return VLB_OK;
@@ -1289,7 +1289,7 @@ SharedHandle<ValueBase> GetOptionRpcMethod::process
   SharedHandle<RequestGroup> group =
     findRequestGroup(e->getRequestGroupMan(), gid);
   if(!group) {
-    throw DL_ABORT_EX(fmt("Cannot get option for GID#%lld", gid));
+    throw DL_ABORT_EX(fmt("Cannot get option for GID#%" PRId64 "", gid));
   }
   SharedHandle<Dict> result = Dict::g();
   SharedHandle<Option> option = group->getOption();
@@ -1357,7 +1357,7 @@ SharedHandle<ValueBase> GetServersRpcMethod::process
   SharedHandle<RequestGroup> group =
     e->getRequestGroupMan()->findRequestGroup(gid);
   if(!group) {
-    throw DL_ABORT_EX(fmt("No active download for GID#%lld", gid));
+    throw DL_ABORT_EX(fmt("No active download for GID#%" PRId64 "", gid));
   }
   const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
   const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries();
@@ -1404,7 +1404,7 @@ SharedHandle<ValueBase> ChangeUriRpcMethod::process
   SharedHandle<RequestGroup> group =
     findRequestGroup(e->getRequestGroupMan(), gid);
   if(!group) {
-    throw DL_ABORT_EX(fmt("Cannot remove URIs from GID#%lld", gid));
+    throw DL_ABORT_EX(fmt("Cannot remove URIs from GID#%" PRId64 "", gid));
   }
   const SharedHandle<DownloadContext>& dctx = group->getDownloadContext();
   const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries();

+ 4 - 4
src/SegmentMan.cc

@@ -120,7 +120,7 @@ SharedHandle<Segment> SegmentMan::checkoutSegment
   if(!piece) {
     return SharedHandle<Segment>();
   }
-  A2_LOG_DEBUG(fmt("Attach segment#%lu to CUID#%lld.",
+  A2_LOG_DEBUG(fmt("Attach segment#%lu to CUID#%" PRId64 ".",
                    static_cast<unsigned long>(piece->getIndex()),
                    cuid));
   piece->setUsedBySegment(true);
@@ -468,10 +468,10 @@ size_t SegmentMan::countFreePieceFrom(size_t index) const
 
 void SegmentMan::ignoreSegmentFor(const SharedHandle<FileEntry>& fileEntry)
 {
-  A2_LOG_DEBUG(fmt("ignoring segment for path=%s, offset=%lld, length=%lld",
+  A2_LOG_DEBUG(fmt("ignoring segment for path=%s, offset=%" PRId64 ", length=%" PRId64 "",
                    fileEntry->getPath().c_str(),
-                   static_cast<long long int>(fileEntry->getOffset()),
-                   static_cast<long long int>(fileEntry->getLength())));
+                   static_cast<int64_t>(fileEntry->getOffset()),
+                   static_cast<int64_t>(fileEntry->getLength())));
   ignoreBitfield_.addFilter(fileEntry->getOffset(), fileEntry->getLength());
 }
 

+ 2 - 2
src/TrackerWatcherCommand.cc

@@ -175,7 +175,7 @@ void TrackerWatcherCommand::processTrackerResponse
     command->setPeerStorage(peerStorage_);
     command->setPieceStorage(pieceStorage_);
     e_->addCommand(command);
-    A2_LOG_DEBUG(fmt("CUID#%lld - Adding new command CUID#%lld",
+    A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Adding new command CUID#%" PRId64 "",
                      getCuid(), peer->usedBy()));
   }
 }
@@ -246,7 +246,7 @@ TrackerWatcherCommand::createRequestGroup(const std::string& uri)
   rg->setFileAllocationEnabled(false);
   rg->setPreLocalFileCheckEnabled(false);
   util::removeMetalinkContentTypes(rg);
-  A2_LOG_INFO(fmt("Creating tracker request group GID#%lld", rg->getGID()));
+  A2_LOG_INFO(fmt("Creating tracker request group GID#%" PRId64 "", rg->getGID()));
   return rg;
 }
 

+ 1 - 1
src/WatchProcessCommand.cc

@@ -118,7 +118,7 @@ void WatchProcessCommand::process()
 #endif
   if(!waiting) {
     A2_LOG_INFO
-      (fmt("CUID#%lld - Process %u is not running. Commencing shutdown.",
+      (fmt("CUID#%" PRId64 " - Process %u is not running. Commencing shutdown.",
            getCuid(), pid_));
     if(forceHalt_) {
       getDownloadEngine()->requestForceHalt();

+ 2 - 2
src/WebSocketInteractionCommand.cc

@@ -91,9 +91,9 @@ bool WebSocketInteractionCommand::execute()
   }
   if(wsSession_->onReadEvent() == -1 || wsSession_->onWriteEvent() == -1) {
     if(wsSession_->closeSent() || wsSession_->closeReceived()) {
-      A2_LOG_INFO(fmt("CUID#%lld - WebSocket session terminated.", getCuid()));
+      A2_LOG_INFO(fmt("CUID#%" PRId64 " - WebSocket session terminated.", getCuid()));
     } else {
-      A2_LOG_INFO(fmt("CUID#%lld - WebSocket session terminated"
+      A2_LOG_INFO(fmt("CUID#%" PRId64 " - WebSocket session terminated"
                       " (Possibly due to EOF).", getCuid()));
     }
     return true;

+ 2 - 4
src/bittorrent_helper.cc

@@ -250,8 +250,7 @@ void extractFileEntries
       }
       length += fileLengthData->i();
       if(length > std::numeric_limits<off_t>::max()) {
-        throw DOWNLOAD_FAILURE_EXCEPTION
-          (fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(length)));
+        throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, length));
       }
       std::string pathKey;
       if(fileDict->containsKey(C_PATH_UTF8)) {
@@ -310,8 +309,7 @@ void extractFileEntries
     }
     int64_t totalLength = lengthData->i();
     if(totalLength > std::numeric_limits<off_t>::max()) {
-      throw DOWNLOAD_FAILURE_EXCEPTION
-        (fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(totalLength)));
+      throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, totalLength));
     }
     // For each uri in urlList, if it ends with '/', then
     // concatenate name to it. Specification just says so.

+ 3 - 0
src/common.h

@@ -75,5 +75,8 @@
 #define __STDC_LIMIT_MACROS
 // included here for compatibility issues with old compiler/libraries.
 #include <stdint.h>
+// For PRId64
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
 
 #endif // D_COMMON_H

+ 52 - 52
src/message.h

@@ -38,70 +38,70 @@
 #include "common.h"
 
 #define MSG_SEGMENT_DOWNLOAD_COMPLETED                                  \
-  "CUID#%lld - The download for one segment completed successfully."
-#define MSG_NO_SEGMENT_AVAILABLE "CUID#%lld - No segment available."
-#define MSG_CONNECTING_TO_SERVER "CUID#%lld - Connecting to %s:%d"
-#define MSG_REDIRECT "CUID#%lld - Redirecting to %s"
-#define MSG_SENDING_REQUEST "CUID#%lld - Requesting:\n%s"
-#define MSG_RECEIVE_RESPONSE "CUID#%lld - Response received:\n%s"
-#define MSG_DOWNLOAD_ABORTED "CUID#%lld - Download aborted. URI=%s"
-#define MSG_RESTARTING_DOWNLOAD "CUID#%lld - Restarting the download. URI=%s"
-#define MSG_TORRENT_DOWNLOAD_ABORTED "CUID#%lld - Download aborted."
+  "CUID#%" PRId64 " - The download for one segment completed successfully."
+#define MSG_NO_SEGMENT_AVAILABLE "CUID#%" PRId64 " - No segment available."
+#define MSG_CONNECTING_TO_SERVER "CUID#%" PRId64 " - Connecting to %s:%d"
+#define MSG_REDIRECT "CUID#%" PRId64 " - Redirecting to %s"
+#define MSG_SENDING_REQUEST "CUID#%" PRId64 " - Requesting:\n%s"
+#define MSG_RECEIVE_RESPONSE "CUID#%" PRId64 " - Response received:\n%s"
+#define MSG_DOWNLOAD_ABORTED "CUID#%" PRId64 " - Download aborted. URI=%s"
+#define MSG_RESTARTING_DOWNLOAD "CUID#%" PRId64 " - Restarting the download. URI=%s"
+#define MSG_TORRENT_DOWNLOAD_ABORTED "CUID#%" PRId64 " - Download aborted."
 #define MSG_MAX_TRY                                                     \
-  "CUID#%lld - %d times attempted, but no success. Download aborted."
-#define MSG_SEND_PEER_MESSAGE "CUID#%lld - To: %s:%d %s"
-#define MSG_RECEIVE_PEER_MESSAGE "CUID#%lld - From: %s:%d %s"
-#define MSG_GOT_NEW_PIECE "CUID#%lld - we got new piece. index=%lu"
-#define MSG_GOT_WRONG_PIECE "CUID#%lld - we got wrong piece. index=%lu"
-#define MSG_DOWNLOAD_NOT_COMPLETE "CUID#%lld - Download not complete: %s"
-#define MSG_DOWNLOAD_ALREADY_COMPLETED _("GID#%lld - Download has already completed: %s")
-#define MSG_RESOLVING_HOSTNAME "CUID#%lld - Resolving hostname %s"
+  "CUID#%" PRId64 " - %d times attempted, but no success. Download aborted."
+#define MSG_SEND_PEER_MESSAGE "CUID#%" PRId64 " - To: %s:%d %s"
+#define MSG_RECEIVE_PEER_MESSAGE "CUID#%" PRId64 " - From: %s:%d %s"
+#define MSG_GOT_NEW_PIECE "CUID#%" PRId64 " - we got new piece. index=%lu"
+#define MSG_GOT_WRONG_PIECE "CUID#%" PRId64 " - we got wrong piece. index=%lu"
+#define MSG_DOWNLOAD_NOT_COMPLETE "CUID#%" PRId64 " - Download not complete: %s"
+#define MSG_DOWNLOAD_ALREADY_COMPLETED _("GID#%" PRId64 " - Download has already completed: %s")
+#define MSG_RESOLVING_HOSTNAME "CUID#%" PRId64 " - Resolving hostname %s"
 #define MSG_NAME_RESOLUTION_COMPLETE                    \
-  "CUID#%lld - Name resolution complete: %s -> %s"
+  "CUID#%" PRId64 " - Name resolution complete: %s -> %s"
 #define MSG_NAME_RESOLUTION_FAILED                      \
-  "CUID#%lld - Name resolution for %s failed:%s"
-#define MSG_DNS_CACHE_HIT "CUID#%lld - DNS cache hit: %s -> %s"
-#define MSG_CONNECTING_TO_PEER "CUID#%lld - Connecting to the peer %s"
+  "CUID#%" PRId64 " - Name resolution for %s failed:%s"
+#define MSG_DNS_CACHE_HIT "CUID#%" PRId64 " - DNS cache hit: %s -> %s"
+#define MSG_CONNECTING_TO_PEER "CUID#%" PRId64 " - Connecting to the peer %s"
 #define MSG_PIECE_RECEIVED                                              \
-  "CUID#%lld - Piece received. index=%lu, begin=%d, length=%d, offset=%lld," \
+  "CUID#%" PRId64 " - Piece received. index=%lu, begin=%d, length=%d, offset=%" PRId64 "," \
   " blockIndex=%lu"
-#define MSG_PIECE_BITFIELD "CUID#%lld - Piece bitfield %s"
+#define MSG_PIECE_BITFIELD "CUID#%" PRId64 " - Piece bitfield %s"
 #define MSG_REJECT_PIECE_CHOKED                                         \
-  "CUID#%lld - Reject piece message in queue because the peer has been" \
+  "CUID#%" PRId64 " - Reject piece message in queue because the peer has been" \
   " choked. index=%lu, begin=%d, length=%d"
 #define MSG_REJECT_PIECE_CANCEL                                         \
-  "CUID#%lld - Reject piece message in queue because cancel message received." \
+  "CUID#%" PRId64 " - Reject piece message in queue because cancel message received." \
   " index=%lu, begin=%d, length=%d"
 #define MSG_FILE_VALIDATION_FAILURE                             \
-  "CUID#%lld - Exception caught while validating file integrity."
-#define MSG_PEER_INTERESTED "CUID#%lld - Interested in the peer"
-#define MSG_PEER_NOT_INTERESTED "CUID#%lld - Not interested in the peer"
-#define MSG_DELETING_REQUEST_SLOT "CUID#%lld - Deleting request slot" \
+  "CUID#%" PRId64 " - Exception caught while validating file integrity."
+#define MSG_PEER_INTERESTED "CUID#%" PRId64 " - Interested in the peer"
+#define MSG_PEER_NOT_INTERESTED "CUID#%" PRId64 " - Not interested in the peer"
+#define MSG_DELETING_REQUEST_SLOT "CUID#%" PRId64 " - Deleting request slot" \
   " index=%lu, begin=%d, blockIndex=%lu"
-#define MSG_DELETING_REQUEST_SLOT_CHOKED "CUID#%lld - Deleting request slot" \
+#define MSG_DELETING_REQUEST_SLOT_CHOKED "CUID#%" PRId64 " - Deleting request slot" \
   " index=%lu, begin=%d, blockIndex=%lu because localhost got choked."
-#define MSG_DELETING_REQUEST_SLOT_TIMEOUT "CUID#%lld - Deleting request slot" \
+#define MSG_DELETING_REQUEST_SLOT_TIMEOUT "CUID#%" PRId64 " - Deleting request slot" \
   " index=%lu, begin=%d, blockIndex=%lu because of time out"
-#define MSG_DELETING_REQUEST_SLOT_ACQUIRED "CUID#%lld - Deleting request slot" \
+#define MSG_DELETING_REQUEST_SLOT_ACQUIRED "CUID#%" PRId64 " - Deleting request slot" \
   " index=%lu, begin=%d, blockIndex=%lu because the block has been acquired."
-#define MSG_FAST_EXTENSION_ENABLED "CUID#%lld - Fast extension enabled."
-#define MSG_EXTENDED_MESSAGING_ENABLED "CUID#%lld - Extended Messaging enabled."
+#define MSG_FAST_EXTENSION_ENABLED "CUID#%" PRId64 " - Fast extension enabled."
+#define MSG_EXTENDED_MESSAGING_ENABLED "CUID#%" PRId64 " - Extended Messaging enabled."
 #define MSG_FILE_ALLOCATION_FAILURE                             \
-  "CUID#%lld - Exception caught while allocating file space."
+  "CUID#%" PRId64 " - Exception caught while allocating file space."
 #define MSG_CONTENT_DISPOSITION_DETECTED                        \
-  "CUID#%lld - Content-Disposition detected. Use %s as filename"
-#define MSG_PEER_BANNED "CUID#%lld - Peer %s:%d banned."
+  "CUID#%" PRId64 " - Content-Disposition detected. Use %s as filename"
+#define MSG_PEER_BANNED "CUID#%" PRId64 " - Peer %s:%d banned."
 #define MSG_LISTENING_PORT                                      \
-  "CUID#%lld - Using port %d for accepting new connections"
-#define MSG_BIND_FAILURE "CUID#%lld - An error occurred while binding port=%d"
+  "CUID#%" PRId64 " - Using port %d for accepting new connections"
+#define MSG_BIND_FAILURE "CUID#%" PRId64 " - An error occurred while binding port=%d"
 #define MSG_INCOMING_PEER_CONNECTION                            \
-  "CUID#%lld - Incoming connection, adding new command CUID#%lld"
-#define MSG_ACCEPT_FAILURE "CUID#%lld - Error in accepting connection"
+  "CUID#%" PRId64 " - Incoming connection, adding new command CUID#%" PRId64 ""
+#define MSG_ACCEPT_FAILURE "CUID#%" PRId64 " - Error in accepting connection"
 #define MSG_TRACKER_RESPONSE_PROCESSING_FAILED                  \
-  "CUID#%lld - Error occurred while processing tracker response."
-#define MSG_DHT_ENABLED_PEER "CUID#%lld - The peer is DHT-enabled."
+  "CUID#%" PRId64 " - Error occurred while processing tracker response."
+#define MSG_DHT_ENABLED_PEER "CUID#%" PRId64 " - The peer is DHT-enabled."
 #define MSG_CONNECT_FAILED_AND_RETRY            \
-  "CUID#%lld - Could not to connect to %s:%u. Trying another address"
+  "CUID#%" PRId64 " - Could not to connect to %s:%u. Trying another address"
 
 #define MSG_UNRECOGNIZED_URI _("Unrecognized URI or unsupported protocol: %s")
 #define MSG_TRACKER_WARNING_MESSAGE _("Tracker returned warning message: %s")
@@ -125,9 +125,9 @@
 #define MSG_DOWNLOAD_COMPLETED _("The download was complete.")
 #define MSG_REMOVED_HAVE_ENTRY _("Removed %lu have entries.")
 #define MSG_VALIDATING_FILE _("Validating file %s")
-#define MSG_ALLOCATION_COMPLETED "%ld seconds to allocate %lld byte(s)"
+#define MSG_ALLOCATION_COMPLETED "%ld seconds to allocate %" PRId64 " byte(s)"
 #define MSG_FILE_ALLOCATION_DISPATCH                    \
-  "Dispatching FileAllocationCommand for CUID#%lld."
+  "Dispatching FileAllocationCommand for CUID#%" PRId64 "."
 #define MSG_METALINK_QUEUEING _("Metalink: Queueing %s for download.")
 #define MSG_FILE_DOWNLOAD_COMPLETED _("Download complete: %s")
 #define MSG_SEEDING_END _("Seeding is over.")
@@ -195,7 +195,7 @@
 #define MSG_DIR_TRAVERSAL_DETECTED _("Detected directory traversal directive in %s")
 #define MSG_HASH_CHECK_NOT_DONE                                         \
   "File has already been downloaded but hash check has not been done yet."
-#define MSG_REMOVING_UNSELECTED_FILE _("GID#%lld - Removing unselected file.")
+#define MSG_REMOVING_UNSELECTED_FILE _("GID#%" PRId64 " - Removing unselected file.")
 #define MSG_FILE_REMOVED _("File %s removed.")
 #define MSG_FILE_COULD_NOT_REMOVED _("File %s could not be removed.")
 
@@ -210,14 +210,14 @@
 #define EX_CONNECTION_FAILED _("Connection failed.")
 #define EX_FILENAME_MISMATCH _("The requested filename and the previously registered one are not same. Expected:%s Actual:%s")
 #define EX_BAD_STATUS _("The response status is not successful. status=%d")
-#define EX_TOO_LARGE_FILE "Too large file size. size=%lld"
+#define EX_TOO_LARGE_FILE "Too large file size. size=%" PRId64 ""
 #define EX_TRANSFER_ENCODING_NOT_SUPPORTED _("Transfer encoding %s is not supported.")
 #define EX_SSL_INIT_FAILURE _("SSL initialization failed: %s")
 #define EX_SSL_IO_ERROR _("SSL I/O error")
 #define EX_SSL_PROTOCOL_ERROR _("SSL protocol error")
 #define EX_SSL_UNKNOWN_ERROR _("SSL unknown error %d")
 #define EX_SSL_CONNECT_ERROR _("SSL initialization failed: OpenSSL connect error %d")
-#define EX_SIZE_MISMATCH "Size mismatch Expected:%lld Actual:%lld"
+#define EX_SIZE_MISMATCH "Size mismatch Expected:%" PRId64 " Actual:%" PRId64 ""
 #define EX_AUTH_FAILED _("Authorization failed.")
 #define EX_GOT_EOF _("Got EOF from the server.")
 #define EX_EOF_FROM_PEER _("Got EOF from peer.")
@@ -229,7 +229,7 @@
 #define EX_DATA_READ _("Failed to read data from disk.")
 #define EX_FILE_SHA1SUM _("Failed to calculate SHA1 digest of or a part of the file %s, cause: %s")
 #define EX_FILE_SEEK _("Failed to seek the file %s, cause: %s")
-#define EX_FILE_OFFSET_OUT_OF_RANGE "The offset is out of range, offset=%lld"
+#define EX_FILE_OFFSET_OUT_OF_RANGE "The offset is out of range, offset=%" PRId64 ""
 #define EX_NOT_DIRECTORY _("%s is not a directory.")
 #define EX_MAKE_DIR _("Failed to make the directory %s, cause: %s")
 #define EX_SEGMENT_FILE_WRITE "Failed to write into the segment file %s"
@@ -256,7 +256,7 @@
 #define EX_INVALID_PAYLOAD_SIZE                                 \
   _("Invalid payload size for %s, size=%lu. It should be %lu.")
 #define EX_INVALID_BT_MESSAGE_ID _("Invalid ID=%d for %s. It should be %d.")
-#define EX_INVALID_CHUNK_CHECKSUM "Chunk checksum validation failed. checksumIndex=%lu, offset=%lld, expectedHash=%s, actualHash=%s"
+#define EX_INVALID_CHUNK_CHECKSUM "Chunk checksum validation failed. checksumIndex=%lu, offset=%" PRId64 ", expectedHash=%s, actualHash=%s"
 #define EX_DOWNLOAD_ABORTED _("Download aborted.")
 #define EX_DUPLICATE_FILE_DOWNLOAD _("File %s is being downloaded by other command.")
 #define EX_INSUFFICIENT_CHECKSUM _("Insufficient checksums.")
@@ -270,7 +270,7 @@
 #define EX_TOO_SLOW_DOWNLOAD_SPEED _("Too slow Downloading speed: %d <= %d(B/s), host:%s")
 #define EX_NO_HTTP_REQUEST_ENTRY_FOUND _("No HttpRequestEntry found.")
 #define EX_LOCATION_HEADER_REQUIRED _("Got %d status, but no location header provided.")
-#define EX_INVALID_RANGE_HEADER "Invalid range header. Request: %lld-%lld/%lld, Response: %lld-%lld/%lld"
+#define EX_INVALID_RANGE_HEADER "Invalid range header. Request: %" PRId64 "-%" PRId64 "/%" PRId64 ", Response: %" PRId64 "-%" PRId64 "/%" PRId64 ""
 #define EX_NO_RESULT_WITH_YOUR_PREFS _("No file matched with your preference.")
 #define EX_EXCEPTION_CAUGHT _("Exception caught")
 #define EX_TOO_LONG_PAYLOAD _("Max payload length exceeded or invalid. length = %u")

+ 1 - 1
src/util.cc

@@ -537,7 +537,7 @@ std::string secfmt(time_t sec) {
   time_t tsec = sec;
   std::string str;
   if(sec >= 3600) {
-    str = fmt("%lldh", static_cast<long long int>(sec/3600));
+    str = fmt("%" PRId64 "h", static_cast<int64_t>(sec/3600));
     sec %= 3600;
   }
   if(sec >= 60) {