aboutsummaryrefslogtreecommitdiffstats
path: root/rdoff/rdoff.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2017-04-17 13:52:19 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2017-04-17 13:56:50 -0700
commit8dc965347ddf9caabacc4ca0441efe3a4ec32af8 (patch)
tree39c561c38dab93e90d70a82a1c6180e1571a15c1 /rdoff/rdoff.c
parent74fa0a736ab769dd07ebe3c98b7e94543b558134 (diff)
downloadnasm-8dc965347ddf9caabacc4ca0441efe3a4ec32af8.tar.gz
nasm-8dc965347ddf9caabacc4ca0441efe3a4ec32af8.tar.xz
nasm-8dc965347ddf9caabacc4ca0441efe3a4ec32af8.zip
rdoff: use nasm-provided safe memory allocation and I/O
We already have abort-on-error memory allocation and I/O operations in nasmlib, so use them for rdoff as well. Delete long-since-obsolete rdoff Mkfiles directory. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'rdoff/rdoff.c')
-rw-r--r--rdoff/rdoff.c51
1 files changed, 29 insertions, 22 deletions
diff --git a/rdoff/rdoff.c b/rdoff/rdoff.c
index ef9a5651..a015acdc 100644
--- a/rdoff/rdoff.c
+++ b/rdoff/rdoff.c
@@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 1996-2014 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -47,13 +47,7 @@
#include <string.h>
#include <errno.h>
-#define RDOFF_UTILS
-
-#include "rdoff.h"
-
-#define newstr(str) strcpy(malloc(strlen(str) + 1),str)
-#define newstrcat(s1,s2) strcat(strcpy(malloc(strlen(s1) + strlen(s2) + 1), \
- s1),s2)
+#include "rdfutils.h"
/*
* Comment this out to allow the module to read & write header record types
@@ -72,7 +66,7 @@ static memorybuffer *newmembuf(void)
{
memorybuffer *t;
- t = malloc(sizeof(memorybuffer));
+ t = nasm_malloc(sizeof(memorybuffer));
if (!t)
return NULL;
@@ -134,8 +128,7 @@ static void membufdump(memorybuffer * b, FILE * fp)
if (!b)
return;
- fwrite(b->buffer, 1, b->length, fp);
-
+ nasm_write(b->buffer, b->length, fp);
membufdump(b->next, fp);
}
@@ -151,7 +144,7 @@ static void freemembuf(memorybuffer * b)
if (!b)
return;
freemembuf(b->next);
- free(b);
+ nasm_free(b);
}
/* =========================================================================
@@ -234,6 +227,22 @@ const char *rdf_errors[11] = {
int rdf_errno = 0;
/* ========================================================================
+ * Hook for nasm_error() to work
+ * ======================================================================== */
+static void rdoff_verror(int severity, const char *fmt, va_list val)
+{
+ vfprintf(stderr, fmt, val);
+
+ if ((severity & ERR_MASK) >= ERR_FATAL)
+ exit(1);
+}
+
+void rdoff_init(void)
+{
+ nasm_set_verror(rdoff_verror);
+}
+
+/* ========================================================================
The library functions
======================================================================== */
@@ -326,7 +335,7 @@ int rdfopenhere(rdffile * f, FILE * fp, int *refcount, const char *name)
fseek(f->fp, initpos, SEEK_SET);
f->header_loc = NULL;
- f->name = newstr(name);
+ f->name = nasm_strdup(name);
f->refcount = refcount;
if (refcount)
(*refcount)++;
@@ -339,7 +348,7 @@ int rdfclose(rdffile * f)
fclose(f->fp);
f->fp = NULL;
}
- free(f->name);
+ nasm_free(f->name);
return 0;
}
@@ -510,7 +519,7 @@ void rdfheaderrewind(rdffile * f)
rdf_headerbuf *rdfnewheader(void)
{
- rdf_headerbuf *hb = malloc(sizeof(rdf_headerbuf));
+ rdf_headerbuf *hb = nasm_malloc(sizeof(rdf_headerbuf));
if (hb == NULL)
return NULL;
@@ -589,14 +598,12 @@ int rdfwriteheader(FILE * fp, rdf_headerbuf * h)
{
int32_t l, l2;
- fwrite(RDOFFId, 1, strlen(RDOFFId), fp);
+ nasm_write(RDOFFId, strlen(RDOFFId), fp);
l = membuflength(h->buf);
l2 = l + 14 + 10 * h->nsegments + h->seglength;
- l = translateint32_t(l);
- l2 = translateint32_t(l2);
- fwrite(&l2, 4, 1, fp); /* object length */
- fwrite(&l, 4, 1, fp); /* header length */
+ fwriteint32_t(l, fp);
+ fwriteint32_t(l2, fp);
membufdump(h->buf, fp);
@@ -606,5 +613,5 @@ int rdfwriteheader(FILE * fp, rdf_headerbuf * h)
void rdfdoneheader(rdf_headerbuf * h)
{
freemembuf(h->buf);
- free(h);
+ nasm_free(h);
}