wrap stdlib calls into cpp namespace

Wrap the stdlib calls into the cpp namespace.

Change-Id: I7ae16d0d18312f3d4118b1d5345df07e28773484
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/cable.cpp b/cable.cpp
index 0bbdcf8..a9e6da2 100644
--- a/cable.cpp
+++ b/cable.cpp
@@ -19,6 +19,7 @@
 #include "main.hpp"
 
 #include <cstdint>
+#include <cstring>
 #include <experimental/filesystem>
 #include <fstream>
 #include <sstream>
@@ -56,8 +57,8 @@
     // This command is expecting: [0x00][len][if_name]
     if ((*dataLen) < sizeof(struct CableRequest) + sizeof(uint8_t))
     {
-        fprintf(stderr, "Invalid command length: %u\n",
-                static_cast<uint32_t>(*dataLen));
+        std::fprintf(stderr, "Invalid command length: %u\n",
+                     static_cast<uint32_t>(*dataLen));
         return IPMI_CC_INVALID;
     }
 
@@ -67,15 +68,16 @@
     // Sanity check the object contents.
     if (request->if_name_len == 0)
     {
-        fprintf(stderr, "Invalid string length: %d\n", request->if_name_len);
+        std::fprintf(stderr, "Invalid string length: %d\n",
+                     request->if_name_len);
         return IPMI_CC_INVALID;
     }
 
     // Verify the request buffer contains the object and the string.
     if ((*dataLen) < (sizeof(struct CableRequest) + request->if_name_len))
     {
-        fprintf(stderr, "*dataLen too small: %u\n",
-                static_cast<uint32_t>(*dataLen));
+        std::fprintf(stderr, "*dataLen too small: %u\n",
+                     static_cast<uint32_t>(*dataLen));
         return IPMI_CC_INVALID;
     }
 
@@ -84,7 +86,7 @@
     std::ostringstream opath;
 
     // Copy the string out of the request buffer.
-    memcpy(&nameBuf[0], request->if_name, request->if_name_len);
+    std::memcpy(&nameBuf[0], request->if_name, request->if_name_len);
     std::string name = nameBuf;
 
     // Minor sanity & security check (of course, I'm less certain if unicode
@@ -93,7 +95,7 @@
     // Basically you can't easily inject ../ or /../ into the path below.
     if (name.find("/") != std::string::npos)
     {
-        fprintf(stderr, "Invalid or illegal name: '%s'\n", nameBuf);
+        std::fprintf(stderr, "Invalid or illegal name: '%s'\n", nameBuf);
         return IPMI_CC_INVALID;
     }
 
@@ -103,7 +105,7 @@
     std::error_code ec;
     if (!fs::exists(path, ec))
     {
-        fprintf(stderr, "Path: '%s' doesn't exist.\n", path.c_str());
+        std::fprintf(stderr, "Path: '%s' doesn't exist.\n", path.c_str());
         return IPMI_CC_INVALID;
     }
     // We're uninterested in the state of ec.
@@ -130,7 +132,7 @@
     reply.value = (count > 0) ? 1 : 0;
 
     // Return the subcommand and the result.
-    memcpy(&replyBuf[0], &reply, sizeof(struct CableReply));
+    std::memcpy(&replyBuf[0], &reply, sizeof(struct CableReply));
     (*dataLen) = sizeof(struct CableReply);
 
     return IPMI_CC_OK;
diff --git a/cpld.cpp b/cpld.cpp
index 5345a74..8748e78 100644
--- a/cpld.cpp
+++ b/cpld.cpp
@@ -18,6 +18,7 @@
 
 #include "main.hpp"
 
+#include <cstring>
 #include <experimental/filesystem>
 #include <fstream>
 #include <sstream>
