Skip to content

Commit 9271886

Browse files
committed
Refactoring
1 parent a552d1c commit 9271886

File tree

6 files changed

+40
-28
lines changed

6 files changed

+40
-28
lines changed

kubernetes/PreTarget.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ list(APPEND SRCS
1616
watch/watch_util.c
1717
websocket/wsclient.c
1818
websocket/kube_exec.c
19-
src/generic.c)
19+
src/generic.c
20+
src/utils.c)
2021

2122
list(APPEND HDRS
2223
config/kube_config_common.h
@@ -31,7 +32,8 @@ list(APPEND HDRS
3132
watch/watch_util.h
3233
websocket/wsclient.h
3334
websocket/kube_exec.h
34-
include/generic.h)
35+
include/generic.h
36+
src/utils.c)
3537

3638
find_package(libwebsockets CONFIG REQUIRED)
3739
find_package(yaml CONFIG REQUIRED)

kubernetes/config/authn_plugin/authn_plugin_util.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "authn_plugin_util.h"
22
#include <errno.h>
3+
#include "include/utils.h"
34

45
int shc_request(char **p_http_response, int *p_http_response_length, char *type, const char *url, sslConfig_t * sc, list_t * apiKeys, list_t * contentType, char *post_data)
56
{

kubernetes/include/generic.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ typedef struct genericClient_t {
1414
char *resourcePlural;
1515
} genericClient_t;
1616

17-
#if !defined(HAVE_STRNDUP)
18-
char *strndup(const char *s, size_t n);
19-
#endif /* ! HAVE_STRNDUP */
20-
2117
genericClient_t* genericClient_create(apiClient_t *client, const char *apiGroup, const char* apiVersion, const char* resourcePlural);
2218
void genericClient_free(genericClient_t* client);
2319

kubernetes/include/utils.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef UTILS_HPP
2+
#define UTILS_HPP
3+
4+
5+
#if !defined(HAVE_STRNDUP)
6+
char *strndup(const char *s, size_t n);
7+
#endif /* ! HAVE_STRNDUP */
8+
9+
#endif //UTILS_HPP

kubernetes/src/generic.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,6 @@
11
#include "../include/apiClient.h"
22
#include "../include/generic.h"
3-
4-
// based on https://github.com/libssh/libssh-mirror/commit/247983e9820fd264cb5a59c14cc12846c028bd08#diff-744295d01685fa411dbfd78679ea20b51dfa4ac7d2d722df53f3d86d728493f8
5-
#if !defined(HAVE_STRNDUP)
6-
char *strndup(const char *s, size_t n)
7-
{
8-
char *x = NULL;
9-
10-
if (n + 1 < n) {
11-
return NULL;
12-
}
13-
14-
x = malloc(n + 1);
15-
if (x == NULL) {
16-
return NULL;
17-
}
18-
19-
memcpy(x, s, n);
20-
x[n] = '\0';
21-
22-
return x;
23-
}
24-
#endif /* ! HAVE_STRNDUP */
3+
#include "../include/utils.h"
254

265
genericClient_t* genericClient_create(apiClient_t *client, const char *apiGroup, const char* apiVersion, const char* resourcePlural) {
276
genericClient_t *result = malloc(sizeof(genericClient_t));

kubernetes/src/utils.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <stdlib.h>
2+
#include "../include/utils.h"
3+
#include <string.h>
4+
5+
// based on https://github.com/libssh/libssh-mirror/commit/247983e9820fd264cb5a59c14cc12846c028bd08#diff-744295d01685fa411dbfd78679ea20b51dfa4ac7d2d722df53f3d86d728493f8
6+
#if !defined(HAVE_STRNDUP)
7+
char *strndup(const char *s, size_t n)
8+
{
9+
char *x = NULL;
10+
11+
if (n + 1 < n) {
12+
return NULL;
13+
}
14+
15+
x = malloc(n + 1);
16+
if (x == NULL) {
17+
return NULL;
18+
}
19+
20+
memcpy(x, s, n);
21+
x[n] = '\0';
22+
23+
return x;
24+
}
25+
#endif /* ! HAVE_STRNDUP */

0 commit comments

Comments
 (0)