diff --git a/common/alloc.c b/common/alloc.c index c0e0218b..188c8a66 100644 --- a/common/alloc.c +++ b/common/alloc.c @@ -5,4 +5,5 @@ #include "../sharedbits/alloc_impl.h" #include "../sharedbits/array_impl.h" #include "../sharedbits/strsafe_impl.h" +#include "../sharedbits/strdup_impl.h" #undef sharedbitsPrefix diff --git a/common/controls.c b/common/controls.c index 0b45868f..bf479a6e 100644 --- a/common/controls.c +++ b/common/controls.c @@ -198,5 +198,3 @@ void *uiControlImplData(uiControl *c) } return c->implData; } - -$$ diff --git a/common/uipriv.h b/common/uipriv.h index 4c195d52..89888cae 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -56,6 +56,7 @@ extern bool uiprivSysCheckThread(void); #define uiprivArrayFree(arr) uiprivArrayFreeFull(&(arr)) #define uiprivArrayAt(arr, T, n) (((T *) (arr.buf)) + (n)) #include "../sharedbits/strsafe_header.h" +#include "../sharedbits/strdup_header.h" #undef sharedbitsPrefix // errors.c diff --git a/sharedbits/strdup_header.h b/sharedbits/strdup_header.h new file mode 100644 index 00000000..0833bbc0 --- /dev/null +++ b/sharedbits/strdup_header.h @@ -0,0 +1,8 @@ +// 8 june 2019 +// requires: alloc_header.h + +#include "start.h" + +extern char *sharedbitsPrefixName(Strdup)(const char *s); + +#include "end.h" diff --git a/sharedbits/strdup_impl.h b/sharedbits/strdup_impl.h new file mode 100644 index 00000000..76151f00 --- /dev/null +++ b/sharedbits/strdup_impl.h @@ -0,0 +1,17 @@ +// 8 june 2019 +// requires alloc_header.h and any of the strsafe_* files + +#include "start.h" + +char *sharedbitsPrefixName(Strdup)(const char *s) +{ + char *t; + size_t n; + + n = strlen(s); + t = (char *) sharedbitsPrefixName(Alloc)((n + 1) * sizeof (char), "char[]"); + sharedbitsPrefixName(Strncpy)(t, s, n + 1); + return t; +} + +#include "end.h" diff --git a/test/lib/testingpriv.c b/test/lib/testingpriv.c index 64fd2658..c9c2e5b7 100644 --- a/test/lib/testingpriv.c +++ b/test/lib/testingpriv.c @@ -31,6 +31,12 @@ void testingprivInternalError(const char *fmt, ...) #undef sharedbitsStatic #undef sharedbitsPrefix +#define sharedbitsPrefix testingpriv +#define testingprivStrncpy testingprivImplStrncpy +#include "../../sharedbits/strdup_impl.h" +#undef testingprivStrncpy +#undef sharedbitsPrefix + int testingprivVsnprintf(char *s, size_t n, const char *fmt, va_list ap) { int ret; @@ -52,17 +58,6 @@ int testingprivSnprintf(char *s, size_t n, const char *fmt, ...) return ret; } -char *testingprivStrdup(const char *s) -{ - char *t; - size_t n; - - n = strlen(s); - t = (char *) testingprivAlloc((n + 1) * sizeof (char), "char[]"); - testingprivImplStrncpy(t, s, n + 1); - return t; -} - char *testingprivVsmprintf(const char *fmt, va_list ap) { char *s; diff --git a/test/lib/testingpriv.h b/test/lib/testingpriv.h index f9e41f6f..1021b79f 100644 --- a/test/lib/testingpriv.h +++ b/test/lib/testingpriv.h @@ -19,13 +19,14 @@ sharedbitsPrintfFunc( #define testingprivArrayFree(arr) testingprivArrayFreeFull(&(arr)) #define testingprivArrayAt(arr, T, n) (((T *) (arr.buf)) + (n)) +#include "../../sharedbits/strdup_header.h" + #undef sharedbitsPrefix extern int testingprivVsnprintf(char *s, size_t n, const char *fmt, va_list ap); sharedbitsPrintfFunc( extern int testingprivSnprintf(char *s, size_t n, const char *fmt, ...), 3, 4); -extern char *testingprivStrdup(const char *s); extern char *testingprivVsmprintf(const char *fmt, va_list ap); sharedbitsPrintfFunc( extern char *testingprivSmprintf(const char *fmt, ...),