Changeset: 736219606d8d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/736219606d8d
Modified Files:
clients/mapiclient/dump.c
cmake/monetdb-defines.cmake
monetdb_config.h.in
Branch: Dec2025
Log Message:
Use strndup, and if it isn't available, we use our own implementation.
diffs (88 lines):
diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -1545,11 +1545,9 @@ describe_sequence(Mapi mid, const char *
if (p != NULL) {
size_t len = p - tname;
- sname = malloc(len+1);
+ sname = strndup(tname, len);
if (sname == NULL)
goto bailout;
- strcpy_len(sname, tname, len);
- sname[len] = 0;
tname += len + 1;
} else if ((sname = get_schema(mid)) == NULL) {
return 1;
@@ -2108,14 +2106,11 @@ dump_table(Mapi mid, const char *schema,
if (p != NULL) {
size_t len = p - tname;
- sname = malloc(len+1);
+ sname = strndup(tname, len);
if (sname == NULL) {
fprintf(stderr, "malloc failure\n");
return 1;
}
- strcpy_len(sname, tname, len);
- sname[len] = 0;
-
tname += len + 1;
} else if ((sname = get_schema(mid)) == NULL) {
return 1;
diff --git a/cmake/monetdb-defines.cmake b/cmake/monetdb-defines.cmake
--- a/cmake/monetdb-defines.cmake
+++ b/cmake/monetdb-defines.cmake
@@ -101,6 +101,8 @@ function(monetdb_configure_defines)
check_function_exists("shutdown" HAVE_SHUTDOWN)
check_function_exists("sigaction" HAVE_SIGACTION)
check_function_exists("siglongjmp" HAVE_SIGLONGJMP)
+ check_function_exists("strndup" HAVE_STRNDUP)
+ check_function_exists("strnlen" HAVE_STRNLEN)
check_function_exists("strptime" HAVE_STRPTIME)
check_symbol_exists("sysconf" "unistd.h" HAVE_SYSCONF)
check_function_exists("task_info" HAVE_TASK_INFO)
diff --git a/monetdb_config.h.in b/monetdb_config.h.in
--- a/monetdb_config.h.in
+++ b/monetdb_config.h.in
@@ -157,6 +157,8 @@
#cmakedefine HAVE_SHUTDOWN 1
#cmakedefine HAVE_SIGACTION 1
#cmakedefine HAVE_SIGLONGJMP 1
+#cmakedefine HAVE_STRNDUP 1
+#cmakedefine HAVE_STRNLEN 1
#cmakedefine HAVE_STRPTIME 1
#cmakedefine HAVE_SYSCONF 1
#cmakedefine HAVE_TASK_INFO 1
@@ -386,6 +388,31 @@ typedef __uint128_t uhge;
#define STRERROR_R_CHARP 1
#endif
+#ifndef HAVE_STRNLEN
+static inline size_t
+strnlen(const char *s, size_t n)
+{
+ for (size_t i = 0; i < n; i++)
+ if (s[i] == 0)
+ return i;
+ return n;
+}
+#endif
+
+#ifndef HAVE_STRNDUP
+static inline char *
+strndup(const char *s, size_t n)
+{
+ n = strnlen(s, n);
+ char *p = malloc(n + 1);
+ if (p != NULL) {
+ memcpy(p, s, n);
+ p[n] = '\0';
+ }
+ return p;
+}
+#endif
+
#ifdef _MSC_VER
#define strdup(s) _strdup(s)
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]