[PATCH 3/5] tests/futex: Add support for return codes other than 0 and -1 to sprintrc
Eugene Syromyatnikov
evgsyr at gmail.com
Thu Sep 1 15:17:14 UTC 2016
* tests/futex.c (sprintrc): Print the actual return code provided, not
just "0".
---
tests/futex.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/tests/futex.c b/tests/futex.c
index edb5c9d..fb7833c 100644
--- a/tests/futex.c
+++ b/tests/futex.c
@@ -147,11 +147,22 @@ const char *sprintrc(int rc)
{
enum { RES_BUF_SIZE = 4095 };
static char buf[RES_BUF_SIZE];
+ int saved_errno = errno;
+ int ret;
+ /* Common case, making it quick and error-free */
if (rc == 0)
return "0";
- snprintf(buf, sizeof(buf), "-1 %s (%m)", errno2name());
+ ret = snprintf(buf, sizeof(buf), "%d", rc);
+
+ if (ret < 0)
+ perror_msg_and_fail("snprintf");
+ if ((rc != -1) || ((size_t)ret >= sizeof(buf)))
+ return buf;
+
+ errno = saved_errno;
+ snprintf(buf + ret, sizeof(buf) - ret, " %s (%m)", errno2name());
return buf;
}
--
1.7.10.4
More information about the Strace-devel
mailing list