clang-format

This commit is contained in:
Gavin Hayes 2023-02-05 23:38:28 -05:00
parent dc6fd43177
commit 3b2b724ac7
3 changed files with 38 additions and 40 deletions

View file

@ -17,8 +17,8 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/assert.h" #include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/blockcancel.internal.h" #include "libc/calls/blockcancel.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/cp.internal.h" #include "libc/calls/cp.internal.h"
#include "libc/calls/execve-sysv.internal.h" #include "libc/calls/execve-sysv.internal.h"
#include "libc/calls/struct/stat.internal.h" #include "libc/calls/struct/stat.internal.h"
@ -71,35 +71,33 @@ typedef enum {
static bool ape_to_elf(void *ape, const size_t apesize) { static bool ape_to_elf(void *ape, const size_t apesize) {
static const char printftok[] = "printf '"; static const char printftok[] = "printf '";
static const size_t printftoklen = sizeof(printftok)-1; static const size_t printftoklen = sizeof(printftok) - 1;
const char *tok = memmem(ape, apesize, printftok, printftoklen); const char *tok = memmem(ape, apesize, printftok, printftoklen);
if(tok) { if (tok) {
tok += printftoklen; tok += printftoklen;
uint8_t *dest = ape; uint8_t *dest = ape;
PTF_PARSE state = PTF_ANY; PTF_PARSE state = PTF_ANY;
uint8_t value = 0; uint8_t value = 0;
for(;tok < (const char*)(dest+apesize); tok++) { for (; tok < (const char *)(dest + apesize); tok++) {
if((state & (PTF_NUM | PTF_NUM2 | PTF_NUM3)) && (*tok >= '0' && *tok <= '7')) { if ((state & (PTF_NUM | PTF_NUM2 | PTF_NUM3)) &&
(*tok >= '0' && *tok <= '7')) {
value = (value << 3) | (*tok - '0'); value = (value << 3) | (*tok - '0');
state <<= 1; state <<= 1;
if(state & PTF_ANY) { if (state & PTF_ANY) {
*dest++ = value; *dest++ = value;
} }
} } else if (state & PTF_NUM) {
else if(state & PTF_NUM) {
break; break;
} } else {
else { if (state & (PTF_NUM2 | PTF_NUM3)) {
if(state & (PTF_NUM2 | PTF_NUM3)) {
*dest++ = value; *dest++ = value;
} }
if(*tok == '\\') { if (*tok == '\\') {
state = PTF_NUM; state = PTF_NUM;
value = 0; value = 0;
} else if(*tok == '\'') { } else if (*tok == '\'') {
return true; return true;
} } else {
else {
*dest++ = *tok; *dest++ = *tok;
state = PTF_ANY; state = PTF_ANY;
} }
@ -116,7 +114,7 @@ static int ape_fd_to_mem_elf_fd(const int infd, char *path) {
} }
struct stat st; struct stat st;
if(sys_fstat(infd, &st) == -1) { if (sys_fstat(infd, &st) == -1) {
return -1; return -1;
} }
int fd; int fd;
@ -139,8 +137,8 @@ static int ape_fd_to_mem_elf_fd(const int infd, char *path) {
rc = sys_ftruncate(fd, st.st_size, st.st_size); rc = sys_ftruncate(fd, st.st_size, st.st_size);
END_CANCELLATION_POINT; END_CANCELLATION_POINT;
if ((rc != -1) && if ((rc != -1) &&
((space = _weaken(mmap)(0, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, ((space = _weaken(mmap)(0, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED,
0)) != MAP_FAILED)) { fd, 0)) != MAP_FAILED)) {
ssize_t readRc; ssize_t readRc;
BEGIN_CANCELLATION_POINT; BEGIN_CANCELLATION_POINT;
readRc = sys_pread(infd, space, st.st_size, 0, 0); readRc = sys_pread(infd, space, st.st_size, 0, 0);
@ -184,9 +182,9 @@ int fexecve(int fd, char *const argv[], char *const envp[]) {
STRACE("fexecve(%d, %s, %s) → ...", fd, DescribeStringList(argv), STRACE("fexecve(%d, %s, %s) → ...", fd, DescribeStringList(argv),
DescribeStringList(envp)); DescribeStringList(envp));
rc = fexecve_impl(fd, argv, envp); rc = fexecve_impl(fd, argv, envp);
if((errno == ENOEXEC) && (IsLinux() || IsFreebsd()) && IsAPEFd(fd)) { if ((errno == ENOEXEC) && (IsLinux() || IsFreebsd()) && IsAPEFd(fd)) {
const int newfd = ape_fd_to_mem_elf_fd(fd, NULL); const int newfd = ape_fd_to_mem_elf_fd(fd, NULL);
if(newfd != -1) { if (newfd != -1) {
rc = fexecve_impl(newfd, argv, envp); rc = fexecve_impl(newfd, argv, envp);
} }
} }