mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 02:38:31 +00:00
Apply clang-format update to repo (#1154)
Commit bc6c183
introduced a bunch of discrepancies between what files
look like in the repo and what clang-format says they should look like.
However, there were already a few discrepancies prior to that. Most of
these discrepancies seemed to be unintentional, but a few of them were
load-bearing (e.g., a #include that violated header ordering needing
something to have been #defined by a 'later' #include.)
I opted to take what I hope is a relatively smooth-brained approach: I
reverted the .clang-format change, ran clang-format on the whole repo,
reapplied the .clang-format change, reran clang-format again, and then
reverted the commit that contained the first run. Thus the full effect
of this PR should only be to apply the changed formatting rules to the
repo, and from skimming the results, this seems to be the case.
My work can be checked by applying the short, manual commits, and then
rerunning the command listed in the autogenerated commits (those whose
messages I have prefixed auto:) and seeing if your results agree.
It might be that the other diffs should be fixed at some point but I'm
leaving that aside for now.
fd '\.c(c|pp)?$' --print0| xargs -0 clang-format -i
This commit is contained in:
parent
342d0c81e5
commit
6e6fc38935
863 changed files with 9201 additions and 4627 deletions
|
@ -179,12 +179,14 @@ static wontreturn void DieOom(void) {
|
|||
|
||||
static void *Calloc(size_t n) {
|
||||
void *p;
|
||||
if (!(p = calloc(1, n))) DieOom();
|
||||
if (!(p = calloc(1, n)))
|
||||
DieOom();
|
||||
return p;
|
||||
}
|
||||
|
||||
static void *Realloc(void *p, size_t n) {
|
||||
if (!(p = realloc(p, n))) DieOom();
|
||||
if (!(p = realloc(p, n)))
|
||||
DieOom();
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -629,10 +631,12 @@ static bool ParseDllImportSymbol(const char *symbol_name,
|
|||
size_t n;
|
||||
char *dll_name;
|
||||
const char *dolla;
|
||||
if (!startswith(symbol_name, "dll$")) return false;
|
||||
if (!startswith(symbol_name, "dll$"))
|
||||
return false;
|
||||
symbol_name += 4;
|
||||
dolla = strchr(symbol_name, '$');
|
||||
if (!dolla) return false;
|
||||
if (!dolla)
|
||||
return false;
|
||||
n = dolla - symbol_name;
|
||||
dll_name = memcpy(Calloc(n + 1), symbol_name, n);
|
||||
*out_dll_name = dll_name;
|
||||
|
@ -682,19 +686,26 @@ static struct Elf *OpenElf(const char *path) {
|
|||
struct Elf *elf;
|
||||
elf = Calloc(sizeof(*elf));
|
||||
elf->path = path;
|
||||
if ((fd = open(path, O_RDONLY)) == -1) DieSys(path);
|
||||
if ((elf->size = lseek(fd, 0, SEEK_END)) == -1) DieSys(path);
|
||||
if ((fd = open(path, O_RDONLY)) == -1)
|
||||
DieSys(path);
|
||||
if ((elf->size = lseek(fd, 0, SEEK_END)) == -1)
|
||||
DieSys(path);
|
||||
elf->map = mmap(0, elf->size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||
if (elf->map == MAP_FAILED) DieSys(path);
|
||||
if (!IsElf64Binary(elf->ehdr, elf->size)) Die(path, "not an elf64 binary");
|
||||
if (elf->map == MAP_FAILED)
|
||||
DieSys(path);
|
||||
if (!IsElf64Binary(elf->ehdr, elf->size))
|
||||
Die(path, "not an elf64 binary");
|
||||
elf->symhdr =
|
||||
GetElfSymbolTable(elf->ehdr, elf->size, SHT_SYMTAB, &elf->symcount);
|
||||
elf->symtab = GetElfSectionAddress(elf->ehdr, elf->size, elf->symhdr);
|
||||
if (!elf->symtab) Die(path, "elf doesn't have symbol table");
|
||||
if (!elf->symtab)
|
||||
Die(path, "elf doesn't have symbol table");
|
||||
elf->strtab = GetElfStringTable(elf->ehdr, elf->size, ".strtab");
|
||||
if (!elf->strtab) Die(path, "elf doesn't have string table");
|
||||
if (!elf->strtab)
|
||||
Die(path, "elf doesn't have string table");
|
||||
elf->secstrs = GetElfSectionNameStringTable(elf->ehdr, elf->size);
|
||||
if (!elf->strtab) Die(path, "elf doesn't have section string table");
|
||||
if (!elf->strtab)
|
||||
Die(path, "elf doesn't have section string table");
|
||||
LoadDllImports(elf);
|
||||
LoadSectionsIntoSegments(elf);
|
||||
close(fd);
|
||||
|
@ -810,14 +821,18 @@ static struct ImagePointer GeneratePe(struct Elf *elf, char *fp, int64_t vp) {
|
|||
// embed the ms-dos stub and/or bios bootloader
|
||||
if (stubpath) {
|
||||
int fd = open(stubpath, O_RDONLY);
|
||||
if (fd == -1) DieSys(stubpath);
|
||||
if (fd == -1)
|
||||
DieSys(stubpath);
|
||||
for (;;) {
|
||||
ssize_t got = read(fd, fp, 512);
|
||||
if (got == -1) DieSys(stubpath);
|
||||
if (!got) break;
|
||||
if (got == -1)
|
||||
DieSys(stubpath);
|
||||
if (!got)
|
||||
break;
|
||||
fp += got;
|
||||
}
|
||||
if (close(fd)) DieSys(stubpath);
|
||||
if (close(fd))
|
||||
DieSys(stubpath);
|
||||
}
|
||||
|
||||
// output portable executable magic
|
||||
|
@ -1083,15 +1098,18 @@ int main(int argc, char *argv[]) {
|
|||
#endif
|
||||
// get program name
|
||||
prog = argv[0];
|
||||
if (!prog) prog = "elf2pe";
|
||||
if (!prog)
|
||||
prog = "elf2pe";
|
||||
// process flags
|
||||
GetOpts(argc, argv);
|
||||
// translate executable
|
||||
struct Elf *elf = OpenElf(argv[optind]);
|
||||
char *buf = memalign(MAX_ALIGN, 134217728);
|
||||
struct ImagePointer ip = GeneratePe(elf, buf, 0x00400000);
|
||||
if (creat(outpath, 0755) == -1) DieSys(elf->path);
|
||||
if (creat(outpath, 0755) == -1)
|
||||
DieSys(elf->path);
|
||||
Pwrite(3, buf, ip.fp - buf, 0);
|
||||
if (close(3)) DieSys(elf->path);
|
||||
if (close(3))
|
||||
DieSys(elf->path);
|
||||
// PrintElf(elf);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue