From c0dde0fade6d2b582015816a6f08f9114c919094 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 17 Jan 2021 14:11:59 +0100 Subject: [PATCH] Provide strdup() compat Make strdup() available on all platforms. --- app/meson.build | 12 ++++++++++++ app/src/compat.c | 14 ++++++++++++++ app/src/compat.h | 4 ++++ 3 files changed, 30 insertions(+) create mode 100644 app/src/compat.c diff --git a/app/meson.build b/app/meson.build index 8e77cb93..2dade249 100644 --- a/app/meson.build +++ b/app/meson.build @@ -2,6 +2,7 @@ src = [ 'src/main.c', 'src/adb.c', 'src/cli.c', + 'src/compat.c', 'src/control_msg.c', 'src/controller.c', 'src/decoder.c', @@ -31,6 +32,10 @@ else src += [ 'src/sys/unix/process.c' ] endif +check_functions = [ + 'strdup' +] + cc = meson.get_compiler('c') if not get_option('crossbuild_windows') @@ -86,6 +91,13 @@ endif conf = configuration_data() +foreach f : check_functions + if cc.has_function(f) + define = 'HAVE_' + f.underscorify().to_upper() + conf.set(define, true) + endif +endforeach + # expose the build type conf.set('NDEBUG', get_option('buildtype') != 'debug') diff --git a/app/src/compat.c b/app/src/compat.c new file mode 100644 index 00000000..b3b98bf1 --- /dev/null +++ b/app/src/compat.c @@ -0,0 +1,14 @@ +#include "compat.h" + +#include "config.h" + +#ifndef HAVE_STRDUP +char *strdup(const char *s) { + size_t size = strlen(s) + 1; + char *dup = malloc(size); + if (dup) { + memcpy(dup, s, size); + } + return dup; +} +#endif diff --git a/app/src/compat.h b/app/src/compat.h index 5464589a..9a84a4c1 100644 --- a/app/src/compat.h +++ b/app/src/compat.h @@ -56,4 +56,8 @@ # define SCRCPY_SDL_HAS_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR #endif +#ifndef HAVE_STRDUP +char *strdup(const char *s); +#endif + #endif