helpers: Implement strndup() for MinGW

Provide strndup implementation if compiled with MinGW because
it is a POSIX only method

Signed-off-by: Miklós Márton <martonmiklosqdev@gmail.com>
Change-Id: If418080bffff1f5961cacf2a300ea9c666682458
Reviewed-on: https://review.coreboot.org/c/flashrom/+/34621
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
diff --git a/helpers.c b/helpers.c
index cfa9812..c83cd2c 100644
--- a/helpers.c
+++ b/helpers.c
@@ -102,6 +102,20 @@
 	*nextp = str;
 	return ret;
 }
+
+/* strndup is a POSIX function not present in MinGW */
+char *strndup(const char *src, size_t maxlen)
+{
+	if (strlen(src) > maxlen) {
+		char *retbuf;
+		if ((retbuf = malloc(1 + maxlen)) != NULL) {
+			memcpy(retbuf, src, maxlen);
+			retbuf[maxlen] = '\0';
+		}
+		return retbuf;
+	}
+	return strdup(src);
+}
 #endif
 
 /* There is no strnlen in DJGPP */