Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[windows][melodic] use c++11 std::snprintf #1820

Merged
merged 1 commit into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions clients/roscpp/src/libros/file_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@

#include <boost/filesystem.hpp>

#ifdef _MSC_VER
#ifdef snprintf
#undef snprintf
#endif
#define snprintf _snprintf_s
#endif


namespace fs = boost::filesystem;

namespace ros
Expand Down Expand Up @@ -112,7 +104,7 @@ void init(const M_string& remappings)
}

char pid_str[100];
snprintf(pid_str, sizeof(pid_str), "%d", pid);
std::snprintf(pid_str, sizeof(pid_str), "%d", pid);
log_file_name += std::string("_") + std::string(pid_str) + std::string(".log");
}

Expand Down
4 changes: 2 additions & 2 deletions clients/roscpp/src/libros/service_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ bool ServiceManager::advertiseService(const AdvertiseServiceOptions& ops)
args[0] = this_node::getName();
args[1] = ops.service;
char uri_buf[1024];
snprintf(uri_buf, sizeof(uri_buf), "rosrpc://%s:%d",
std::snprintf(uri_buf, sizeof(uri_buf), "rosrpc://%s:%d",
network::getHost().c_str(), connection_manager_->getTCPPort());
args[2] = string(uri_buf);
args[3] = xmlrpc_manager_->getServerURI();
Expand Down Expand Up @@ -196,7 +196,7 @@ bool ServiceManager::unregisterService(const std::string& service)
args[0] = this_node::getName();
args[1] = service;
char uri_buf[1024];
snprintf(uri_buf, sizeof(uri_buf), "rosrpc://%s:%d",
std::snprintf(uri_buf, sizeof(uri_buf), "rosrpc://%s:%d",
network::getHost().c_str(), connection_manager_->getTCPPort());
args[2] = string(uri_buf);

Expand Down
9 changes: 1 addition & 8 deletions clients/roscpp/src/libros/this_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
#include "ros/topic_manager.h"
#include "ros/init.h"

#ifdef _MSC_VER
#ifdef snprintf
#undef snprintf
#endif
#define snprintf _snprintf_s
#endif

namespace ros
{

Expand Down Expand Up @@ -172,7 +165,7 @@ void ThisNode::init(const std::string& name, const M_string& remappings, uint32_
if (options & init_options::AnonymousName && !disable_anon)
{
char buf[200];
snprintf(buf, sizeof(buf), "_%llu", (unsigned long long)WallTime::now().toNSec());
std::snprintf(buf, sizeof(buf), "_%llu", (unsigned long long)WallTime::now().toNSec());
name_ += buf;
}

Expand Down
2 changes: 0 additions & 2 deletions utilities/xmlrpcpp/include/xmlrpcpp/XmlRpcUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include "xmlrpcpp/XmlRpcDecl.h"

#if defined(_MSC_VER)
# define snprintf _snprintf_s
# define vsnprintf _vsnprintf_s
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
#elif defined(__BORLANDC__)
Expand Down
4 changes: 2 additions & 2 deletions utilities/xmlrpcpp/src/XmlRpcClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ XmlRpcClient::generateHeader(size_t length) const
header += _host;

char buff[40];
snprintf(buff,40,":%d\r\n", _port);
std::snprintf(buff,40,":%d\r\n", _port);

header += buff;
header += "Content-Type: text/xml\r\nContent-length: ";

snprintf(buff,40,"%zu\r\n\r\n", length);
std::snprintf(buff,40,"%zu\r\n\r\n", length);

return header + buff;
}
Expand Down
6 changes: 1 addition & 5 deletions utilities/xmlrpcpp/src/XmlRpcSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,7 @@ std::string
XmlRpcSocket::getErrorMsg(int error)
{
char err[60];
#ifdef _MSC_VER
strerror_s(err,60,error);
#else
snprintf(err,sizeof(err),"%s",strerror(error));
#endif
std::snprintf(err,sizeof(err),"%s",strerror(error));
return std::string(err);
}

Expand Down
4 changes: 2 additions & 2 deletions utilities/xmlrpcpp/src/XmlRpcUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void XmlRpcUtil::log(int level, const char* fmt, ...)
va_list va;
char buf[1024];
va_start( va, fmt);
vsnprintf(buf,sizeof(buf)-1,fmt,va);
std::vsnprintf(buf,sizeof(buf)-1,fmt,va);
va_end(va);
buf[sizeof(buf)-1] = 0;
XmlRpcLogHandler::getLogHandler()->log(level, buf);
Expand All @@ -97,7 +97,7 @@ void XmlRpcUtil::error(const char* fmt, ...)
va_list va;
va_start(va, fmt);
char buf[1024];
vsnprintf(buf,sizeof(buf)-1,fmt,va);
std::vsnprintf(buf,sizeof(buf)-1,fmt,va);
va_end(va);
buf[sizeof(buf)-1] = 0;
XmlRpcErrorHandler::getErrorHandler()->error(buf);
Expand Down
6 changes: 3 additions & 3 deletions utilities/xmlrpcpp/src/XmlRpcValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ namespace XmlRpc {
std::string XmlRpcValue::intToXml() const
{
char buf[256];
snprintf(buf, sizeof(buf)-1, "%d", _value.asInt);
std::snprintf(buf, sizeof(buf)-1, "%d", _value.asInt);
buf[sizeof(buf)-1] = 0;
std::string xml = VALUE_TAG;
xml += I4_TAG;
Expand Down Expand Up @@ -434,7 +434,7 @@ namespace XmlRpc {
{
struct tm* t = _value.asTime;
char buf[20];
snprintf(buf, sizeof(buf)-1, "%4d%02d%02dT%02d:%02d:%02d",
std::snprintf(buf, sizeof(buf)-1, "%4d%02d%02dT%02d:%02d:%02d",
t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
buf[sizeof(buf)-1] = 0;

Expand Down Expand Up @@ -610,7 +610,7 @@ namespace XmlRpc {
{
struct tm* t = _value.asTime;
char buf[20];
snprintf(buf, sizeof(buf)-1, "%4d%02d%02dT%02d:%02d:%02d",
std::snprintf(buf, sizeof(buf)-1, "%4d%02d%02dT%02d:%02d:%02d",
t->tm_year,t->tm_mon,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
buf[sizeof(buf)-1] = 0;
os << buf;
Expand Down
6 changes: 1 addition & 5 deletions utilities/xmlrpcpp/test/mock_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ std::string XmlRpcSocket::getErrorMsg() {
// NOTE(austin): this matches the default implementation.
std::string XmlRpcSocket::getErrorMsg(int error) {
char err[60];
#ifdef _MSC_VER
strerror_s(err, 60, error);
#else
snprintf(err, sizeof(err), "%s", strerror(error));
#endif
std::snprintf(err, sizeof(err), "%s", strerror(error));
return std::string(err);
}

Expand Down