From 8900d6c8e1438ee2a4a77c8e4d3feab81ee261e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20M=C3=A1rton?= Date: Tue, 30 Jul 2019 00:03:22 +0200 Subject: helpers: Implement strndup() for MinGW MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Provide strndup implementation if compiled with MinGW because it is a POSIX only method Signed-off-by: Miklós Márton Change-Id: If418080bffff1f5961cacf2a300ea9c666682458 Reviewed-on: https://review.coreboot.org/c/flashrom/+/34621 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber --- helpers.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'helpers.c') diff --git a/helpers.c b/helpers.c index cfa9812c..c83cd2cb 100644 --- a/helpers.c +++ b/helpers.c @@ -102,6 +102,20 @@ char* strtok_r(char *str, const char *delim, char **nextp) *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 */ -- cgit v1.2.3