nasmlib/file.c: simplify and unify fwriteint*/addr()

The fwriteint*() and fwriteaddr() functions can be trivially unified
by using cpu_to_le*().

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2017-11-29 16:53:52 -08:00
parent b533f545e4
commit 82025ea0e9

View File

@ -50,61 +50,30 @@ void nasm_write(const void *ptr, size_t size, FILE *f)
nasm_fatal(0, "unable to write output: %s", strerror(errno));
}
#ifdef WORDS_LITTLEENDIAN
void fwriteint16_t(uint16_t data, FILE * fp)
{
data = cpu_to_le16(data);
nasm_write(&data, 2, fp);
}
void fwriteint32_t(uint32_t data, FILE * fp)
{
data = cpu_to_le32(data);
nasm_write(&data, 4, fp);
}
void fwriteint64_t(uint64_t data, FILE * fp)
{
data = cpu_to_le64(data);
nasm_write(&data, 8, fp);
}
void fwriteaddr(uint64_t data, int size, FILE * fp)
{
data = cpu_to_le64(data);
nasm_write(&data, size, fp);
}
#else /* not WORDS_LITTLEENDIAN */
void fwriteint16_t(uint16_t data, FILE * fp)
{
char buffer[2], *p = buffer;
WRITESHORT(p, data);
nasm_write(buffer, 2, fp);
}
void fwriteint32_t(uint32_t data, FILE * fp)
{
char buffer[4], *p = buffer;
WRITELONG(p, data);
nasm_write(buffer, 4, fp);
}
void fwriteint64_t(uint64_t data, FILE * fp)
{
char buffer[8], *p = buffer;
WRITEDLONG(p, data);
nasm_write(buffer, 8, fp);
}
void fwriteaddr(uint64_t data, int size, FILE * fp)
{
char buffer[8], *p = buffer;
WRITEADDR(p, data, size);
nasm_write(buffer, size, fp);
}
#endif
void fwritezero(off_t bytes, FILE *fp)
{
size_t blksize;