[Drbd-dev] [PATCH 2/2] drbdmeta: drop usage of strndupa() which is not provided by musl

Christophe Vu-Brugier cvubrugier at fastmail.fm
Wed Sep 9 15:16:07 CEST 2015


The musl C library does not support strndupa() which is an
implementation of strndup() that allocates its buffer on the stack.

This patch changes drbd_str_disk() to compute the string length up to
the first slash (if any) and use the length to match the string with
the state names.

Signed-off-by: Christophe Vu-Brugier <cvubrugier at fastmail.fm>
---
 user/shared/drbdmeta.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/user/shared/drbdmeta.c b/user/shared/drbdmeta.c
index 82482e0..d700747 100644
--- a/user/shared/drbdmeta.c
+++ b/user/shared/drbdmeta.c
@@ -4819,17 +4819,17 @@ static enum drbd_disk_state drbd_str_disk(const char *str)
 	/* drbd 8.4 and earlier provide "Local/Remote"
 	 * drbd 9. only "Local". */
 	const char *slash = strchr(str, '/');
-	const char *tmp;
+	size_t len;
 	int n;
 
 	if (slash)
-		tmp = strndupa(str, slash - str);
+		len = slash - str;
 	else
-		tmp = str;
+		len = strlen(str);
 
 	for (n = 0; n < drbd_disk_state_names.size; n++) {
 		if (drbd_disk_state_names.names[n] &&
-		    !strcmp(tmp, drbd_disk_state_names.names[n]))
+		    !strncmp(str, drbd_disk_state_names.names[n], len))
 			return (enum drbd_disk_state)n;
 	}
 	if (!strcmp(str, "Unconfigured"))
-- 
2.5.0



More information about the drbd-dev mailing list