diff mbox series

[v2,3/5] trace-cmd: Use errno from zlib, if available

Message ID 20220304055658.440904-4-tz.stoyanov@gmail.com (mailing list archive)
State Accepted
Commit 7dbe5054e4a141ff7a2e162db60abd05e8f4f1f6
Headers show
Series trace-cmd: Improvements in compression logic | expand

Commit Message

Tzvetomir Stoyanov (VMware) March 4, 2022, 5:56 a.m. UTC
Some zlib APIs set the errno in case of an error and return Z_ERRNO.
In these cases, errno should not be overwritten by the tarce-cmd zlib
wrappers.

Suggested-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 lib/trace-cmd/trace-compress-zlib.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/trace-cmd/trace-compress-zlib.c b/lib/trace-cmd/trace-compress-zlib.c
index 41342597..fd43d879 100644
--- a/lib/trace-cmd/trace-compress-zlib.c
+++ b/lib/trace-cmd/trace-compress-zlib.c
@@ -20,7 +20,6 @@  static int zlib_compress(const void *in, int in_bytes, void *out, int out_bytes)
 
 	ret = compress2((unsigned char *)out, &obytes,
 			(unsigned char *)in, (unsigned long)in_bytes, Z_BEST_COMPRESSION);
-	errno = 0;
 	switch (ret) {
 	case Z_OK:
 		return obytes;
@@ -33,6 +32,8 @@  static int zlib_compress(const void *in, int in_bytes, void *out, int out_bytes)
 	case Z_STREAM_ERROR:
 		errno = -EINVAL;
 		break;
+	case Z_ERRNO:
+		break;
 	default:
 		errno = -EFAULT;
 		break;
@@ -48,7 +49,6 @@  static int zlib_decompress(const void *in, int in_bytes, void *out, int out_byte
 
 	ret = uncompress((unsigned char *)out, &obytes,
 			 (unsigned char *)in, (unsigned long)in_bytes);
-	errno = 0;
 	switch (ret) {
 	case Z_OK:
 		return obytes;
@@ -61,6 +61,8 @@  static int zlib_decompress(const void *in, int in_bytes, void *out, int out_byte
 	case Z_DATA_ERROR:
 		errno = -EINVAL;
 		break;
+	case Z_ERRNO:
+		break;
 	default:
 		errno = -EFAULT;
 		break;