mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-28 07:23:43 +02:00
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>
This commit is contained in:
parent
7d6b526ef5
commit
8900d6c8e1
1
flash.h
1
flash.h
@ -314,6 +314,7 @@ uint8_t reverse_byte(uint8_t x);
|
|||||||
void reverse_bytes(uint8_t *dst, const uint8_t *src, size_t length);
|
void reverse_bytes(uint8_t *dst, const uint8_t *src, size_t length);
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
char* strtok_r(char *str, const char *delim, char **nextp);
|
char* strtok_r(char *str, const char *delim, char **nextp);
|
||||||
|
char *strndup(const char *str, size_t size);
|
||||||
#endif
|
#endif
|
||||||
#if defined(__DJGPP__) || (!defined(__LIBPAYLOAD__) && !defined(HAVE_STRNLEN))
|
#if defined(__DJGPP__) || (!defined(__LIBPAYLOAD__) && !defined(HAVE_STRNLEN))
|
||||||
size_t strnlen(const char *str, size_t n);
|
size_t strnlen(const char *str, size_t n);
|
||||||
|
14
helpers.c
14
helpers.c
@ -102,6 +102,20 @@ char* strtok_r(char *str, const char *delim, char **nextp)
|
|||||||
*nextp = str;
|
*nextp = str;
|
||||||
return ret;
|
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
|
#endif
|
||||||
|
|
||||||
/* There is no strnlen in DJGPP */
|
/* There is no strnlen in DJGPP */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user