Remove duplicate macro
Add alternative strndup implementation
This commit is contained in:
3
kubernetes/ConfigureChecks.cmake
Normal file
3
kubernetes/ConfigureChecks.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
include(CheckFunctionExists)
|
||||
|
||||
check_function_exists(strndup HAVE_STRNDUP)
|
||||
@@ -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
2
kubernetes/config.h.in
Normal file
@@ -0,0 +1,2 @@
|
||||
/* Define to 1 if you have the `strndup' function. */
|
||||
#cmakedefine HAVE_STRNDUP 1
|
||||
@@ -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")) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user