Skip to content

Commit

Permalink
Add compatibility for non GNU strerror_r.
Browse files Browse the repository at this point in the history
Needed for libraries like musl that do not implement the GNU variant.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
nswamina committed Jul 2, 2019
1 parent 7966ac8 commit c2a52f9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions traceevent/event-parse.c
Expand Up @@ -5121,12 +5121,17 @@ int pevent_strerror(struct pevent *pevent __maybe_unused,
const char *msg;

if (errnum >= 0) {
#if defined(__GLIBC__)
msg = strerror_r(errnum, buf, buflen);
if (msg != buf) {
size_t len = strlen(msg);
memcpy(buf, msg, min(buflen - 1, len));
*(buf + min(buflen - 1, len)) = '\0';
}
#else
if (strerror_r(errnum, buf, buflen))
snprintf(buf, buflen, "errnum %i", errnum);
#endif
return 0;
}

Expand Down

0 comments on commit c2a52f9

Please sign in to comment.