aboutsummaryrefslogtreecommitdiffstats
path: root/executor/common_zlib.h
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-11-22 12:08:21 +0100
committerDmitry Vyukov <dvyukov@google.com>2022-11-23 09:09:39 +0100
commit1c50689b39eb028d91a28951b8300b7970a2aca5 (patch)
tree84cd6ab7f5fb0d87ed334a59ad3949df35afb5ab /executor/common_zlib.h
parentcaddc6cbcef9933a4539a06714df006e0c5ac7b2 (diff)
executor: fix puff_zlib_to_file signature
In executor code we commonly use the syscall interface for functions: return -1 on erorr and set errno. Use this interface for puff_zlib_to_file.
Diffstat (limited to 'executor/common_zlib.h')
-rw-r--r--executor/common_zlib.h21
1 files changed, 11 insertions, 10 deletions
diff --git a/executor/common_zlib.h b/executor/common_zlib.h
index e122f2dd0..d5fd480d3 100644
--- a/executor/common_zlib.h
+++ b/executor/common_zlib.h
@@ -499,6 +499,7 @@ static int puff(
//% END CODE DERIVED FROM puff.{c,h}
+#include <errno.h>
#include <sys/mman.h>
#define ZLIB_HEADER_WIDTH 2 // Two-byte zlib header width.
@@ -509,27 +510,27 @@ static int puff_zlib_to_file(
unsigned long destlen)
{
// Ignore zlib header.
- if (sourcelen < ZLIB_HEADER_WIDTH)
- return -12; // use next available negative return value
+ if (sourcelen < ZLIB_HEADER_WIDTH) {
+ errno = EMSGSIZE;
+ return -1;
+ }
source += ZLIB_HEADER_WIDTH;
sourcelen -= ZLIB_HEADER_WIDTH;
// Memory-map destination file dest_fd.
void* ret = mmap(0, destlen, PROT_WRITE | PROT_READ, MAP_SHARED, dest_fd, 0);
if (ret == MAP_FAILED)
- return -13; // use next available negative return value
+ return -1;
unsigned char* dest = (unsigned char*)ret;
// Inflate source array to destination file.
unsigned long destlen_copy = destlen; // copy destlen as puff() may modify it
int err = puff(dest, &destlen_copy, source, &sourcelen);
- if (err)
- return err;
+ if (err) {
+ errno = -err;
+ return -1;
+ }
// Unmap memory-mapped region
- err = munmap(dest, destlen);
- if (err)
- return -14; // use next available negative return value
-
- return 0;
+ return munmap(dest, destlen);
}