aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-12-10 21:11:46 +0100
committerMattias Andrée <maandree@kth.se>2021-12-10 21:11:46 +0100
commitff35af3b422d81143cdd436b9412652bca760a69 (patch)
tree93555000c5100abd391bb1ecb85525dfad5604ce
parentAdd liberror_send_require and liberror_send_short (diff)
downloadliberror-libc-ff35af3b422d81143cdd436b9412652bca760a69.tar.gz
liberror-libc-ff35af3b422d81143cdd436b9412652bca760a69.tar.bz2
liberror-libc-ff35af3b422d81143cdd436b9412652bca760a69.tar.xz
Add strdup
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--Makefile1
-rw-r--r--liberror-libc.h2
-rw-r--r--strdup.c22
3 files changed, 25 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index a9812c1..094eb7b 100644
--- a/Makefile
+++ b/Makefile
@@ -37,6 +37,7 @@ OBJ =\
setenv.o\
shutdown.o\
sockatmark.o\
+ strdup.o\
unsetenv.o
LOBJ = $(OBJ:.o=.lo)
diff --git a/liberror-libc.h b/liberror-libc.h
index 8de6025..108ac19 100644
--- a/liberror-libc.h
+++ b/liberror-libc.h
@@ -58,6 +58,8 @@ int liberror_shutdown(int, int, const char *);
void liberror_shutdown_failed(int, int, const char *);
int liberror_sockatmark(int, const char *);
void liberror_sockatmark_failed(int, const char *);
+char *liberror_strdup(const char *);
+void liberror_strdup_failed(const char *);
int liberror_unsetenv(const char *);
void liberror_unsetenv_failed(const char *);
diff --git a/strdup.c b/strdup.c
new file mode 100644
index 0000000..0b1c8ee
--- /dev/null
+++ b/strdup.c
@@ -0,0 +1,22 @@
+/* See LICENSE file for copyright and license details. */
+#include "internal.h"
+
+
+void
+liberror_strdup_failed(const char *s)
+{
+ liberror_set_error_errno(errno == ENOMEM ? "Out of memory" : "", "strdup", errno);
+ (void) s;
+}
+
+
+char *
+liberror_strdup(const char *s)
+{
+ char *ret = malloc(s);
+ if (ret)
+ return ret;
+ liberror_save_backtrace(NULL);
+ liberror_strdup_failed(s);
+ return NULL;
+}