Explorar o código

Removed some old string.h portability stuff and replaced it with CString.h which is easier portability, also made TUNInterface and NetPlatform fully non-portable since they are not intended to be portable and portability code changes from time to time, putting them at risk since they are not often compiled.

Caleb James DeLisle %!s(int64=10) %!d(string=hai) anos
pai
achega
3005cac83c
Modificáronse 63 ficheiros con 151 adicións e 578 borrados
  1. 7 11
      admin/Admin.c
  2. 1 2
      admin/AdminClient.c
  3. 3 7
      admin/AdminLog.c
  4. 0 1
      admin/AuthorizedPasswords.c
  5. 1 4
      admin/Configurator.c
  6. 0 1
      admin/angel/AngelInit.c
  7. 2 4
      admin/angel/Cjdns.c
  8. 15 16
      admin/angel/cjdroute2.c
  9. 0 1
      admin/test/Admin_test.c
  10. 5 9
      admin/testframework/AdminTestFramework.c
  11. 2 4
      benc/String.c
  12. 2 2
      benc/String.h
  13. 1 2
      benc/serialization/json/JsonBencSerializer.c
  14. 2 3
      benc/serialization/standard/StandardBencSerializer.c
  15. 3 4
      benc/serialization/standard/test/benc_serializeInteger_test.c
  16. 3 3
      benc/serialization/standard/test/benc_serializeList_test.c
  17. 3 5
      benc/serialization/standard/test/benc_serializeString_test.c
  18. 1 2
      contrib/c/privatetopublic.c
  19. 2 1
      contrib/c/publictoip6.c
  20. 0 1
      crypto/test/CryptoAuth_async_test.c
  21. 6 10
      crypto/test/CryptoAuth_test.c
  22. 4 7
      crypto/test/CryptoAuth_unit_test.c
  23. 2 2
      dht/DHTModuleRegistry.c
  24. 0 1
      dht/ReplyModule.c
  25. 0 1
      dht/SerializationModule.c
  26. 0 1
      dht/dhtcore/Janitor.c
  27. 0 3
      dht/dhtcore/NodeStore_admin.c
  28. 1 3
      dht/dhtcore/test/NodeStore_test_disabled.c
  29. 2 3
      exception/Except.c
  30. 6 6
      interface/ETHInterface_linux.c
  31. 6 6
      interface/test/FramingInterface_test.c
  32. 0 3
      interface/test/TUNInterface_ipv4_root_test.c
  33. 0 1
      interface/test/TUNInterface_ipv6_root_test.c
  34. 0 3
      interface/test/UDPInterface_communication_test.c
  35. 0 1
      interface/tuntap/TUNInterface_freebsd.c
  36. 1 5
      interface/tuntap/TUNInterface_linux.c
  37. 0 1
      interface/tuntap/TUNInterface_openbsd.c
  38. 8 8
      interface/tuntap/windows/TAPDevice.c
  39. 0 2
      memory/Allocator.c
  40. 0 1
      memory/test/Allocator_test.c
  41. 1 1
      test/cjdroute_routerPing_test.c
  42. 2 5
      test/threeNodes_test_disabled.c
  43. 0 1
      tunnel/IpTunnel.c
  44. 4 6
      tunnel/test/IpTunnel_test.c
  45. 0 1
      util/AverageRoller.c
  46. 10 0
      util/CString.c
  47. 7 0
      util/CString.h
  48. 2 4
      util/Seccomp.c
  49. 3 3
      util/Security.c
  50. 0 2
      util/Security_admin.c
  51. 4 4
      util/events/libuv/Pipe.c
  52. 6 8
      util/log/WriterLog.c
  53. 0 330
      util/platform/libc/string.h
  54. 0 25
      util/platform/libc/strlen.h
  55. 2 2
      util/platform/netdev/NetPlatform_darwin.c
  56. 1 2
      util/platform/netdev/NetPlatform_freebsd.c
  57. 7 12
      util/platform/netdev/NetPlatform_linux.c
  58. 3 4
      util/platform/netdev/NetPlatform_openbsd.c
  59. 4 5
      util/platform/netdev/NetPlatform_sunos.c
  60. 1 1
      util/platform/netdev/NetPlatform_win32.c
  61. 3 5
      util/platform/test/Sockaddr_test.c
  62. 0 4
      util/test/Hex_test.c
  63. 2 2
      util/test/Process_test.c

+ 7 - 11
admin/Admin.c

@@ -33,10 +33,6 @@
 #include "util/Identity.h"
 #include "util/platform/Sockaddr.h"
 
-#define string_strstr
-#define string_strcmp
-#define string_strlen
-#include "util/platform/libc/string.h"
 
 #include <crypto_hash_sha256.h>
 
@@ -247,7 +243,7 @@ static inline bool authValid(Dict* message, struct Message* messageBytes, struct
         return false;
     }
 
