summaryrefslogtreecommitdiffstats
path: root/byterun/misc.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2014-04-15 17:09:13 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2014-04-15 17:09:13 +0000
commit774e30e138dc22a5acd6cfac03ae25194ae8cd6e (patch)
tree2acda83264153258c7f978efeae08d260598c023 /byterun/misc.c
parent2fc7ac7e8b95a143b6b38eab28622389cc19001b (diff)
PR#6075: avoid using unsafe C library functions (strcpy, strcat, sprintf).
An ISO C99-compliant C compiler and standard library is now assumed. (Plus special exceptions for MSVC.) In particular, emulation code for 64-bit integer arithmetic was removed, the C compiler must support a 64-bit integer type. git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14607 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun/misc.c')
-rw-r--r--byterun/misc.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/byterun/misc.c b/byterun/misc.c
index 6eeae0f1b..6dc27d5cc 100644
--- a/byterun/misc.c
+++ b/byterun/misc.c
@@ -12,6 +12,8 @@
/***********************************************************************/
#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
#include "config.h"
#include "misc.h"
#include "memory.h"
@@ -121,3 +123,39 @@ void caml_ext_table_free(struct ext_table * tbl, int free_entries)
for (i = 0; i < tbl->size; i++) caml_stat_free(tbl->contents[i]);
caml_stat_free(tbl->contents);
}
+
+CAMLexport char * caml_strdup(const char * s)
+{
+ size_t slen = strlen(s);
+ char * res = caml_stat_alloc(slen + 1);
+ memcpy(res, s, slen + 1);
+ return res;
+}
+
+CAMLexport char * caml_strconcat(int n, ...)
+{
+ va_list args;
+ char * res, * p;
+ size_t len;
+ int i;
+
+ len = 0;
+ va_start(args, n);
+ for (i = 0; i < n; i++) {
+ const char * s = va_arg(args, const char *);
+ len += strlen(s);
+ }
+ va_end(args);
+ res = caml_stat_alloc(len + 1);
+ va_start(args, n);
+ p = res;
+ for (i = 0; i < n; i++) {
+ const char * s = va_arg(args, const char *);
+ size_t l = strlen(s);
+ memcpy(p, s, l);
+ p += l;
+ }
+ va_end(args);
+ *p = 0;
+ return res;
+}