Skip to content

Commit 9ed13ac

Browse files
committed
remove strndupa to build on musl
musl lacks strndupa, and we have attribute cleanup macros, so use them instead.
1 parent 3f0801c commit 9ed13ac

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

systemd/util.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <unistd.h>
3434
#include <net/if.h>
3535

36+
#include "macro.h"
3637
#include "util.h"
3738

3839
int safe_atou(const char *s, unsigned *ret_u) {
@@ -112,7 +113,8 @@ static int assign_address(const char *s,
112113
int parse_sockaddr(const char *s,
113114
union sockaddr_union *addr, unsigned *addr_len) {
114115

115-
char *e, *n;
116+
char *e;
117+
_cleanup_free_ char *n = NULL;
116118
unsigned u;
117119
int r;
118120

@@ -123,7 +125,7 @@ int parse_sockaddr(const char *s,
123125
if (!e)
124126
return -EINVAL;
125127

126-
n = strndupa(s+1, e-s-1);
128+
n = strndup(s+1, e-s-1);
127129

128130
errno = 0;
129131
if (inet_pton(AF_INET6, n, &addr->in6.sin6_addr) <= 0)
@@ -158,7 +160,7 @@ int parse_sockaddr(const char *s,
158160
if (u <= 0 || u > 0xFFFF)
159161
return -EINVAL;
160162

161-
n = strndupa(s, e-s);
163+
n = strndup(s, e-s);
162164
return assign_address(n, u, addr, addr_len);
163165

164166
} else {

0 commit comments

Comments
 (0)