Miklós Márton has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/34621 )
Change subject: Removed strndup because it is not available in MingW ......................................................................
Removed strndup because it is not available in MingW
Signed-off-by: Miklós Márton martonmiklosqdev@gmail.com Change-Id: If418080bffff1f5961cacf2a300ea9c666682458 --- M libflashrom.c 1 file changed, 10 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/21/34621/1
diff --git a/libflashrom.c b/libflashrom.c index af62002..a1c0a9c 100644 --- a/libflashrom.c +++ b/libflashrom.c @@ -371,6 +371,7 @@ struct flashctx *const flashctx, const struct fmap *const fmap) { int i; + size_t len; struct flashrom_layout *l = get_global_layout();
if (!fmap || !l) @@ -385,8 +386,15 @@ l->entries[l->num_entries].start = fmap->areas[i].offset; l->entries[l->num_entries].end = fmap->areas[i].offset + fmap->areas[i].size - 1; l->entries[l->num_entries].included = false; - l->entries[l->num_entries].name = - strndup((const char *)fmap->areas[i].name, FMAP_STRLEN); + // MingW does not have strndup + len = strlen((const char *)fmap->areas[i].name); + if (len > (FMAP_STRLEN - 1)) + len = (FMAP_STRLEN - 1); + l->entries[l->num_entries].name = malloc(len + 1); + strncpy(l->entries[l->num_entries].name, + (const char *)fmap->areas[i].name, + len); + l->entries[l->num_entries].name[len] = '\0'; if (!l->entries[l->num_entries].name) { msg_gerr("Error adding layout entry: %s\n", strerror(errno)); return 1;
Hello build bot (Jenkins),
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/34621
to look at the new patch set (#2).
Change subject: Removed strndup because it is not available in MinGW ......................................................................
Removed strndup because it is not available in MinGW
Signed-off-by: Miklós Márton martonmiklosqdev@gmail.com Change-Id: If418080bffff1f5961cacf2a300ea9c666682458 --- M flash.h M helpers.c 2 files changed, 15 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/21/34621/2
Hello build bot (Jenkins),
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/34621
to look at the new patch set (#3).
Change subject: Provide strndup implementation if compiled with MinGW because it is a POSIX only method ......................................................................
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 --- M flash.h M helpers.c 2 files changed, 15 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/21/34621/3
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/34621 )
Change subject: Provide strndup implementation if compiled with MinGW because it is a POSIX only method ......................................................................
Patch Set 4: Code-Review+1
(4 comments)
https://review.coreboot.org/c/flashrom/+/34621/4//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/flashrom/+/34621/4//COMMIT_MSG@6 PS4, Line 6: Add a summary line, e.g. `helpers: Implement strndup() for MinGW`
https://review.coreboot.org/c/flashrom/+/34621/4/helpers.c File helpers.c:
https://review.coreboot.org/c/flashrom/+/34621/4/helpers.c@109 PS4, Line 109: if(strlen(src) > maxlen) { Add a space after `if`, please.
https://review.coreboot.org/c/flashrom/+/34621/4/helpers.c@111 PS4, Line 111: if((retbuf = malloc( 1 + maxlen )) != NULL) { Also here. And no spaces inside the parenteses (i.e. `malloc(1 + maxlen)`).
https://review.coreboot.org/c/flashrom/+/34621/4/helpers.c@112 PS4, Line 112: memcpy( retbuf, src, maxlen ); spaces...
Hello build bot (Jenkins), Nico Huber,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/34621
to look at the new patch set (#5).
Change subject: helpers: Implement strndup() for MinGW ......................................................................
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 --- M flash.h M helpers.c 2 files changed, 15 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/21/34621/5
Miklós Márton has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/34621 )
Change subject: helpers: Implement strndup() for MinGW ......................................................................
Patch Set 5:
(3 comments)
Thanks for the review!
https://review.coreboot.org/c/flashrom/+/34621/4//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/flashrom/+/34621/4//COMMIT_MSG@6 PS4, Line 6:
Add a summary line, e.g. […]
Done
https://review.coreboot.org/c/flashrom/+/34621/4/helpers.c File helpers.c:
https://review.coreboot.org/c/flashrom/+/34621/4/helpers.c@109 PS4, Line 109: if(strlen(src) > maxlen) {
Add a space after `if`, please.
Done
https://review.coreboot.org/c/flashrom/+/34621/4/helpers.c@112 PS4, Line 112: memcpy( retbuf, src, maxlen );
spaces...
Done
Miklós Márton has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/34621 )
Change subject: helpers: Implement strndup() for MinGW ......................................................................
Patch Set 5:
(1 comment)
https://review.coreboot.org/c/flashrom/+/34621/4/helpers.c File helpers.c:
https://review.coreboot.org/c/flashrom/+/34621/4/helpers.c@111 PS4, Line 111: if((retbuf = malloc( 1 + maxlen )) != NULL) {
Also here. And no spaces inside the parenteses (i.e. `malloc(1 + maxlen)`).
Done
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/34621 )
Change subject: helpers: Implement strndup() for MinGW ......................................................................
Patch Set 5: Code-Review+2
Nico Huber has submitted this change. ( https://review.coreboot.org/c/flashrom/+/34621 )
Change subject: helpers: Implement strndup() for MinGW ......................................................................
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 --- M flash.h M helpers.c 2 files changed, 15 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Nico Huber: Looks good to me, approved
diff --git a/flash.h b/flash.h index c1d8980..1a9bd9f 100644 --- a/flash.h +++ b/flash.h @@ -314,6 +314,7 @@ void reverse_bytes(uint8_t *dst, const uint8_t *src, size_t length); #ifdef __MINGW32__ char* strtok_r(char *str, const char *delim, char **nextp); +char *strndup(const char *str, size_t size); #endif #if defined(__DJGPP__) || (!defined(__LIBPAYLOAD__) && !defined(HAVE_STRNLEN)) size_t strnlen(const char *str, size_t n); 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 */