summaryrefslogtreecommitdiff
path: root/nasmlib.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-02-09 11:03:33 +0100
committerH. Peter Anvin <hpa@zytor.com>2009-02-21 17:24:08 -0800
commit999868f06f49ec6450872f224a7cc0a43214b063 (patch)
tree30f34b5c0133c948654ebcb386f0b53127d4309d /nasmlib.c
parent04616f4e85d7c5c8501432f7124cf15f440aeae1 (diff)
downloadnasm-999868f06f49ec6450872f224a7cc0a43214b063.tar.gz
Unify all-zero buffers; add fwritezero()
We have a number of all-zero buffers in the code. Put a single all-zero buffer in nasmlib.c. Additionally, add fwritezero() which can be used to write an arbitrary number of all-zero bytes; this prevents the situation where the all-zero buffer is simply too small.
Diffstat (limited to 'nasmlib.c')
-rw-r--r--nasmlib.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/nasmlib.c b/nasmlib.c
index 91eeb2ff..34dbbcf5 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -25,6 +25,9 @@ efunc nasm_malloc_error; /* Exported for the benefit of vsnprintf.c */
static FILE *logfp;
#endif
+/* Uninitialized -> all zero by C spec */
+const uint8_t zero_buffer[ZERO_BUF_SIZE];
+
/*
* Prepare a table of tolower() results. This avoids function calls
* on some platforms.
@@ -454,6 +457,26 @@ void fwriteaddr(uint64_t data, int size, FILE * fp)
#endif
+size_t fwritezero(size_t bytes, FILE *fp)
+{
+ size_t count = 0;
+ size_t blksize;
+ size_t rv;
+
+ while (bytes) {
+ blksize = (bytes < ZERO_BUF_SIZE) ? bytes : ZERO_BUF_SIZE;
+
+ rv = fwrite(zero_buffer, 1, blksize, fp);
+ if (!rv)
+ break;
+
+ count += rv;
+ bytes -= rv;
+ }
+
+ return count;
+}
+
void standard_extension(char *inname, char *outname, char *extension,
efunc error)
{