Remove duplicate macro

Add alternative strndup implementation
This commit is contained in:
Ahmed Yarub Hani Al Nuaimi
2021-09-06 18:18:47 -03:00
parent 4221f70114
commit 1d5348f99e
6 changed files with 36 additions and 3 deletions

View File

@@ -0,0 +1,3 @@
include(CheckFunctionExists)
check_function_exists(strndup HAVE_STRNDUP)

View File

@@ -1,3 +1,7 @@
# config.h checks
include(ConfigureChecks.cmake)
configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
list(APPEND SRCS
config/kube_config_model.c
config/kube_config_yaml.c
@@ -27,5 +31,5 @@ list(APPEND HDRS
websocket/kube_exec.h
include/generic.h)
find_package(libwebsockets REQUIRED)
find_package(libwebsockets CONFIG REQUIRED)
find_package(yaml CONFIG REQUIRED)

2
kubernetes/config.h.in Normal file
View File

@@ -0,0 +1,2 @@
/* Define to 1 if you have the `strndup' function. */
#cmakedefine HAVE_STRNDUP 1

View File

@@ -13,8 +13,6 @@
#endif
#include "../include/apiClient.h"
#define KUBE_CONFIG_TEMPFILE_NAME_TEMPLATE "/tmp/kubeconfig-XXXXXX"
static bool is_cert_or_key_base64_encoded(const char *data)
{
if (NULL == strstr(data, "BEGIN")) {

View File

@@ -14,6 +14,10 @@ typedef struct genericClient_t {
char *resourcePlural;
} genericClient_t;
#if !defined(HAVE_STRNDUP)
char *strndup(const char *s, size_t n);
#endif /* ! HAVE_STRNDUP */
genericClient_t* genericClient_create(apiClient_t *client, const char *apiGroup, const char* apiVersion, const char* resourcePlural);
void genericClient_free(genericClient_t* client);

View File

@@ -1,6 +1,28 @@
#include "../include/apiClient.h"
#include "../include/generic.h"
// based on https://github.com/libssh/libssh-mirror/commit/247983e9820fd264cb5a59c14cc12846c028bd08#diff-744295d01685fa411dbfd78679ea20b51dfa4ac7d2d722df53f3d86d728493f8
#if !defined(HAVE_STRNDUP)
char *strndup(const char *s, size_t n)
{
char *x = NULL;
if (n + 1 < n) {
return NULL;
}
x = malloc(n + 1);
if (x == NULL) {
return NULL;
}
memcpy(x, s, n);
x[n] = '\0';
return x;
}
#endif /* ! HAVE_STRNDUP */
genericClient_t* genericClient_create(apiClient_t *client, const char *apiGroup, const char* apiVersion, const char* resourcePlural) {
genericClient_t *result = malloc(sizeof(genericClient_t));
result->client = client;