Merge pull request #10994 from BKPepe/libseccomp
[feed/packages.git] / libs / libssh / patches / 0001-misc-Add-strndup-implementation-if-not-provides-by-t.patch
1 From f81ca6161223e3566ce78a427571235fb6848fe9 Mon Sep 17 00:00:00 2001
2 From: Andreas Schneider <asn@cryptomilk.org>
3 Date: Wed, 29 Aug 2018 18:41:15 +0200
4 Subject: [PATCH 1/8] misc: Add strndup implementation if not provides by the
5 OS
6
7 Fixes T112
8
9 Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
10 (cherry picked from commit 247983e9820fd264cb5a59c14cc12846c028bd08)
11 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
12 ---
13 ConfigureChecks.cmake | 1 +
14 config.h.cmake | 3 +++
15 include/libssh/priv.h | 4 ++++
16 src/misc.c | 21 +++++++++++++++++++++
17 4 files changed, 29 insertions(+)
18
19 --- a/ConfigureChecks.cmake
20 +++ b/ConfigureChecks.cmake
21 @@ -115,6 +115,7 @@ endif (NOT WITH_GCRYPT)
22
23 check_function_exists(isblank HAVE_ISBLANK)
24 check_function_exists(strncpy HAVE_STRNCPY)
25 +check_function_exists(strndup HAVE_STRNDUP)
26 check_function_exists(strtoull HAVE_STRTOULL)
27
28 if (NOT WIN32)
29 --- a/config.h.cmake
30 +++ b/config.h.cmake
31 @@ -103,6 +103,9 @@
32 /* Define to 1 if you have the `strncpy' function. */
33 #cmakedefine HAVE_STRNCPY 1
34
35 +/* Define to 1 if you have the `strndup' function. */
36 +#cmakedefine HAVE_STRNDUP 1
37 +
38 /* Define to 1 if you have the `cfmakeraw' function. */
39 #cmakedefine HAVE_CFMAKERAW 1
40
41 --- a/include/libssh/priv.h
42 +++ b/include/libssh/priv.h
43 @@ -43,6 +43,10 @@
44 # endif
45 #endif /* !defined(HAVE_STRTOULL) */
46
47 +#if !defined(HAVE_STRNDUP)
48 +char *strndup(const char *s, size_t n);
49 +#endif /* ! HAVE_STRNDUP */
50 +
51 #ifdef HAVE_BYTESWAP_H
52 #include <byteswap.h>
53 #endif
54 --- a/src/misc.c
55 +++ b/src/misc.c
56 @@ -1028,6 +1028,27 @@ int ssh_match_group(const char *group, c
57 return 0;
58 }
59
60 +#if !defined(HAVE_STRNDUP)
61 +char *strndup(const char *s, size_t n)
62 +{
63 + char *x = NULL;
64 +
65 + if (n + 1 < n) {
66 + return NULL;
67 + }
68 +
69 + x = malloc(n + 1);
70 + if (x == NULL) {
71 + return NULL;
72 + }
73 +
74 + memcpy(x, s, n);
75 + x[n] = '\0';
76 +
77 + return x;
78 +}
79 +#endif /* ! HAVE_STRNDUP */
80 +
81 /** @} */
82
83 /* vim: set ts=4 sw=4 et cindent: */