Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c47fa902 authored by Terry Guan's avatar Terry Guan Committed by Automerger Merge Worker
Browse files

Merge "read() can return fewer bytes than requested" into main am: 5ce7c6a4

parents 4b6c8379 5ce7c6a4
Loading
Loading
Loading
Loading
+7 −12
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@
#include <private/android_filesystem_config.h>
#include <private/fs_config.h>

#include <android-base/file.h>
#include <string>

/* NOTES
**
** - see https://www.kernel.org/doc/Documentation/early-userspace/buffer-format.txt
@@ -212,20 +215,12 @@ static void _archive(char *in, char *out, int ilen, int olen)
    if(lstat(in, &s)) err(1, "could not stat '%s'", in);

    if(S_ISREG(s.st_mode)){
        int fd = open(in, O_RDONLY);
        if(fd < 0) err(1, "cannot open '%s' for read", in);

        char* tmp = (char*) malloc(s.st_size);
        if(tmp == 0) errx(1, "cannot allocate %zd bytes", s.st_size);

        if(read(fd, tmp, s.st_size) != s.st_size) {
            err(1, "cannot read %zd bytes", s.st_size);
        std::string content;
        if (!android::base::ReadFileToString(in, &content)) {
            err(1, "cannot read '%s'", in);
        }

        _eject(&s, out, olen, tmp, s.st_size);

        free(tmp);
        close(fd);
        _eject(&s, out, olen, content.data(), content.size());
    } else if(S_ISDIR(s.st_mode)) {
        _eject(&s, out, olen, 0, 0);
        _archive_dir(in, out, ilen, olen);