@@ -51,8 +52,8 @@
 {
     if ((*dataLen) < sizeof(struct CpldRequest))
     {
-        fprintf(stderr, "Invalid command length: %u\n",
-                static_cast<uint32_t>(*dataLen));
+        std::fprintf(stderr, "Invalid command length: %u\n",
+                     static_cast<uint32_t>(*dataLen));
         return IPMI_CC_INVALID;
     }
 
@@ -75,7 +76,8 @@
     std::error_code ec;
     if (!fs::exists(opath.str(), ec))
     {
-        fprintf(stderr, "Path: '%s' doesn't exist.\n", opath.str().c_str());
+        std::fprintf(stderr, "Path: '%s' doesn't exist.\n",
+                     opath.str().c_str());
         return IPMI_CC_INVALID;
     }
     // We're uninterested in the state of ec.
@@ -104,7 +106,7 @@
         sscanf(value.c_str(), "%d.%d.%d.%d", &major, &minor, &point, &subpoint);
     if (num_fields == 0)
     {
-        fprintf(stderr, "Invalid version.\n");
+        std::fprintf(stderr, "Invalid version.\n");
         return IPMI_CC_INVALID;
     }
 
@@ -116,7 +118,7 @@
     reply.point = static_cast<uint8_t>(point);
     reply.subpoint = static_cast<uint8_t>(subpoint);
 
-    memcpy(&replyBuf[0], &reply, sizeof(struct CpldReply));
+    std::memcpy(&replyBuf[0], &reply, sizeof(struct CpldReply));
     (*dataLen) = sizeof(struct CpldReply);
 
     return IPMI_CC_OK;
diff --git a/eth.cpp b/eth.cpp
index ba46f73..2689fab 100644
--- a/eth.cpp
+++ b/eth.cpp
@@ -19,6 +19,7 @@
 #include "main.hpp"
 
 #include <cstdint>
+#include <cstring>
 #include <string>
 
 namespace google
@@ -70,21 +71,21 @@
 {
     if ((*dataLen) < sizeof(struct EthDeviceRequest))
     {
-        fprintf(stderr, "Invalid command length: %u\n",
-                static_cast<uint32_t>(*dataLen));
+        std::fprintf(stderr, "Invalid command length: %u\n",
+                     static_cast<uint32_t>(*dataLen));
         return IPMI_CC_INVALID;
     }
 
     std::string device = NCSI_IF_NAME_STR;
     if (device.length() == 0)
     {
-        fprintf(stderr, "Invalid eth string\n");
+        std::fprintf(stderr, "Invalid eth string\n");
         return IPMI_CC_INVALID;
     }
 
     if ((sizeof(struct EthDeviceReply) + device.length()) > MAX_IPMI_BUFFER)
     {
-        fprintf(stderr, "Response would overflow response buffer\n");
+        std::fprintf(stderr, "Response would overflow response buffer\n");
         return IPMI_CC_INVALID;
     }
 
@@ -93,7 +94,7 @@
     reply->subcommand = SysGetEthDevice;
     reply->channel = NCSI_IPMI_CHANNEL;
     reply->if_name_len = device.length();
-    memcpy(reply->if_name, device.c_str(), device.length());
+    std::memcpy(reply->if_name, device.c_str(), device.length());
 
     (*dataLen) = sizeof(struct EthDeviceReply) + device.length();
 
diff --git a/main.cpp b/main.cpp
index 4b8bc61..9575a1a 100644
--- a/main.cpp
+++ b/main.cpp
@@ -51,8 +51,8 @@
     // Verify it's at least as long as it needs to be for a subcommand.
     if ((*dataLen) < 1)
     {
-        fprintf(stderr, "*dataLen too small: %u\n",
-                static_cast<uint32_t>(*dataLen));
+        std::fprintf(stderr, "*dataLen too small: %u\n",
+                     static_cast<uint32_t>(*dataLen));
         return IPMI_CC_INVALID;
     }
 
@@ -67,7 +67,7 @@
         case SysPsuHardReset:
             return PsuHardReset(reqBuf, replyCmdBuf, dataLen);
         default:
-            fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]);
+            std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]);
             return IPMI_CC_INVALID;
     }
 }
@@ -78,8 +78,9 @@
 {
     oem::Router* oemRouter = oem::mutableRouter();
 
-    fprintf(stderr, "Registering OEM:[%#08X], Cmd:[%#04X] for Sys Commands\n",
-            oem::googOemNumber, oem::google::sysCmd);
+    std::fprintf(stderr,
+                 "Registering OEM:[%#08X], Cmd:[%#04X] for Sys Commands\n",
+                 oem::googOemNumber, oem::google::sysCmd);
 
     oemRouter->registerHandler(oem::googOemNumber, oem::google::sysCmd,
                                HandleSysCommand);
diff --git a/psu.cpp b/psu.cpp
index addf0d1..46e097a 100644
--- a/psu.cpp
+++ b/psu.cpp
@@ -19,6 +19,7 @@
 #include "main.hpp"
 
 #include <cstdint>
+#include <cstring>
 #include <fstream>
 #include <phosphor-logging/log.hpp>
 #include <sdbusplus/bus.hpp>
@@ -48,26 +49,26 @@
 {
     if ((*dataLen) < sizeof(struct PsuResetRequest))
     {
-        fprintf(stderr, "Invalid command length: %u\n",
-                static_cast<uint32_t>(*dataLen));
+        std::fprintf(stderr, "Invalid command length: %u\n",
+                     static_cast<uint32_t>(*dataLen));
         return IPMI_CC_INVALID;
     }
 
     struct PsuResetRequest request;
-    memcpy(&request, &reqBuf[0], sizeof(struct PsuResetRequest));
+    std::memcpy(&request, &reqBuf[0], sizeof(struct PsuResetRequest));
 
     std::ofstream ofs;
     ofs.open(TIME_DELAY_FILENAME, std::ofstream::out);
     if (!ofs.good())
     {
-        fprintf(stderr, "Unable to open file for output.\n");
+        std::fprintf(stderr, "Unable to open file for output.\n");
         return IPMI_CC_INVALID;
     }
 
     ofs << "PSU_HARDRESET_DELAY=" << request.delay << std::endl;
     if (ofs.fail())
     {
-        fprintf(stderr, "Write failed\n");
+        std::fprintf(stderr, "Write failed\n");
         ofs.close();
         return IPMI_CC_INVALID;
     }