scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 924b7323d1b84dd30f98e3a03a30d914f5731a5e
parent 4487c528bec486eea97508050d01325bb615b92d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 14 Mar 2018 08:08:18 +0100

[ld/coff32] Add support for coff32 probe()

This function checks if a file is a coff32 object file.

Diffstat:
Mld/Makefile | 4++++
Mld/coff32.c | 36+++++++++++++++++++++++++++++++++---
2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/ld/Makefile b/ld/Makefile @@ -26,6 +26,10 @@ clean: distclean: clean #deps +coff32.c: ../inc/coff32/filehdr.h +coff32.c: ../inc/coff32/scnhdr.h +coff32.c: ../inc/coff32/syms.h +coff32.c: ../inc/scc.h coff32.c: ld.h formats.c: ld.h main.c: ../inc/arg.h diff --git a/ld/coff32.c b/ld/coff32.c @@ -1,22 +1,52 @@ static char sccsid[] = "@(#) ./ld/coff32.c"; +#include <errno.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "../inc/coff32/filehdr.h" +#include "../inc/coff32/scnhdr.h" +#include "../inc/coff32/syms.h" +#include "../inc/scc.h" #include "ld.h" static int -probe(char *fname, char *member, FILE *fp) +pass1(char *fname, char *member, FILE *fp) { } static int -pass1(char *fname, char *member, FILE *fp) +pass2(char *fname, char *member, FILE *fp) { } static int -pass2(char *fname, char *member, FILE *fp) +probe(char *fname, char *member, FILE *fp) { + int c; + int c1, c2; + fpos_t pos; + unsigned short magic; + + fgetpos(fp, &pos); + c1 = getc(fp); + c2 = getc(fp); + fsetpos(fp, &pos); + + if (ferror(fp)) + die("nm: %s: %s", fname, strerror(errno)); + + if (c1 == EOF || c2 == EOF) + return 0; + magic = c1 | c2 << 8; + + switch (magic) { + case COFF_Z80MAGIC: + return 1; + default: + return 0; + } } struct objfile coff32 = {