event-parse: Add compatibility for non GNU strerror_r
Rosen Penev
PATCH 1/1 event-parse: Add compatibility for non GNU strerror_r
Needed for libraries like musl that do not implement the GNU variant.
--- traceevent/event-parse.c | 5 +++++ 1 file changed, 5 insertions(+)
traceevent/event-parse.c +5 -0
@@ -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 ; }
Signature · 1 line
2.17.1
Magnus Fromreide
Quoted 1 line · Rosen Penev
Needed for libraries like musl that do not implement the GNU variant.
This patch seems curious.
Quoted 13 lines
Signed-off-by Rosen Penev <rosenp(a)gmail.com>--- traceevent/event-parse.c | 5 +++++ 1 file changed, 5 insertions(+)traceevent/event-parse.c +0
-0@@ -5121,12 +5121,17 @@ int pevent_strerror(struct pevent *pevent __maybe_unused,const char *msg;if (errnum >=0 ) {
traceevent/event-parse.c int pevent_strerror(struct pevent *pevent __maybe_unused, · line 5133
Quoted 10 lines
traceevent/event-parse.c +4
-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);
Was
if (a human readable response is returned from strerror_r)
clobber it with a numeric version of the error
really what you wanted to achieve?
I would rather expect something like
if (errnum >= 0) {
msg = strerror_r(errnum, buf, buflen);
#if defined(__GLIBC__)
if (msg != buf)
strlcpy(buf, msg, buflen);
#endif
}where the #ifdef ends up as a pure optimization if strerror_r is the XSI version.
/MF
Quoted 11 lines
traceevent/event-parse.c +1
-0+#endif return 0 ; }Signature · 6 lines
2.17.1 _______________________________________________ PowerTop mailing list PowerTop(a)lists.01.org https://lists.01.org/mailman/listinfo/powertop
Rosen Penev
Quoted 32 lines · Magnus Fromreide
Quoted 1 line · Rosen Penev
Needed for libraries like musl that do not implement the GNU variant.
This patch seems curious.
Quoted 13 lines
Signed-off-by Rosen Penev <rosenp(a)gmail.com>--- traceevent/event-parse.c | 5 +++++ 1 file changed, 5 insertions(+)traceevent/event-parse.c +0
-0@@ -5121,12 +5121,17 @@ int pevent_strerror(struct pevent *pevent __maybe_unused,const char *msg;if (errnum >=0 ) {traceevent/event-parse.c int pevent_strerror(struct pevent *pevent __maybe_unused, · line 5133
Quoted 10 lines
traceevent/event-parse.c +4
-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);Was
if (a human readable response is returned from
strerror_r)
clobber it with a numeric version of the error
Quoted 6 lines
really what you wanted to achieve?
I would rather expect something like
if (errnum >= 0) { msg = strerror_r(errnum, buf, buflen);
No idea what you mean by this. The XSI strerror_r returns an int, not a char pointer.
Quoted 21 lines
#if defined(__GLIBC__) if (msg != buf) strlcpy(buf, msg, buflen); #endif }where the #ifdef ends up as a pure optimization if
strerror_ris the XSI version./MF
Quoted 11 lines
traceevent/event-parse.c +1
-0+#endif return 0 ; }Signature · 6 lines
2.17.1 _______________________________________________ PowerTop mailing list PowerTop(a)lists.01.org https://lists.01.org/mailman/listinfo/powertop