summaryrefslogtreecommitdiff
path: root/nasmlib.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-11-13 09:37:59 -0800
committerH. Peter Anvin <hpa@zytor.com>2007-11-13 09:37:59 -0800
commitd1fb15c154b99f9ca8d2356fa9057827b0ab89af (patch)
treee6e95a1979107466eadfad29577e278ee1273890 /nasmlib.c
parenta5fb90834aa2e849e67bf45b478d498a6cb72062 (diff)
downloadnasm-d1fb15c154b99f9ca8d2356fa9057827b0ab89af.tar.gz
nasm-d1fb15c154b99f9ca8d2356fa9057827b0ab89af.tar.bz2
nasm-d1fb15c154b99f9ca8d2356fa9057827b0ab89af.zip
Address data is int64_t; simplify writing an address object
Address data is always int64_t even if the size itself is smaller; this was broken on bigendian hosts (still need testing!) Create simple "write sized object" macros.
Diffstat (limited to 'nasmlib.c')
-rw-r--r--nasmlib.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/nasmlib.c b/nasmlib.c
index 170c95f..b89c711 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -363,28 +363,30 @@ int32_t seg_alloc(void)
void fwriteint16_t(int data, FILE * fp)
{
- fputc((int)(data & 255), fp);
- fputc((int)((data >> 8) & 255), fp);
+ char buffer[2], *p = buffer;
+ WRITESHORT(p, data);
+ fwrite(buffer, 1, 2, fp);
}
void fwriteint32_t(int32_t data, FILE * fp)
{
- fputc((int)(data & 255), fp);
- fputc((int)((data >> 8) & 255), fp);
- fputc((int)((data >> 16) & 255), fp);
- fputc((int)((data >> 24) & 255), fp);
+ char buffer[4], *p = buffer;
+ WRITELONG(p, data);
+ fwrite(buffer, 1, 4, fp);
}
void fwriteint64_t(int64_t data, FILE * fp)
{
- fputc((int)(data & 255), fp);
- fputc((int)((data >> 8) & 255), fp);
- fputc((int)((data >> 16) & 255), fp);
- fputc((int)((data >> 24) & 255), fp);
- fputc((int)((data >> 32) & 255), fp);
- fputc((int)((data >> 40) & 255), fp);
- fputc((int)((data >> 48) & 255), fp);
- fputc((int)((data >> 56) & 255), fp);
+ char buffer[8], *p = buffer;
+ WRITEDLONG(p, data);
+ fwrite(buffer, 1, 8, fp);
+}
+
+void fwriteaddr(int64_t data, int size, FILE * fp)
+{
+ char buffer[8], *p = buffer;
+ WRITEADDR(p, data, size);
+ fwrite(buffer, 1, size, fp);
}
void standard_extension(char *inname, char *outname, char *extension,