summaryrefslogtreecommitdiffstats
path: root/helpers.c
diff options
context:
space:
mode:
authorMiklós Márton <martonmiklosqdev@gmail.com>2019-07-30 00:03:22 +0200
committerNico Huber <nico.h@gmx.de>2019-10-04 11:03:46 +0000
commit8900d6c8e1438ee2a4a77c8e4d3feab81ee261e2 (patch)
tree5664d15b2f3ca63f9f96ef3284cbbf5c46499179 /helpers.c
parent7d6b526ef5b7b11f89eee37062e91590f5fa7f43 (diff)
downloadflashrom-8900d6c8e1438ee2a4a77c8e4d3feab81ee261e2.tar.gz
flashrom-8900d6c8e1438ee2a4a77c8e4d3feab81ee261e2.tar.bz2
flashrom-8900d6c8e1438ee2a4a77c8e4d3feab81ee261e2.zip
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>
Diffstat (limited to 'helpers.c')
-rw-r--r--helpers.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/helpers.c b/helpers.c
index cfa9812c2..c83cd2cb0 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 */