scc

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

commit d002ec15cf34d032d59872e75afb96bb4eddc4a6
parent 19ec26233d17768b62e8055548523086fa6946f0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 23 Nov 2017 19:52:23 +0100

[lib/scc] Return an error code in myro functions

It is better to return an error code instead of giving this
responsability to the user.

Diffstat:
Minc/myro.h | 13+++++++++----
Mlib/scc/wmyro.c | 32++++++++++++++++----------------
2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/inc/myro.h b/inc/myro.h @@ -1,4 +1,9 @@ +#define MYROHDR_SIZ 48 +#define MYROSECT_SIZ 24 +#define MYROSYM_SIZ 24 +#define MYROREL_SIZ 20 + struct myrohdr { unsigned long format; unsigned long long entry; @@ -35,7 +40,7 @@ struct myrorel { unsigned long long offset; }; -extern size_t writehdr(FILE *fp, struct myrohdr *hdr); -extern size_t writesec(FILE *fp, struct myrosect *sect); -extern size_t writesym(FILE *fp, struct myrosym *sym); -extern size_t writerel(FILE *fp, struct myrorel *rel); +extern int writehdr(FILE *fp, struct myrohdr *hdr); +extern int writesec(FILE *fp, struct myrosect *sect); +extern int writesym(FILE *fp, struct myrosym *sym); +extern int writerel(FILE *fp, struct myrorel *rel); diff --git a/lib/scc/wmyro.c b/lib/scc/wmyro.c @@ -5,11 +5,11 @@ static char sccsid[] = "@(#) ./lib/scc/wmyro.c"; #include "../../inc/scc.h" #include "../../inc/myro.h" -size_t +int writehdr(FILE *fp, struct myrohdr *hdr) { - unsigned char buf[sizeof(*hdr)]; - size_t len; + unsigned char buf[MYROHDR_SIZ]; + int len; len = lpack(buf, "lqqqqq", hdr->format, @@ -20,14 +20,14 @@ writehdr(FILE *fp, struct myrohdr *hdr) hdr->relsize); fwrite(buf, len, 1, fp); - return len; + return (ferror(fp)) ? EOF : len; } -size_t +int writesec(FILE *fp, struct myrosect *sect) { - unsigned char buf[sizeof(*sect)]; - size_t len; + unsigned char buf[MYROSECT_SIZ]; + int len; len = lpack(buf, "lsccqq", sect->name, @@ -38,14 +38,14 @@ writesec(FILE *fp, struct myrosect *sect) sect->len); fwrite(buf, len, 1, fp); - return len; + return (ferror(fp)) ? EOF : len; } -size_t +int writesym(FILE *fp, struct myrosym *sym) { - unsigned char buf[sizeof(*sym)]; - size_t len; + unsigned char buf[MYROSYM_SIZ]; + int len; len = lpack(buf, "llccqq", sym->name, @@ -56,14 +56,14 @@ writesym(FILE *fp, struct myrosym *sym) sym->len); fwrite(buf, len, 1, fp); - return len; + return (ferror(fp)) ? EOF : len; } -size_t +int writerel(FILE *fp, struct myrorel *rel) { - unsigned char buf[sizeof(*rel)]; - size_t len; + unsigned char buf[MYROREL_SIZ]; + int len; len = lpack(buf, "lccccq", rel->id, @@ -74,5 +74,5 @@ writerel(FILE *fp, struct myrorel *rel) rel->offset); fwrite(buf, len, 1, fp); - return len; + return (ferror(fp)) ? EOF : len; }