ref: 28bcaf2f4432e8d4ec3b224cf99cf4a19c60bb1a
parent: 7bc957e955f3f89ebf7781d5e631996564c87292
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Nov 23 14:52:23 EST 2017
[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.
--- 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 @@
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);
--- a/lib/scc/wmyro.c
+++ b/lib/scc/wmyro.c
@@ -5,11 +5,11 @@
#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 @@
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 @@
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 @@
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 @@
rel->offset);
fwrite(buf, len, 1, fp);
- return len;
+ return (ferror(fp)) ? EOF : len;
}