clang-format and cleanup

This commit is contained in:
Gavin Hayes 2023-02-25 18:09:22 -05:00
parent b0be622915
commit 7ae7d0f1b3
3 changed files with 19 additions and 18 deletions

View file

@ -143,9 +143,11 @@ static int fd_to_mem_fd(const int infd, char *path) {
bool success = readRc != -1;
if (success && (st.st_size > 8) && IsAPEMagic(space)) {
int flags = fcntl(fd, F_GETFD);
if(success = (flags != -1) && (fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC)) != -1) && ape_to_elf(space, st.st_size)) {
if (success = (flags != -1) &&
(fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC)) != -1) &&
ape_to_elf(space, st.st_size)) {
const int newfd = fcntl(fd, F_DUPFD, 9001);
if(newfd != -1) {
if (newfd != -1) {
close(fd);
fd = newfd;
}
@ -153,7 +155,7 @@ static int fd_to_mem_fd(const int infd, char *path) {
}
const int e = errno;
if ((_weaken(munmap)(space, st.st_size) != -1) && success) {
if(path) {
if (path) {
FormatInt32(stpcpy(path, "COSMOPOLITAN_INIT_ZIPOS="), fd);
}
_unassert(readRc == st.st_size);
@ -232,17 +234,13 @@ int fexecve(int fd, char *const argv[], char *const envp[]) {
for (numenvs = 0; envp[numenvs];) ++numenvs;
const size_t desenvs = min(500, max(numenvs + 1, 2));
char *envs[500];
if (envs) {
memcpy(envs, envp, numenvs * sizeof(char *));
envs[numenvs] = path;
envs[numenvs+1] = NULL;
envs[numenvs + 1] = NULL;
fexecve_impl(newfd, argv, envs);
if(!savedErr) {
if (!savedErr) {
savedErr = errno;
}
} else if(!savedErr) {
savedErr = ENOMEM;
}
BEGIN_CANCELLATION_POINT;
BLOCK_SIGNALS;
strace_enabled(-1);
@ -251,7 +249,7 @@ int fexecve(int fd, char *const argv[], char *const envp[]) {
ALLOW_SIGNALS;
END_CANCELLATION_POINT;
} while (0);
if(savedErr) {
if (savedErr) {
errno = savedErr;
}
rc = -1;

View file

@ -69,12 +69,12 @@ struct Zipos *__zipos_get(void) {
static struct Zipos zipos;
uint8_t *map, *base, *cdir;
progpath = getenv("COSMOPOLITAN_INIT_ZIPOS");
if(progpath) {
if (progpath) {
fd = atoi(progpath);
}
if (!once && ((fd != -1) || PLEDGED(RPATH))) {
__zipos_lock();
if(fd == -1) {
if (fd == -1) {
progpath = GetProgramExecutableName();
fd = open(progpath, O_RDONLY);
}

View file

@ -24,11 +24,14 @@ STATIC_YOINK("zip_uri_support");
int main(int argc, char *argv[]) {
int fd = open("/zip/life.elf", O_RDONLY);
if (fd != -1 ) {
if (fd != -1) {
uint8_t buf[4] = {0};
ssize_t readres = read(fd, buf, sizeof(buf));
if (readres == sizeof(buf)) {
if(memcmp(buf, "\x7F""ELF", sizeof(buf)) == 0) {
if (memcmp(buf,
"\x7F"
"ELF",
sizeof(buf)) == 0) {
return 42;
}
}