-    uint8_t* hashPtr = (uint8_t*) strstr((char*) messageBytes->bytes, submittedHash->bytes);
+    uint8_t* hashPtr = (uint8_t*) CString_strstr((char*) messageBytes->bytes, submittedHash->bytes);
 
     if (!hashPtr || !admin->password) {
         return false;
@@ -256,7 +252,7 @@ static inline bool authValid(Dict* message, struct Message* messageBytes, struct
     uint8_t passAndCookie[64];
     snprintf((char*) passAndCookie, 64, "%s%u", admin->password->bytes, cookie);
     uint8_t hash[32];
-    crypto_hash_sha256(hash, passAndCookie, strlen((char*) passAndCookie));
+    crypto_hash_sha256(hash, passAndCookie, CString_strlen((char*) passAndCookie));
     Hex_encode(hashPtr, 64, hash, 32);
 
     crypto_hash_sha256(hash, messageBytes->bytes, messageBytes->length);
@@ -358,7 +354,7 @@ static void handleRequest(Dict* messageDict,
         Dict* d = Dict_new(allocator);
         char bytes[32];
         snprintf(bytes, 32, "%u", (uint32_t) Time_currentTimeSeconds(admin->eventBase));
-        String* theCookie = &(String) { .len = strlen(bytes), .bytes = bytes };
+        String* theCookie = &(String) { .len = CString_strlen(bytes), .bytes = bytes };
         Dict_putString(d, cookie, theCookie, allocator);
         Admin_sendMessage(d, txid, admin);
         return;
@@ -512,13 +508,13 @@ void Admin_registerFunctionWithArgCount(char* name,
     for (int i = 0; arguments && i < argCount; i++) {
         // "type" must be one of: [ "String", "Int", "Dict", "List" ]
         String* type = NULL;
-        if (!strcmp(arguments[i].type, STRING->bytes)) {
+        if (!CString_strcmp(arguments[i].type, STRING->bytes)) {
             type = STRING;
-        } else if (!strcmp(arguments[i].type, INTEGER->bytes)) {
+        } else if (!CString_strcmp(arguments[i].type, INTEGER->bytes)) {
             type = INTEGER;
-        } else if (!strcmp(arguments[i].type, DICT->bytes)) {
+        } else if (!CString_strcmp(arguments[i].type, DICT->bytes)) {
             type = DICT;
-        } else if (!strcmp(arguments[i].type, LIST->bytes)) {
+        } else if (!CString_strcmp(arguments[i].type, LIST->bytes)) {
             type = LIST;
         } else {
             abort();

+ 1 - 2
admin/AdminClient.c

@@ -24,7 +24,6 @@
 #include "io/Reader.h"
 #include "io/Writer.h"
 #include "util/Bits.h"
-#include "util/platform/libc/strlen.h"
 #include "util/Endian.h"
 #include "util/Hex.h"
 #include "util/events/Timeout.h"
@@ -89,7 +88,7 @@ static int calculateAuth(Dict* message,
     uint32_t cookie = (cookieStr != NULL) ? strtoll(cookieStr->bytes, NULL, 10) : 0;
     snprintf((char*) passAndCookie, 64, "%s%u", password->bytes, cookie);
     uint8_t hash[32];
-    crypto_hash_sha256(hash, passAndCookie, strlen((char*) passAndCookie));
+    crypto_hash_sha256(hash, passAndCookie, CString_strlen((char*) passAndCookie));
     Hex_encode((uint8_t*)hashHex->bytes, 64, hash, 32);
 
     Dict_putString(message, String_new("hash", alloc), hashHex, alloc);

+ 3 - 7
admin/AdminLog.c

@@ -26,10 +26,6 @@
 #include "util/log/Log_impl.h"
 #include "util/Hex.h"
 
-#define string_strcmp
-#define string_strrchr
-#define string_strlen
-#include "util/platform/libc/string.h"
 
 #include <stdint.h>
 #include <stdio.h>
@@ -79,7 +75,7 @@ struct AdminLog
 
 static inline const char* getShortName(const char* fullFilePath)
 {
-    const char* out = strrchr(fullFilePath, '/');
+    const char* out = CString_strrchr(fullFilePath, '/');
     if (out) {
         return out + 1;
     }
@@ -99,7 +95,7 @@ static inline bool isMatch(struct Subscription* subscription,
             }
         } else {
             const char* shortFileName = getShortName(file);
-            if (strcmp(shortFileName, subscription->file)) {
+            if (CString_strcmp(shortFileName, subscription->file)) {
                 return false;
             }
 
@@ -232,7 +228,7 @@ static void subscribe(Dict* args, void* vcontext, String* txid, struct Allocator
         if (file) {
             int i;
             for (i = 0; i < FILE_NAME_COUNT; i++) {
-                if (log->fileNames[i] && !strcmp(log->fileNames[i], file)) {
+                if (log->fileNames[i] && !CString_strcmp(log->fileNames[i], file)) {
                     file = log->fileNames[i];
                     sub->internalName = true;
                     break;

+ 0 - 1
admin/AuthorizedPasswords.c

@@ -16,7 +16,6 @@
 #include "benc/Int.h"
 #include "benc/List.h"
 #include "benc/String.h"
-#include "util/platform/libc/strlen.h"
 
 struct Context
 {

+ 1 - 4
admin/Configurator.c

@@ -12,12 +12,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strrchr
-#define string_strlen
 #include "admin/AdminClient.h"
 #include "admin/Configurator.h"
 #include "benc/String.h"
-#include "util/platform/libc/string.h"
 #include "benc/Dict.h"
 #include "benc/Int.h"
 #include "benc/List.h"
@@ -230,7 +227,7 @@ static void udpInterface(Dict* config, struct Context* ctx)
                 Dict* value = entry->val->as.dictionary;
                 Log_keys(ctx->logger, "Attempting to connect to node [%s].", key->bytes);
                 key = String_clone(key, perCallAlloc);
-                char* lastColon = strrchr(key->bytes, ':');
+                char* lastColon = CString_strrchr(key->bytes, ':');
 
                 if (!Sockaddr_parse(key->bytes, NULL)) {
                     // it's a sockaddr, fall through

+ 0 - 1
admin/angel/AngelInit.c

@@ -31,7 +31,6 @@
 #include "util/events/EventBase.h"
 #include "util/events/Pipe.h"
 #include "util/events/Process.h"
-#include "util/platform/libc/strlen.h"
 #include "util/Bits.h"
 #include "util/Assert.h"
 #include "util/Hex.h"

+ 2 - 4
admin/angel/Cjdns.c

@@ -12,11 +12,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strcmp
 #define string_strlen // some systems implement strcmp as a macro using strlen.
 #include "admin/angel/AngelInit.h"
 #include "admin/angel/Core.h"
-#include "util/platform/libc/string.h"
 
 #include <stdio.h>
 #include <unistd.h>
@@ -25,9 +23,9 @@ int main(int argc, char** argv)
 {
     if (isatty(STDIN_FILENO) || argc < 2) {
         // Fall through.
-    } else if (!strcmp("angel", argv[1])) {
+    } else if (!CString_strcmp("angel", argv[1])) {
         return AngelInit_main(argc, argv);
-    } else if (!strcmp("core", argv[1])) {
+    } else if (!CString_strcmp("core", argv[1])) {
         return Core_main(argc, argv);
     }
     printf("This is internal to cjdns, it should not be started manually.\n");

+ 15 - 16
admin/angel/cjdroute2.c

@@ -12,9 +12,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strcmp
-#define string_strrchr
-#define string_strlen
 #include "admin/Admin.h"
 #include "admin/AdminClient.h"
 #include "admin/angel/InterfaceWaiter.h"
@@ -49,9 +46,9 @@
 #include "net/SwitchPinger.h"
 #include "net/SwitchPinger_admin.h"
 #include "switch/SwitchCore.h"
+#include "util/CString.h"
 #include "util/ArchInfo.h"
 #include "util/SysInfo.h"
-#include "util/platform/libc/string.h"
 #include "util/events/EventBase.h"
 #include "util/events/Pipe.h"
 #include "util/events/Process.h"
@@ -446,9 +443,9 @@ int main(int argc, char** argv)
 
     if (isatty(STDIN_FILENO) || argc < 2) {
         // Fall through.
-    } else if (!strcmp("angel", argv[1])) {
+    } else if (!CString_strcmp("angel", argv[1])) {
         return AngelInit_main(argc, argv);
-    } else if (!strcmp("core", argv[1])) {
+    } else if (!CString_strcmp("core", argv[1])) {
         return Core_main(argc, argv);
     }
 
@@ -462,22 +459,24 @@ int main(int argc, char** argv)
 
     if (argc == 2) {
         // one argument
-        if ((strcmp(argv[1], "--help") == 0) || (strcmp(argv[1], "-h") == 0)) {
+        if ((CString_strcmp(argv[1], "--help") == 0) || (CString_strcmp(argv[1], "-h") == 0)) {
             return usage(allocator, argv[0]);
-        } else if (strcmp(argv[1], "--genconf") == 0) {
+        } else if (CString_strcmp(argv[1], "--genconf") == 0) {
             return genconf(rand);
-        } else if (strcmp(argv[1], "--pidfile") == 0) {
+        } else if (CString_strcmp(argv[1], "--pidfile") == 0) {
             // deprecated
             fprintf(stderr, "'--pidfile' option is deprecated.\n");
             return 0;
-        } else if (strcmp(argv[1], "--reconf") == 0) {
+        } else if (CString_strcmp(argv[1], "--reconf") == 0) {
             // Performed after reading the configuration
-        } else if (strcmp(argv[1], "--bench") == 0) {
+        } else if (CString_strcmp(argv[1], "--bench") == 0) {
             return benchmark();
-        } else if ((strcmp(argv[1], "--version") == 0) || (strcmp(argv[1], "-v") == 0)) {
+        } else if ((CString_strcmp(argv[1], "--version") == 0)
+            || (CString_strcmp(argv[1], "-v") == 0))
+        {
             printf("Cjdns protocol version: %d\n", Version_CURRENT_PROTOCOL);
             return 0;
-        } else if (strcmp(argv[1], "--cleanconf") == 0) {
+        } else if (CString_strcmp(argv[1], "--cleanconf") == 0) {
             // Performed after reading configuration
         } else {
             fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], argv[1]);
@@ -489,7 +488,7 @@ int main(int argc, char** argv)
         fprintf(stderr, "%s: too many arguments\n", argv[0]);
         fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
         // because of '--pidfile $filename'?
-        if (strcmp(argv[1], "--pidfile") == 0)
+        if (CString_strcmp(argv[1], "--pidfile") == 0)
         {
             fprintf(stderr, "\n'--pidfile' option is deprecated.\n");
         }
@@ -513,7 +512,7 @@ int main(int argc, char** argv)
         return -1;
     }
 
-    if (argc == 2 && strcmp(argv[1], "--cleanconf") == 0) {
+    if (argc == 2 && CString_strcmp(argv[1], "--cleanconf") == 0) {
         struct Writer* stdoutWriter = FileWriter_new(stdout, allocator);
         JsonBencSerializer_get()->serializeDictionary(stdoutWriter, &config);
         printf("\n");
@@ -530,7 +529,7 @@ int main(int argc, char** argv)
     if (!adminPass) {
         adminPass = String_newBinary(NULL, 32, allocator);
         Random_base32(rand, (uint8_t*) adminPass->bytes, 32);
-        adminPass->len = strlen(adminPass->bytes);
+        adminPass->len = CString_strlen(adminPass->bytes);
     }
     if (!adminBind) {
         Except_throw(eh, "You must specify admin.bind in the cjdroute.conf file.");

+ 0 - 1
admin/test/Admin_test.c

@@ -18,7 +18,6 @@
 #include "benc/Int.h"
 #include "memory/Allocator.h"
 #include "util/Assert.h"
-#include "util/platform/libc/strlen.h"
 
 #include <stdio.h>
 

+ 5 - 9
admin/testframework/AdminTestFramework.c

@@ -36,10 +36,6 @@
 #include "util/Assert.h"
 #include "util/log/Log.h"
 #include "util/log/WriterLog.h"
-#define string_strlen
-#define string_strchr
-#define string_strcmp
-#include "util/platform/libc/string.h"
 
 #include <unistd.h>
 #include <stdlib.h>
@@ -109,9 +105,9 @@ static void initAngel(struct Pipe* asClientPipe,
 
     struct Message* m = &(struct Message) {
         .bytes = (uint8_t*) coreToAngelResponse,
-        .length = strlen(coreToAngelResponse),
+        .length = CString_strlen(coreToAngelResponse),
         .padding = 0,
-        .capacity = strlen(coreToAngelResponse)
+        .capacity = CString_strlen(coreToAngelResponse)
     };
     Message_shift(m, -24, NULL);
     m = Message_clone(m, tempAlloc);
@@ -136,7 +132,7 @@ static void initAngel(struct Pipe* asClientPipe,
 
 struct AdminTestFramework* AdminTestFramework_setUp(int argc, char** argv, char* testName)
 {
-    if (argc > 2 && !strcmp(testName, argv[1]) && !strcmp("angel", argv[2])) {
+    if (argc > 2 && !CString_strcmp(testName, argv[1]) && !CString_strcmp("angel", argv[2])) {
         exit(AngelInit_main(argc-1, &argv[1]));
     }
 
@@ -201,10 +197,10 @@ void AdminTestFramework_tearDown(struct AdminTestFramework* framework)
           "1:q" "10:Angel_exit"
         "e";
 
-    char* start = strchr(buff, 'd');
+    char* start = CString_strchr(buff, 'd');
     struct Message m = {
         .bytes = (uint8_t*) start,
-        .length = strlen(start),
+        .length = CString_strlen(start),
         .padding = start - buff
     };
     struct Message* mp = Message_clone(&m, framework->alloc);

+ 2 - 4
benc/String.c

@@ -16,15 +16,13 @@
 #include "benc/String.h"
 #include "util/Bits.h"
 
-#define string_strlen
-#include "util/platform/libc/string.h"
 #include <stdio.h>
 #include <stdarg.h>
 
 /** @see Object.h */
 String* String_new(const char* bytes, struct Allocator* allocator)
 {
-    return String_newBinary(bytes, strlen(bytes), allocator);
+    return String_newBinary(bytes, CString_strlen(bytes), allocator);
 }
 
 /** @see Object.h */
@@ -49,7 +47,7 @@ String* String_vprintf(struct Allocator* allocator, const char* format, va_list
     #define String_BUFFER_SZ 1024
     char buff[String_BUFFER_SZ];
     vsnprintf(buff, String_BUFFER_SZ, format, args);
-    size_t length = strlen(buff);
+    size_t length = CString_strlen(buff);
     return String_newBinary(buff, length, allocator);
     #undef String_BUFFER_SZ
 }

+ 2 - 2
benc/String.h

@@ -17,7 +17,7 @@
 
 #include "benc/Object.h"
 #include "memory/Allocator.h"
-#include "util/platform/libc/strlen.h"
+#include "util/CString.h"
 #include "util/Linker.h"
 Linker_require("benc/String.c")
 
@@ -37,7 +37,7 @@ String* String_new(const char* bytes, struct Allocator* allocator);
 /**
  * Create a new bencoded constant string on the stack.
  */
-#define String_CONST(x) (&(String) { .bytes = x, .len = strlen(x) })
+#define String_CONST(x) (&(String) { .bytes = x, .len = CString_strlen(x) })
 
 /** For use outside of functions with compile time constant strings. */
 #define String_CONST_SO(x) (&(String) { .bytes = x, .len = sizeof(x) - 1 })

+ 1 - 2
benc/serialization/json/JsonBencSerializer.c

@@ -19,7 +19,6 @@
 #include "benc/List.h"
 #include "benc/String.h"
 #include "benc/serialization/BencSerializer.h"
-#include "util/platform/libc/strlen.h"
 #include "util/Bits.h"
 #include "util/Hex.h"
 
@@ -172,7 +171,7 @@ static int32_t serializeint64_t(struct Writer* writer,
 
     snprintf(buffer, 32, "%" PRId64, integer);
 
-    return Writer_write(writer, buffer, strlen(buffer));
+    return Writer_write(writer, buffer, CString_strlen(buffer));
 }
 
 /** @see BencSerializer.h */

+ 2 - 3
benc/serialization/standard/StandardBencSerializer.c

@@ -19,8 +19,7 @@
 #include "benc/Dict.h"
 #include "benc/List.h"
 #include "benc/serialization/BencSerializer.h"
-#define string_strlen
-#include "util/platform/libc/string.h"
+#include "util/CString.h"
 
 #include <stdio.h>
 /* for parseint64_t */
@@ -45,7 +44,7 @@ static int32_t writeint64_t(struct Writer* writer,
 {
     char buffer[32] = {0};
     snprintf(buffer, 32, "%" PRId64, integer);
-    return Writer_write(writer, buffer, strlen(buffer));
+    return Writer_write(writer, buffer, CString_strlen(buffer));
 }
 
 /** @see BencSerializer.h */

+ 3 - 4
benc/serialization/standard/test/benc_serializeInteger_test.c

@@ -12,8 +12,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strcmp
-#include "util/platform/libc/string.h"
 #include "memory/Allocator.h"
 #include "memory/MallocAllocator.h"
 #include "io/Reader.h"
@@ -23,6 +21,7 @@
 #include "benc/Object.h"
 #include "benc/serialization/BencSerializer.h"
 #include "benc/serialization/standard/StandardBencSerializer.h"
+#include "util/CString.h"
 
 #include <stdio.h>
 
@@ -30,8 +29,8 @@ static int expect(char* str, struct Writer* writer, struct Reader* reader, int r
 {
     char buffer[32];
     Writer_write(writer, "\0", 1);
-    Reader_read(reader, buffer, strlen(str) + 1);
-    if (strcmp(str, buffer) != 0) {
+    Reader_read(reader, buffer, CString_strlen(str) + 1);
+    if (CString_strcmp(str, buffer) != 0) {
         printf("Expected %s\n Got %s\n", str, buffer);
         return -1;
     }

+ 3 - 3
benc/serialization/standard/test/benc_serializeList_test.c

@@ -23,7 +23,7 @@
 #include "benc/serialization/BencSerializer.h"
 #include "benc/serialization/standard/StandardBencSerializer.h"
 #include "util/Bits.h"
-#include "util/platform/libc/strlen.h"
+#include "util/CString.h"
 
 #include <stdio.h>
 
@@ -31,14 +31,14 @@ static int parseEmptyList()
 {
     char* test = "d" "2:hi" "le" "e";
     struct Allocator* alloc = MallocAllocator_new(1<<20);
-    struct Reader* reader = ArrayReader_new(test, strlen(test), alloc);
+    struct Reader* reader = ArrayReader_new(test, CString_strlen(test), alloc);
     Dict d;
     int ret = StandardBencSerializer_get()->parseDictionary(reader, alloc, &d);
 
     char out[256];
     struct Writer* w = ArrayWriter_new(out, 256, alloc);
     ret |= StandardBencSerializer_get()->serializeDictionary(w, &d);
-    ret |= Bits_memcmp(test, out, strlen(test));
+    ret |= Bits_memcmp(test, out, CString_strlen(test));
 
     Allocator_free(alloc);
     return ret;

+ 3 - 5
benc/serialization/standard/test/benc_serializeString_test.c

@@ -12,8 +12,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strcmp
-#include "util/platform/libc/string.h"
 #include "memory/Allocator.h"
 #include "memory/MallocAllocator.h"
 #include "io/Reader.h"
@@ -32,8 +30,8 @@ static int expect(char* str, struct Writer* writer, struct Reader* reader)
     int ret = 0;
     char buffer[32];
     Writer_write(writer, "\0", 1);
-    Reader_read(reader, buffer, strlen(str) + 1);
-    if (strcmp(str, buffer) != 0) {
+    Reader_read(reader, buffer, CString_strlen(str) + 1);
+    if (CString_strcmp(str, buffer) != 0) {
         printf("Expected %s\n Got %s\n", str, buffer);
         return -1;
     }
@@ -54,7 +52,7 @@ static void testParse(struct Writer* w, struct Reader* r, struct Allocator* allo
     char* badBenc = "d2:aq21:RouterModule_pingNode4:argsd4:path39:fcd9:6a75:6c9c7:timeouti4000ee"
                     "6:cookie0:4:hash64:09c6bcd1482df339757c99bbc5e796192968a28562f701fb53a57ed6"
                     "e26b15511:q4:auth4:txid19:43866780dc455e15619e";
-    Writer_write(w, badBenc, strlen(badBenc)+1);
+    Writer_write(w, badBenc, CString_strlen(badBenc)+1);
     Dict dict;
     Assert_true(StandardBencSerializer_get()->parseDictionary(r, alloc, &dict));
 }

+ 1 - 2
contrib/c/privatetopublic.c

@@ -12,18 +12,17 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strerror
 #include "crypto/AddressCalc.h"
 #include "dht/Address.h"
 #include "util/Base32.h"
 #include "util/Hex.h"
-#include "util/platform/libc/string.h"
 
 #include "crypto_scalarmult_curve25519.h"
 
 #include <unistd.h>
 #include <stdio.h>
 #include <errno.h>
+#include <string.h>
 
 static int usage(char* appName)
 {

+ 2 - 1
contrib/c/publictoip6.c

@@ -14,6 +14,7 @@
  */
 #include "crypto/Key.h"
 #include "util/AddrTools.h"
+#include "util/CString.h"
 #include <stdio.h>
 
 static int usage(char* appName)
@@ -34,7 +35,7 @@ int main(int argc, char** argv)
 
     uint8_t keyBytes[32];
     uint8_t ip6Bytes[16];
-    String key = { .bytes = argv[1], .len = strlen(argv[1]) };
+    String key = { .bytes = argv[1], .len = CString_strlen(argv[1]) };
 
     int ret = Key_parse(&key, keyBytes, ip6Bytes);
     switch (ret) {

+ 0 - 1
crypto/test/CryptoAuth_async_test.c

@@ -17,7 +17,6 @@
 #include "io/FileWriter.h"
 #include "benc/String.h"
 #include "memory/MallocAllocator.h"
-#include "util/platform/libc/string.h"
 #include "util/events/EventBase.h"
 #include "util/Assert.h"
 #include "util/Bits.h"

+ 6 - 10
crypto/test/CryptoAuth_test.c

@@ -12,15 +12,11 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strcmp
-#define string_strncmp
-#define string_strlen
 #include "crypto/random/Random.h"
 #include "crypto/CryptoAuth.h"
 #include "io/FileWriter.h"
 #include "benc/String.h"
 #include "memory/MallocAllocator.h"
-#include "util/platform/libc/string.h"
 #include "util/events/EventBase.h"
 #include "util/Assert.h"
 #include "util/Bits.h"
@@ -51,11 +47,11 @@ static struct Message msg;
 
 #define BUFFER_SIZE 400
 static uint8_t* textBuff;
-#define ALIGNED_LEN(x) (strlen(x) + 4 - (strlen(x) % 4))
+#define ALIGNED_LEN(x) (CString_strlen(x) + 4 - (CString_strlen(x) % 4))
 #define MK_MSG(x) \
     Bits_memset(textBuff, 0, BUFFER_SIZE);                                      \
-    Bits_memcpy(&textBuff[BUFFER_SIZE - ALIGNED_LEN(x)], x, strlen(x));         \
-    msg.length = strlen(x);                                                     \
+    Bits_memcpy(&textBuff[BUFFER_SIZE - ALIGNED_LEN(x)], x, CString_strlen(x));         \
+    msg.length = CString_strlen(x);                                                     \
     msg.bytes = textBuff + BUFFER_SIZE - ALIGNED_LEN(x);                        \
     msg.padding = BUFFER_SIZE - ALIGNED_LEN(x)
 
@@ -136,7 +132,7 @@ static int init(const uint8_t* privateKey,
 
     ca2 = CryptoAuth_new(allocator, privateKey, base, logger, rand);
     if (password) {
-        String passStr = {.bytes=(char*)password,.len=strlen((char*)password)};
+        String passStr = {.bytes=(char*)password,.len=CString_strlen((char*)password)};
         CryptoAuth_setAuth(&passStr, 1, cif1);
         CryptoAuth_addUser(&passStr, 1, String_new(userObj, allocator), ca2);
     }
@@ -162,7 +158,7 @@ static int sendToIf1(const char* x)
     cif2->sendMessage(&msg, cif2);
     if (!suppressMessages) {
         Assert_true(if1Msg);
-        if (strncmp((char*)if1Msg, x, strlen(x)) != 0) {
+        if (CString_strncmp((char*)if1Msg, x, CString_strlen(x)) != 0) {
             printf("expected %s, got %s\n", x, (char*)if1Msg);
             Assert_true(0);
         }
@@ -179,7 +175,7 @@ static int sendToIf2(const char* x)
     cif1->sendMessage(&msg, cif1);
     if (!suppressMessages) {
         Assert_true(if2Msg);
-        if (strncmp((char*)if2Msg, x, strlen(x)) != 0) {
+        if (CString_strncmp((char*)if2Msg, x, CString_strlen(x)) != 0) {
             printf("expected %s, got %s\n", x, (char*)if2Msg);
             Assert_true(0);
         }

+ 4 - 7
crypto/test/CryptoAuth_unit_test.c

@@ -12,8 +12,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strcpy
-#define string_strlen
 #include "benc/List.h"
 #include "benc/String.h"
 #include "crypto/CryptoAuth_pvt.h"
@@ -22,7 +20,6 @@
 #include "io/FileWriter.h"
 #include "memory/MallocAllocator.h"
 #include "memory/Allocator.h"
-#include "util/platform/libc/string.h"
 #include "util/events/EventBase.h"
 #include "util/Assert.h"
 #include "util/Bits.h"
@@ -56,7 +53,7 @@ static void encryptRndNonceTest()
     Bits_memset(secret, 0, 32);
 
     struct Message m = { .bytes=&buff[32], .length=12, .padding=32};
-    strcpy((char*) m.bytes, "hello world");
+    CString_strcpy((char*) m.bytes, "hello world");
 
     CryptoAuth_encryptRndNonce(nonce, &m, secret);
 
@@ -130,7 +127,7 @@ static struct CryptoAuth_Wrapper* setUp(uint8_t* myPrivateKey,
             .senderContext = wrapper,
             .allocator = allocator
         };
-        String str = { .bytes = (char*) authPassword, .len = strlen((char*)authPassword) };
+        String str = { .bytes = (char*) authPassword, .len = CString_strlen((char*)authPassword) };
         CryptoAuth_setAuth(&str, 1, &temp);
     }
 
@@ -143,7 +140,7 @@ static struct CryptoAuth_Wrapper* setUp(uint8_t* myPrivateKey,
 
 static void testHello(uint8_t* password, uint8_t* expectedOutput)
 {
-    Assert_true(strlen((char*)expectedOutput) == 264);
+    Assert_true(CString_strlen((char*)expectedOutput) == 264);
     struct Message* outMessage;
     struct CryptoAuth_Wrapper* wrapper =
         setUp(NULL, (uint8_t*) "wxyzabcdefghijklmnopqrstuv987654", password, &outMessage);
@@ -201,7 +198,7 @@ static void receiveHelloWithNoAuth()
         "29ea3e12";
 
     uint8_t message[132];
-    Assert_true(Hex_decode(message, 132, messageHex, strlen((char*)messageHex)) > 0);
+    Assert_true(Hex_decode(message, 132, messageHex, CString_strlen((char*)messageHex)) > 0);
     struct Message incoming = {
         .length = 132,
         .padding = 0,

+ 2 - 2
dht/DHTModuleRegistry.c

@@ -20,9 +20,9 @@
 #include "benc/Object.h"
 #include "benc/serialization/BencSerializer.h"
 #include "benc/serialization/standard/StandardBencSerializer.h"
-
 #include "util/Assert.h"
-#include "util/platform/libc/string.h"
+
+#include <stddef.h> // NULL
 
 #define DEBUG2(x, y)
 /* #define DEBUG2(x, y) fprintf(stderr, x, y); fflush(stderr) */

+ 0 - 1
dht/ReplyModule.c

@@ -12,7 +12,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#include "util/platform/libc/string.h"
 
 #include "dht/CJDHTConstants.h"
 #include "dht/DHTMessage.h"

+ 0 - 1
dht/SerializationModule.c

@@ -27,7 +27,6 @@
 #include "util/log/Log.h"
 #include "wire/Message.h"
 
-#include "util/platform/libc/string.h"
 
 #define SERIALIZER StandardBencSerializer_get()
 

+ 0 - 1
dht/dhtcore/Janitor.c

@@ -31,7 +31,6 @@
 #include "util/events/Timeout.h"
 #include "util/events/Time.h"
 
-#include "util/platform/libc/string.h"
 #include <stdint.h>
 #include <stdbool.h>
 

+ 0 - 3
dht/dhtcore/NodeStore_admin.c

@@ -12,8 +12,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strcpy
-#define string_strlen
 #include "admin/Admin.h"
 #include "benc/Dict.h"
 #include "benc/String.h"
@@ -26,7 +24,6 @@
 #include "switch/EncodingScheme.h"
 #include "util/AddrTools.h"
 #include "util/version/Version.h"
-#include "util/platform/libc/string.h"
 
 struct Context {
     struct Admin* admin;

+ 1 - 3
dht/dhtcore/test/NodeStore_test_disabled.c

@@ -12,7 +12,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strcmp
 #include "memory/MallocAllocator.h"
 #include "crypto/random/Random.h"
 #include "crypto/AddressCalc.h"
@@ -26,7 +25,6 @@
 #include "util/Endian.h"
 #include "util/log/WriterLog.h"
 #include "util/version/Version.h"
-#include "util/platform/libc/string.h"
 
 #include "crypto_scalarmult_curve25519.h"
 
@@ -431,7 +429,7 @@ static void test_pathfinderTwo_splitLink()
 
 int main(int argc, char** argv)
 {
-    if (argc > 1 && !strcmp(argv[argc-1], "--genkeys")) {
+    if (argc > 1 && !CString_strcmp(argv[argc-1], "--genkeys")) {
         genKeys = 1;
     }
 

+ 2 - 3
exception/Except.c

@@ -14,12 +14,11 @@
  */
 #define _POSIX_C_SOURCE 200112L
 
-#define string_strrchr
 
 #include "exception/Except.h"
+#include "util/CString.h"
 
 #include <stdarg.h>
-#include "util/platform/libc/string.h"
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -28,7 +27,7 @@ void Except__throw(char* file, int line, struct Except* eh, char* format, ...)
     va_list args;
     va_start(args, format);
 
-    char* subFile = strrchr(file, '/');
+    char* subFile = CString_strrchr(file, '/');
     if (!subFile) {
         subFile = file;
     }

+ 6 - 6
interface/ETHInterface_linux.c

@@ -12,8 +12,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strncpy
-#define string_strerror
 #include "exception/Except.h"
 #include "interface/Interface.h"
 #include "interface/ETHInterface.h"
@@ -25,7 +23,6 @@
 #include "wire/Error.h"
 #include "wire/Ethernet.h"
 #include "util/Assert.h"
-#include "util/platform/libc/string.h"
 #include "util/platform/Socket.h"
 #include "util/events/Event.h"
 #include "util/Identity.h"
@@ -33,6 +30,7 @@
 #include "util/version/Version.h"
 #include "util/events/Timeout.h"
 
+#include <string.h>
 #include <sys/socket.h>
 #include <linux/if_packet.h>
 #include <linux/if_ether.h>
@@ -129,7 +127,8 @@ static uint8_t sendMessage(struct Message* message, struct Interface* ethIf)
                 return Error_LINK_LIMIT_EXCEEDED;
 
             default:;
-                Log_info(context->logger, "Got error sending to socket [%s]", strerror(errno));
+                Log_info(context->logger, "Got error sending to socket [%s]",
+                         strerror(errno));
         }
     }
     return 0;
@@ -339,7 +338,7 @@ struct ETHInterface* ETHInterface_new(struct EventBase* base,
     if (context->socket == -1) {
         Except_throw(exHandler, "call to socket() failed. [%s]", strerror(errno));
     }
-    strncpy(ifr.ifr_name, bindDevice, IFNAMSIZ - 1);
+    CString_strncpy(ifr.ifr_name, bindDevice, IFNAMSIZ - 1);
 
     if (ioctl(context->socket, SIOCGIFINDEX, &ifr) == -1) {
         Except_throw(exHandler, "failed to find interface index [%s]", strerror(errno));
@@ -347,7 +346,8 @@ struct ETHInterface* ETHInterface_new(struct EventBase* base,
     context->ifindex = ifr.ifr_ifindex;
 
     if (ioctl(context->socket, SIOCGIFHWADDR, &ifr) == -1) {
-       Except_throw(exHandler, "failed to find mac address of interface [%s]", strerror(errno));
+       Except_throw(exHandler, "failed to find mac address of interface [%s]",
+                    strerror(errno));
     }
 
     uint8_t srcMac[6];

+ 6 - 6
interface/test/FramingInterface_test.c

@@ -16,9 +16,9 @@
 #include "interface/FramingInterface.h"
 #include "memory/Allocator.h"
 #include "memory/MallocAllocator.h"
-#include "util/platform/libc/strlen.h"
 #include "util/Endian.h"
 #include "util/Bits.h"
+#include "util/CString.h"
 #include "wire/Error.h"
 
 union MessageLength
@@ -53,7 +53,7 @@ int main()
     fi->receiverContext = &output;
 
     char* text = "Hello World!";
-    Assert_true(12 == strlen(text));
+    Assert_true(12 == CString_strlen(text));
     union MessageLength ml = { .length_be = Endian_hostToBigEndian32(12) };
 
     struct Message* msg;
@@ -85,8 +85,8 @@ int main()
         send(&dummy, msg, alloc);
     }
 
-    Assert_true(output && output->length == (int)strlen(text));
-    Assert_true(!Bits_memcmp(output->bytes, text, strlen(text)));
+    Assert_true(output && output->length == (int)CString_strlen(text));
+    Assert_true(!Bits_memcmp(output->bytes, text, CString_strlen(text)));
 
     Allocator_free(child);
     child = Allocator_child(alloc);
@@ -100,8 +100,8 @@ int main()
         send(&dummy, msg, alloc);
     }
 
-    Assert_true(output && output->length == (int)strlen(text));
-    Assert_true(!Bits_memcmp(output->bytes, text, strlen(text)));
+    Assert_true(output && output->length == (int)CString_strlen(text));
+    Assert_true(!Bits_memcmp(output->bytes, text, CString_strlen(text)));
 
     Allocator_free(alloc);
 

+ 0 - 3
interface/test/TUNInterface_ipv4_root_test.c

@@ -12,8 +12,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strcmp
-#define string_strlen
 #include "admin/testframework/AdminTestFramework.h"
 #include "admin/Admin.h"
 #include "admin/AdminClient.h"
@@ -31,7 +29,6 @@
 #include "util/Assert.h"
 #include "util/log/Log.h"
 #include "util/log/WriterLog.h"
-#include "util/platform/libc/string.h"
 #include "util/events/Timeout.h"
 #include "wire/Ethernet.h"
 #include "wire/Headers.h"

+ 0 - 1
interface/test/TUNInterface_ipv6_root_test.c

@@ -29,7 +29,6 @@
 #include "util/Assert.h"
 #include "util/log/Log.h"
 #include "util/log/WriterLog.h"
-#include "util/platform/libc/string.h"
 #include "util/events/Timeout.h"
 #include "wire/Ethernet.h"
 #include "wire/Headers.h"

+ 0 - 3
interface/test/UDPInterface_communication_test.c

@@ -12,8 +12,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strcmp
-#define string_strlen
 #include "admin/testframework/AdminTestFramework.h"
 #include "admin/Admin.h"
 #include "admin/AdminClient.h"
@@ -29,7 +27,6 @@
 #include "util/Assert.h"
 #include "util/log/Log.h"
 #include "util/log/WriterLog.h"
-#include "util/platform/libc/string.h"
 #include "util/events/Timeout.h"
 
 #include <stdlib.h>

+ 0 - 1
interface/tuntap/TUNInterface_freebsd.c

@@ -16,7 +16,6 @@
 #include "interface/tuntap/TUNInterface.h"
 #include "interface/tuntap/BSDMessageTypeWrapper.h"
 #include "util/AddrTools.h"
-#include "util/Bits.h"
 #include "util/events/Pipe.h"
 
 #include <errno.h>

+ 1 - 5
interface/tuntap/TUNInterface_linux.c

@@ -18,10 +18,6 @@
 #include "interface/Interface.h"
 #include "interface/tuntap/TUNInterface.h"
 #include "util/events/Pipe.h"
-#define string_strncpy
-#define string_strlen
-#define string_strerror
-#include "util/platform/libc/string.h"
 
 #include <errno.h>
 #include <stdio.h>
@@ -34,7 +30,7 @@
 #include <stddef.h>
 #include <net/if.h>
 #include <arpa/inet.h>
-
+#include <string.h>
 #include <linux/if.h>
 #include <linux/if_tun.h>
 #include <linux/if_ether.h>

+ 0 - 1
interface/tuntap/TUNInterface_openbsd.c

@@ -15,7 +15,6 @@
 #include "exception/Except.h"
 #include "interface/Interface.h"
 #include "interface/TUNConfigurator.h"
-#include "util/Bits.h"
 
 #include <errno.h>
 #include <ctype.h>

+ 8 - 8
interface/tuntap/windows/TAPDevice.c

@@ -147,7 +147,7 @@ static int is_tap_win32_dev(const char *guid)
                     &len);
 
                 if (status == ERROR_SUCCESS && data_type == REG_SZ) {
-                    if (!Bits_memcmp(component_id, "tap", strlen("tap")) &&
+                    if (!Bits_memcmp(component_id, "tap", CString_strlen("tap")) &&
                         !strcmp (net_cfg_instance_id, guid)) {
                         RegCloseKey (unit_key);
                         RegCloseKey (netcard_key);
@@ -197,7 +197,7 @@ static int get_device_guid(
             WinFail_fail(eh, "RegEnumKeyEx() failed", status);
         }
 
-        if (len != strlen(NETWORK_ADAPTER_GUID)) {
+        if (len != CString_strlen(NETWORK_ADAPTER_GUID)) {
             // extranious directory, eg: "Descriptions"
             continue;
         }
@@ -224,8 +224,8 @@ static int get_device_guid(
         if (is_tap_win32_dev(enum_name)) {
             snprintf(name, name_size, "%s", enum_name);
             if (actual_name) {
-                if (strcmp(actual_name, "") != 0) {
-                    if (strcmp(name_data, actual_name) != 0) {
+                if (CString_strcmp(actual_name, "") != 0) {
+                    if (CString_strcmp(name_data, actual_name) != 0) {
                         RegCloseKey (connKey);
                         ++i;
                         continue;
@@ -266,12 +266,12 @@ struct TAPDevice* TAPDevice_find(const char* preferredName,
     }
 
     struct TAPDevice* out = Allocator_malloc(alloc, sizeof(struct TAPDevice));
-    out->name = Allocator_malloc(alloc, strlen(buff)+1);
-    Bits_memcpy(out->name, buff, strlen(buff)+1);
+    out->name = Allocator_malloc(alloc, CString_strlen(buff)+1);
+    Bits_memcpy(out->name, buff, CString_strlen(buff)+1);
 
     snprintf(buff, sizeof(buff), USERMODEDEVICEDIR "%s" TAPSUFFIX, guid);
 
-    out->path = Allocator_malloc(alloc, strlen(buff)+1);
-    Bits_memcpy(out->path, buff, strlen(buff)+1);
+    out->path = Allocator_malloc(alloc, CString_strlen(buff)+1);
+    Bits_memcpy(out->path, buff, CString_strlen(buff)+1);
     return out;
 }

+ 0 - 2
memory/Allocator.c

@@ -12,8 +12,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strrchr
-#include "util/platform/libc/string.h"
 
 #include "memory/Allocator.h"
 #include "memory/Allocator_pvt.h"

+ 0 - 1
memory/test/Allocator_test.c

@@ -13,7 +13,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include "util/Assert.h"
-#include "util/platform/libc/string.h"
 #include <stdint.h>
 #include <stdio.h>
 

+ 1 - 1
test/cjdroute_routerPing_test.c

@@ -41,7 +41,7 @@ int main()
     struct Ducttape_pvt* dt = (struct Ducttape_pvt*) tf->ducttape;
 
     struct Allocator* allocator = MallocAllocator_new(85000);
-    uint16_t buffLen = sizeof(struct Ducttape_IncomingForMe) + 8 + strlen(pingBenc);
+    uint16_t buffLen = sizeof(struct Ducttape_IncomingForMe) + 8 + CString_strlen(pingBenc);
     uint8_t* buff = Allocator_calloc(allocator, buffLen+PADDING, 1);
     struct Headers_SwitchHeader* sh = (struct Headers_SwitchHeader*) (buff + PADDING);
     sh->label_be = Endian_hostToBigEndian64(4);

+ 2 - 5
test/threeNodes_test_disabled.c

@@ -12,15 +12,12 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strncpy
-#define string_strlen
 #include "crypto/Key.h"
 #include "io/FileWriter.h"
 #include "memory/MallocAllocator.h"
 #include "memory/Allocator.h"
 #include "util/Base32.h"
 #include "util/Checksum.h"
-#include "util/platform/libc/string.h"
 #include "util/log/WriterLog.h"
 #include "test/TestFramework.h"
 #include "net/Ducttape_pvt.h"
@@ -149,8 +146,8 @@ static void sendMessage(struct ThreeNodes* tn,
     struct Message* msg;
     Message_STACK(msg, 64, 512);
 
-    Bits_memcpy(msg->bytes, message, strlen(message) + 1);
-    msg->length = strlen(message) + 1;
+    Bits_memcpy(msg->bytes, message, CString_strlen(message) + 1);
+    msg->length = CString_strlen(message) + 1;
 
     TestFramework_craftIPHeader(msg, from->ip, to->ip);
 

+ 0 - 1
tunnel/IpTunnel.c

@@ -27,7 +27,6 @@
 #include "memory/Allocator.h"
 #include "tunnel/IpTunnel.h"
 #include "crypto/AddressCalc.h"
-#include "util/platform/libc/strlen.h"
 #include "util/Checksum.h"
 #include "util/AddrTools.h"
 #include "util/events/EventBase.h"

+ 4 - 6
tunnel/test/IpTunnel_test.c

@@ -12,8 +12,6 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strcpy
-#define string_strlen
 #include "memory/Allocator.h"
 #include "memory/MallocAllocator.h"
 #include "io/FileWriter.h"
@@ -24,9 +22,9 @@
 #include "crypto/random/Random.h"
 #include "crypto/AddressCalc.h"
 #include "tunnel/IpTunnel.h"
-#include "util/platform/libc/string.h"
 #include "util/Bits.h"
 #include "util/Checksum.h"
+#include "util/CString.h"
 #include "wire/Message.h"
 #include "wire/Headers.h"
 #include "wire/Ethernet.h"
@@ -66,7 +64,7 @@ static uint8_t responseWithIpCallback(struct Message* message, struct Interface*
           "e"
           "4:txid" "4:abcd"
         "e";
-    Assert_true(message->length == (int32_t) strlen(expectedResponse));
+    Assert_true(message->length == (int32_t) CString_strlen(expectedResponse));
     Assert_true(!Bits_memcmp(message->bytes, expectedResponse, message->length));
     called = 1;
     return 0;
@@ -108,8 +106,8 @@ int main()
           "1:q" "21:IpTunnel_getAddresses"
           "4:txid" "4:abcd"
         "e";
-    strcpy((char*)message->bytes, requestForAddresses);
-    message->length = strlen(requestForAddresses);
+    CString_strcpy((char*)message->bytes, requestForAddresses);
+    message->length = CString_strlen(requestForAddresses);
 
     Message_shift(message, Headers_UDPHeader_SIZE, NULL);
     struct Headers_UDPHeader* uh = (struct Headers_UDPHeader*) message->bytes;

+ 0 - 1
util/AverageRoller.c

@@ -17,7 +17,6 @@
 #include "util/Bits.h"
 #include "util/events/Time.h"
 
-#include "util/platform/libc/string.h"
 
 /** @see AverageRoller.h */
 struct AverageRoller* AverageRoller_new(const uint32_t windowSeconds,

+ 10 - 0
util/CString.c

@@ -31,6 +31,11 @@ int CString_strcmp(const char* a, const char* b)
     return strcmp(a,b);
 }
 
+int CString_strncmp(const char* a, const char *b, size_t n)
+{
+    return strncmp(a, b, n);
+}
+
 char* CString_strchr(const char* a, int b)
 {
     return strchr(a,b);
@@ -51,6 +56,11 @@ char* CString_strstr(const char* haystack, const char* needle)
     return strstr(haystack,needle);
 }
 
+char* CString_strcpy(char* restrict dest, const char* restrict src)
+{
+    return strcpy(dest, src);
+}
+
 char* CString_strncpy(char* restrict dest, const char *restrict src, size_t n)
 {
     return strncpy(dest, src, n);

+ 7 - 0
util/CString.h

@@ -29,6 +29,10 @@ Gcc_PURE
 Gcc_NONNULL(1,2)
 int CString_strcmp(const char* a, const char* b);
 
+Gcc_PURE
+Gcc_NONNULL(1,2)
+int CString_strncmp(const char* a, const char *b, size_t n);
+
 Gcc_PURE
 Gcc_NONNULL(1)
 char* CString_strchr(const char *a, int b);
@@ -45,6 +49,9 @@ Gcc_PURE
 Gcc_NONNULL(1,2)
 char* CString_strstr(const char* a, const char* b);
 
+Gcc_NONNULL(1,2)
+char* CString_strcpy(char* restrict dest, const char* restrict src);
+
 Gcc_NONNULL(1,2)
 char* CString_strncpy(char* restrict dest, const char *restrict src, size_t n);
 

+ 2 - 4
util/Seccomp.c

@@ -20,20 +20,18 @@
 #include "util/Bits.h"
 #include "util/ArchInfo.h"
 
-#include <signal.h>
-
 // getpriority()
 #include <sys/resource.h>
+#include <signal.h>
 #include <sys/prctl.h>
 #include <errno.h>
-#include <string.h>
 #include <linux/filter.h>
 #include <linux/seccomp.h>
 #include <linux/audit.h>
 #include <sys/syscall.h>
 #include <stddef.h>
-
 #include <stdio.h>
+#include <string.h>
 
 static void catchViolation(int sig, siginfo_t* si, void* threadContext)
 {

+ 3 - 3
util/Security.c

@@ -12,11 +12,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strerror
 #include "exception/Except.h"
 #include "util/log/Log.h"
 #include "util/Security.h"
-#include "util/platform/libc/string.h"
 #include "util/Seccomp.h"
 #include "memory/Allocator.h"
 
@@ -26,6 +24,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <string.h>
 
 #define __USE_MISC // for MAP_ANONYMOUS
 #include <sys/mman.h>
@@ -39,7 +38,8 @@ int Security_setUser(char* userName, struct Log* logger, struct Except* eh)
 {
     struct passwd* pw = getpwnam(userName);
     if (!pw) {
-        Except_throw(eh, "Failed to set UID, couldn't find user named [%s].", strerror(errno));
+        Except_throw(eh, "Failed to set UID, couldn't find user named [%s].",
+                     strerror(errno));
     }
     if (setuid(pw->pw_uid)) {
         if (errno == EPERM) {

+ 0 - 2
util/Security_admin.c

@@ -20,8 +20,6 @@
 #include "util/log/Log.h"
 #include "util/Security.h"
 
-#define string_strlen
-#include "util/platform/libc/string.h"
 
 struct Context
 {

+ 4 - 4
util/events/libuv/Pipe.c

@@ -15,11 +15,11 @@
 #include "util/events/libuv/UvWrapper.h"
 #include "memory/Allocator.h"
 #include "interface/Interface.h"
-#include "util/platform/libc/strlen.h"
 #include "util/events/Pipe.h"
 #include "util/events/libuv/EventBase_pvt.h"
 #include "util/log/Log.h"
 #include "util/Identity.h"
+#include "util/CString.h"
 #include "wire/Message.h"
 #include "wire/Error.h"
 
@@ -342,9 +342,9 @@ static struct Pipe_pvt* newPipe(struct EventBase* eb,
         #define PREFIX "/tmp/cjdns_pipe_"
     #endif
 
-    char* cname = Allocator_malloc(alloc, strlen(PREFIX)+strlen(name)+1);
-    Bits_memcpy(cname, PREFIX, strlen(PREFIX));
-    Bits_memcpy(cname+strlen(PREFIX), name, strlen(name)+1);
+    char* cname = Allocator_malloc(alloc, CString_strlen(PREFIX)+CString_strlen(name)+1);
+    Bits_memcpy(cname, PREFIX, CString_strlen(PREFIX));
+    Bits_memcpy(cname+CString_strlen(PREFIX), name, CString_strlen(name)+1);
 
     struct Pipe_pvt* out = Allocator_clone(alloc, (&(struct Pipe_pvt) {
         .pub = {

+ 6 - 8
util/log/WriterLog.c

@@ -15,14 +15,12 @@
 
 #include "util/log/WriterLog.h"
 #include "util/log/Log_impl.h"
+#include "util/CString.h"
 #include "io/Writer.h"
 
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdio.h>
-#define string_strlen
-#define string_strrchr
-#include "util/platform/libc/string.h"
 #include <strings.h>
 #include <time.h>
 
@@ -44,20 +42,20 @@ static void print(struct Log* genericLog,
     time_t now;
     time(&now);
     snprintf(timeAndLevelBuff, 64, "%u %s ", (uint32_t) now, Log_nameForLevel(logLevel));
-    Writer_write(log->writer, timeAndLevelBuff, strlen(timeAndLevelBuff));
+    Writer_write(log->writer, timeAndLevelBuff, CString_strlen(timeAndLevelBuff));
 
     // Strip the path to make log lines shorter.
-    //char* lastSlash = strrchr(file, '/');
-    Writer_write(log->writer, file, strlen(file));
+    //char* lastSlash = CString_strrchr(file, '/');
+    Writer_write(log->writer, file, CString_strlen(file));
 
     #define Log_BUFFER_SZ 1024
     char buff[Log_BUFFER_SZ];
     snprintf(buff, Log_BUFFER_SZ, ":%u ", line);
-    Writer_write(log->writer, buff, strlen(buff));
+    Writer_write(log->writer, buff, CString_strlen(buff));
 
     vsnprintf(buff, Log_BUFFER_SZ, format, args);
 
-    size_t length = strlen(buff);
+    size_t length = CString_strlen(buff);
 
     // Some log lines end in \n, others don't.
     if (length < Log_BUFFER_SZ && buff[length - 1] != '\n') {

+ 0 - 330
util/platform/libc/string.h

@@ -1,330 +0,0 @@
-/* vim: set expandtab ts=4 sw=4: */
-/*
- * You may redistribute this program and/or modify it under the terms of
- * the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef string_H
-#define string_H
-
-#undef memcpy
-#ifndef string_memcpy
-    #define memcpy string_internal_memcpy
-#endif
-#undef memmove
-#ifndef string_memmove
-    #define memmove string_internal_memmove
-#endif
-#undef memccpy
-#ifndef string_memccpy
-    #define memccpy string_internal_memccpy
-#endif
-#undef memset
-#ifndef string_memset
-    #define memset string_internal_memset
-#endif
-#undef memcmp
-#ifndef string_memcmp
-    #define memcmp string_internal_memcmp
-#endif
-#undef memchr
-#ifndef string_memchr
-    #define memchr string_internal_memchr
-#endif
-#undef strcpy
-#ifndef string_strcpy
-    #define strcpy string_internal_strcpy
-#endif
-#undef strncpy
-#ifndef string_strncpy
-    #define strncpy string_internal_strncpy
-#endif
-#undef strcat
-#ifndef string_strcat
-    #define strcat string_internal_strcat
-#endif
-#undef strncat
-#ifndef string_strncat
-    #define strncat string_internal_strncat
-#endif
-#undef strncmp
-#ifndef string_strncmp
-    #define strncmp string_internal_strncmp
-#endif
-#undef strcoll
-#ifndef string_strcoll
-    #define strcoll string_internal_strcoll
-#endif
-#undef strxfrm
-#ifndef string_strxfrm
-    #define strxfrm string_internal_strxfrm
-#endif
-#undef strcoll_l
-#ifndef string_strcoll_l
-    #define strcoll_l string_internal_strcoll_l
-#endif
-#undef strxfrm_l
-#ifndef string_strxfrm_l
-    #define strxfrm_l string_internal_strxfrm_l
-#endif
-#undef strdup
-#ifndef string_strdup
-    #define strdup string_internal_strdup
-#endif
-#undef strndup
-#ifndef string_strndup
-    #define strndup string_internal_strndup
-#endif
-#undef strchr
-#ifndef string_strchr
-    #define strchr string_internal_strchr
-#endif
-#undef strrchr
-#ifndef string_strrchr
-    #define strrchr string_internal_strrchr
-#endif
-#undef strcspn
-#ifndef string_strcspn
-    #define strcspn string_internal_strcspn
-#endif
-#undef strspn
-#ifndef string_strspn
-    #define strspn string_internal_strspn
-#endif
-#undef strpbrk
-#ifndef string_strpbrk
-    #define strpbrk string_internal_strpbrk
-#endif
-#undef strstr
-#ifndef string_strstr
-    #define strstr string_internal_strstr
-#endif
-#undef strtok
-#ifndef string_strtok
-    #define strtok string_internal_strtok
-#endif
-#undef strtok_r
-#ifndef string_strtok_r
-    #define strtok_r string_internal_strtok_r
-#endif
-
-#undef strcmp
-#ifndef string_strcmp
-    #define strcmp string_internal_strcmp
-#else
-    // some systems use a macro which relies on strlen.
-    #ifndef string_strlen
-        #define string_strlen
-    #endif
-#endif
-
-#undef strlen
-#ifndef string_strlen
-    #define strlen string_internal_strlen
-#endif
-#undef strnlen
-#ifndef string_strnlen
-    #define strnlen string_internal_strnlen
-#endif
-#undef strerror
-#ifndef string_strerror
-    #define strerror string_internal_strerror
-#endif
-#undef strerror_r
-#ifndef string_strerror_r
-    #define strerror_r string_internal_strerror_r
-#endif
-#undef strerror_l
-#ifndef string_strerror_l
-    #define strerror_l string_internal_strerror_l
-#endif
-#undef bcopy
-#ifndef string_bcopy
-    #define bcopy string_internal_bcopy
-#endif
-#undef bzero
-#ifndef string_bzero
-    #define bzero string_internal_bzero
-#endif
-#undef bcmp
-#ifndef string_bcmp
-    #define bcmp string_internal_bcmp
-#endif
-#undef index
-#ifndef string_index
-    #define index string_internal_index
-#endif
-#undef rindex
-#ifndef string_rindex
-    #define rindex string_internal_rindex
-#endif
-#undef ffs
-#ifndef string_ffs
-    #define ffs string_internal_ffs
-#endif
-#undef strcasecmp
-#ifndef string_strcasecmp
-    #define strcasecmp string_internal_strcasecmp
-#endif
-#undef strncasecmp
-#ifndef string_strncasecmp
-    #define strncasecmp string_internal_strncasecmp
-#endif
-#undef strsep
-#ifndef string_strsep
-    #define strsep string_internal_strsep
-#endif
-#undef strsignal
-#ifndef string_strsignal
-    #define strsignal string_internal_strsignal
-#endif
-#undef stpcpy
-#ifndef string_stpcpy
-    #define stpcpy string_internal_stpcpy
-#endif
-#undef stpncpy
-#ifndef string_stpncpy
-    #define stpncpy string_internal_stpncpy
-#endif
-
-#include <string.h>
-
-#ifndef string_memcpy
-    #undef memcpy
-#endif
-#ifndef string_memmove
-    #undef memmove
-#endif
-#ifndef string_memccpy
-    #undef memccpy
-#endif
-#ifndef string_memset
-    #undef memset
-#endif
-#ifndef string_memcmp
-    #undef memcmp
-#endif
-#ifndef string_memchr
-    #undef memchr
-#endif
-#ifndef string_strcpy
-    #undef strcpy
-#endif
-#ifndef string_strncpy
-    #undef strncpy
-#endif
-#ifndef string_strcat
-    #undef strcat
-#endif
-#ifndef string_strncat
-    #undef strncat
-#endif
-#ifndef string_strcmp
-    #undef strcmp
-#endif
-#ifndef string_strncmp
-    #undef strncmp
-#endif
-#ifndef string_strcoll
-    #undef strcoll
-#endif
-#ifndef string_strxfrm
-    #undef strxfrm
-#endif
-#ifndef string_strcoll_l
-    #undef strcoll_l
-#endif
-#ifndef string_strxfrm_l
-    #undef strxfrm_l
-#endif
-#ifndef string_strdup
-    #undef strdup
-#endif
-#ifndef string_strndup
-    #undef strndup
-#endif
-#ifndef string_strchr
-    #undef strchr
-#endif
-#ifndef string_strrchr
-    #undef strrchr
-#endif
-#ifndef string_strcspn
-    #undef strcspn
-#endif
-#ifndef string_strspn
-    #undef strspn
-#endif
-#ifndef string_strpbrk
-    #undef strpbrk
-#endif
-#ifndef string_strstr
-    #undef strstr
-#endif
-#ifndef string_strtok
-    #undef strtok
-#endif
-#ifndef string_strtok_r
-    #undef strtok_r
-#endif
-#ifndef string_strlen
-    #undef strlen
-#endif
-#ifndef string_strnlen
-    #undef strnlen
-#endif
-#ifndef string_strerror
-    #undef strerror
-#endif
-#ifndef string_strerror_r
-    #undef strerror_r
-#endif
-#ifndef string_strerror_l
-    #undef strerror_l
-#endif
-#ifndef string_bcopy
-    #undef bcopy
-#endif
-#ifndef string_bzero
-    #undef bzero
-#endif
-#ifndef string_bcmp
-    #undef bcmp
-#endif
-#ifndef string_index
-    #undef index
-#endif
-#ifndef string_rindex
-    #undef rindex
-#endif
-#ifndef string_ffs
-    #undef ffs
-#endif
-#ifndef string_strcasecmp
-    #undef strcasecmp
-#endif
-#ifndef string_strncasecmp
-    #undef strncasecmp
-#endif
-#ifndef string_strsep
-    #undef strsep
-#endif
-#ifndef string_strsignal
-    #undef strsignal
-#endif
-#ifndef string_stpcpy
-    #undef stpcpy
-#endif
-#ifndef string_stpncpy
-    #undef stpncpy
-#endif
-
-#endif

+ 0 - 25
util/platform/libc/strlen.h

@@ -1,25 +0,0 @@
-/* vim: set expandtab ts=4 sw=4: */
-/*
- * You may redistribute this program and/or modify it under the terms of
- * the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef strlen_H
-#define strlen_H
-
-#include "util/Gcc.h"
-
-#define strlen(a) __builtin_strlen(a)
-/*Gcc_PURE
-Gcc_NONNULL(1)
-unsigned long strlen(const char* str);*/
-
-#endif

+ 2 - 2
util/platform/netdev/NetPlatform_darwin.c

@@ -85,7 +85,7 @@ static void addIp6Address(const char* interfaceName,
         ((uint8_t*)&mask->sin6_addr)[prefixLen>>3] = 0xff << (8 - (prefixLen%8));
     }
 
-    strncpy(in6_addreq.ifra_name, interfaceName, sizeof(in6_addreq.ifra_name));
+    CString_strncpy(in6_addreq.ifra_name, interfaceName, sizeof(in6_addreq.ifra_name));
 
     /* do the actual assignment ioctl */
     int s = socket(AF_INET6, SOCK_DGRAM, 0);
@@ -133,7 +133,7 @@ void NetPlatform_setMTU(const char* interfaceName,
 
     struct ifreq ifRequest;
 
-    strncpy(ifRequest.ifr_name, interfaceName, IFNAMSIZ);
+    CString_strncpy(ifRequest.ifr_name, interfaceName, IFNAMSIZ);
     ifRequest.ifr_mtu = mtu;
 
     Log_info(logger, "Setting MTU for device [%s] to [%u] bytes.", interfaceName, mtu);

+ 1 - 2
util/platform/netdev/NetPlatform_freebsd.c

@@ -16,7 +16,6 @@
 #include "exception/Except.h"
 #include "interface/Interface.h"
 #include "util/AddrTools.h"
-#include "util/Bits.h"
 
 #include <errno.h>
 #include <ctype.h>
@@ -75,7 +74,7 @@ static void addIp6Address(const char* interfaceName,
         Except_throw(eh, "bad IPv6 address [%s]", gai_strerror(err));
     }
 
-    Bits_memcpy(&in6_addreq.ifra_addr, result->ai_addr, result->ai_addrlen);
+    memcpy(&in6_addreq.ifra_addr, result->ai_addr, result->ai_addrlen);
 
     /* turn the prefixlen into a mask, and add it to the request */
     struct sockaddr_in6* mask = &in6_addreq.ifra_prefixmask;

+ 7 - 12
util/platform/netdev/NetPlatform_linux.c

@@ -13,13 +13,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include "util/platform/netdev/NetPlatform.h"
-#define string_strncpy
-#define string_strlen
-#define string_strerror
-#include "util/platform/libc/string.h"
 #include "util/platform/Sockaddr.h"
-#include "util/Bits.h"
 
+#include <string.h>
 #include <errno.h>
 #include <stdio.h>
 #include <sys/ioctl.h>
@@ -31,7 +27,6 @@
 #include <stddef.h>
 #include <net/if.h>
 #include <arpa/inet.h>
-
 #include <linux/if.h>
 
 /**
@@ -68,7 +63,7 @@ static int socketForIfName(const char* interfaceName,
         Except_throw(eh, "socket() [%s]", strerror(errno));
     }
 
-    Bits_memset(ifRequestOut, 0, sizeof(struct ifreq));
+    memset(ifRequestOut, 0, sizeof(struct ifreq));
     strncpy(ifRequestOut->ifr_name, interfaceName, IFNAMSIZ);
 
     if (ioctl(s, SIOCGIFINDEX, ifRequestOut) < 0) {
@@ -124,7 +119,7 @@ void NetPlatform_addAddress(const char* interfaceName,
             .ifr6_ifindex = ifIndex,
             .ifr6_prefixlen = prefixLen
         };
-        Bits_memcpyConst(&ifr6.ifr6_addr, address, 16);
+        memcpy(&ifr6.ifr6_addr, address, 16);
 
         if (ioctl(s, SIOCSIFADDR, &ifr6) < 0) {
             int err = errno;
@@ -135,8 +130,8 @@ void NetPlatform_addAddress(const char* interfaceName,
 
     } else if (addrFam == Sockaddr_AF_INET) {
         struct sockaddr_in sin = { .sin_family = AF_INET, .sin_port = 0 };
-        Bits_memcpyConst(&sin.sin_addr.s_addr, address, 4);
-        Bits_memcpyConst(&ifRequest.ifr_addr, &sin, sizeof(struct sockaddr));
+        memcpy(&sin.sin_addr.s_addr, address, 4);
+        memcpy(&ifRequest.ifr_addr, &sin, sizeof(struct sockaddr));
 
         if (ioctl(s, SIOCSIFADDR, &ifRequest) < 0) {
             int err = errno;
@@ -146,8 +141,8 @@ void NetPlatform_addAddress(const char* interfaceName,
 
         uint32_t x = ~0 << (32 - prefixLen);
         x = Endian_hostToBigEndian32(x);
-        Bits_memcpyConst(&sin.sin_addr, &x, 4);
-        Bits_memcpyConst(&ifRequest.ifr_addr, &sin, sizeof(struct sockaddr_in));
+        memcpy(&sin.sin_addr, &x, 4);
+        memcpy(&ifRequest.ifr_addr, &sin, sizeof(struct sockaddr_in));
 
         if (ioctl(s, SIOCSIFNETMASK, &ifRequest) < 0) {
             int err = errno;

+ 3 - 4
util/platform/netdev/NetPlatform_openbsd.c

@@ -16,7 +16,6 @@
 #include "interface/Interface.h"
 #include "util/platform/netdev/NetPlatform.h"
 #include "util/AddrTools.h"
-#include "util/Bits.h"
 
 #include <errno.h>
 #include <ctype.h>
@@ -73,7 +72,7 @@ static void addIp6Address(const char* interfaceName,
         Except_throw(eh, "bad IPv6 address [%s]", gai_strerror(err));
     }
 
-    Bits_memcpy(&in6_addreq.ifra_addr, result->ai_addr, result->ai_addrlen);
+    memcpy(&in6_addreq.ifra_addr, result->ai_addr, result->ai_addrlen);
 
     /* turn the prefixlen into a mask, and add it to the request */
     struct sockaddr_in6* mask = &in6_addreq.ifra_prefixmask;
@@ -91,7 +90,7 @@ static void addIp6Address(const char* interfaceName,
         *cp = 0xff << (8 - len);
     }
 
-    strncpy(in6_addreq.ifra_name, interfaceName, sizeof(in6_addreq.ifra_name));
+    CString_strncpy(in6_addreq.ifra_name, interfaceName, sizeof(in6_addreq.ifra_name));
 
     /* do the actual assignment ioctl */
     int s = socket(AF_INET6, SOCK_DGRAM, 0);
@@ -140,7 +139,7 @@ void NetPlatform_setMTU(const char* interfaceName,
 
     struct ifreq ifRequest;
 
-    strncpy(ifRequest.ifr_name, interfaceName, IFNAMSIZ);
+    CString_strncpy(ifRequest.ifr_name, interfaceName, IFNAMSIZ);
     ifRequest.ifr_mtu = mtu;
 
     Log_info(logger, "Setting MTU for device [%s] to [%u] bytes.", interfaceName, mtu);

+ 4 - 5
util/platform/netdev/NetPlatform_sunos.c

@@ -15,7 +15,6 @@
 #include "util/platform/netdev/NetPlatform.h"
 #include "util/Assert.h"
 #include "util/platform/Sockaddr.h"
-#include "util/Bits.h"
 
 #include <errno.h>
 #include <stdio.h>
@@ -80,8 +79,8 @@ static void setupRoute(const uint8_t address[16],
         }
     };
 
-    Bits_memcpyConst(&rm.dest.sin6_addr, address, 16);
-    Bits_memcpyConst(&rm.gateway.sin6_addr, address, 16);
+    memcpy(&rm.dest.sin6_addr, address, 16);
+    memcpy(&rm.gateway.sin6_addr, address, 16);
     maskForPrefix((uint8_t*) &rm.netmask.sin6_addr, prefixLen);
 
     int sock = socket(PF_ROUTE, SOCK_RAW, 0);
@@ -123,7 +122,7 @@ static void addIp6Address(const char* interfaceName,
     struct sockaddr_in6* sin6 = (struct sockaddr_in6 *) &ifr.lifr_addr;
     maskForPrefix((uint8_t*) sin6->sin6_addr.s6_addr, prefixLen);
     ifr.lifr_addr.ss_family = AF_INET6;
-    strncpy(ifr.lifr_name, interfaceName, LIFNAMSIZ);
+    CString_strncpy(ifr.lifr_name, interfaceName, LIFNAMSIZ);
 
     int udpSock = socket(AF_INET6, SOCK_DGRAM, 0);
     if (udpSock < 0) {
@@ -133,7 +132,7 @@ static void addIp6Address(const char* interfaceName,
         // set the netmask.
         error = "ioctl(SIOCSLIFNETMASK) (setting netmask)";
     }
-    Bits_memcpyConst(&sin6->sin6_addr, address, 16);
+    memcpy(&sin6->sin6_addr, address, 16);
     if (!error && ioctl(udpSock, SIOCSLIFADDR, (caddr_t)&ifr) < 0) {
         // set the ip address.
         error = "ioctl(SIOCSLIFADDR) (setting ipv6 address)";

+ 1 - 1
util/platform/netdev/NetPlatform_win32.c

@@ -57,7 +57,7 @@ static NET_LUID getLuid(const char* name, struct Except* eh)
 {
     uint16_t ifName[IF_MAX_STRING_SIZE + 1] = {0};
     WinFail_check(eh,
-        (!MultiByteToWideChar(CP_UTF8, 0, name, strlen(name), ifName, IF_MAX_STRING_SIZE + 1))
+        (!MultiByteToWideChar(CP_UTF8, 0, name, CString_strlen(name), ifName, IF_MAX_STRING_SIZE + 1))
     );
     NET_LUID out;
     WinFail_check(eh, ConvertInterfaceAliasToLuid(ifName, &out));

+ 3 - 5
util/platform/test/Sockaddr_test.c

@@ -12,12 +12,10 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strlen
-#define string_strcmp
 #include "memory/MallocAllocator.h"
 #include "util/platform/Sockaddr.h"
 #include "util/Assert.h"
-#include "util/platform/libc/string.h"
+#include "util/CString.h"
 
 static void expectFailure(char* address)
 {
@@ -32,8 +30,8 @@ static void expectConvert(char* address, char* expectedOutput)
     struct Allocator* alloc = MallocAllocator_new(20000);
     char* outAddr = Sockaddr_print(&ss.addr, alloc);
     Assert_true(outAddr);
-    Assert_true(strlen(outAddr) == strlen(expectedOutput));
-    Assert_true(!strcmp(outAddr, expectedOutput));
+    Assert_true(CString_strlen(outAddr) == CString_strlen(expectedOutput));
+    Assert_true(!CString_strcmp(outAddr, expectedOutput));
     Allocator_free(alloc);
 }
 

+ 0 - 4
util/test/Hex_test.c

@@ -12,12 +12,8 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-#define string_strlen
-#define string_strstr
-#define string_strcmp
 #include "crypto/random/Random.h"
 #include "memory/MallocAllocator.h"
-#include "util/platform/libc/string.h"
 #include "util/Bits.h"
 #include "util/Hex.h"
 #include "util/Assert.h"

+ 2 - 2
util/test/Process_test.c

@@ -138,8 +138,8 @@ int main(int argc, char** argv)
 
     Assert_true(path != NULL);
     #ifdef win32
-        Assert_true(strstr(path, ":\\") == path + 1); /* C:\ */
-        Assert_true(strstr(path, ".exe"));
+        Assert_true(CString_strstr(path, ":\\") == path + 1); /* C:\ */
+        Assert_true(CString_strstr(path, ".exe"));
     #else
         Assert_true(path[0] == '/');
     #endif