aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.in3
-rw-r--r--Mkfiles/msvc.mak3
-rw-r--r--Mkfiles/netware.mak3
-rw-r--r--Mkfiles/openwcom.mak3
-rw-r--r--Mkfiles/owlinux.mak3
-rw-r--r--file.c140
-rw-r--r--nasm.h4
-rw-r--r--nasmlib.c95
-rw-r--r--nasmlib.h6
-rw-r--r--rdoff/Makefile.in2
10 files changed, 151 insertions, 111 deletions
diff --git a/Makefile.in b/Makefile.in
index 44ceceb7..2b8a8b0a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -79,7 +79,7 @@ endif
#-- Begin File Lists --#
NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \
raa.$(O) saa.$(O) rbtree.$(O) \
- realpath.$(O) \
+ realpath.$(O) file.$(O) \
float.$(O) insnsa.$(O) insnsb.$(O) \
directiv.$(O) \
assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \
@@ -333,6 +333,7 @@ eval.$(O): eval.c compiler.h config.h directiv.h eval.h float.h insnsi.h \
labels.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
exprlib.$(O): exprlib.c compiler.h config.h directiv.h insnsi.h nasm.h \
nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
+file.$(O): file.c compiler.h config.h nasmlib.h
float.$(O): float.c compiler.h config.h directiv.h float.h insnsi.h nasm.h \
nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
hashtbl.$(O): hashtbl.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak
index 133087dd..eae6cdb0 100644
--- a/Mkfiles/msvc.mak
+++ b/Mkfiles/msvc.mak
@@ -48,7 +48,7 @@ X = .exe
# Edit in Makefile.in, not here!
NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \
raa.$(O) saa.$(O) rbtree.$(O) \
- realpath.$(O) \
+ realpath.$(O) file.$(O) \
float.$(O) insnsa.$(O) insnsb.$(O) \
directiv.$(O) \
assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \
@@ -242,6 +242,7 @@ eval.$(O): eval.c compiler.h directiv.h eval.h float.h insnsi.h labels.h \
nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
exprlib.$(O): exprlib.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \
opflags.h pptok.h preproc.h regs.h tables.h
+file.$(O): file.c compiler.h nasmlib.h
float.$(O): float.c compiler.h directiv.h float.h insnsi.h nasm.h nasmlib.h \
opflags.h pptok.h preproc.h regs.h tables.h
hashtbl.$(O): hashtbl.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak
index 3d40c1c8..676de8d3 100644
--- a/Mkfiles/netware.mak
+++ b/Mkfiles/netware.mak
@@ -32,7 +32,7 @@ O = o
# Edit in Makefile.in, not here!
NASM = nasm.o nasmlib.o ver.o \
raa.o saa.o rbtree.o \
- realpath.o \
+ realpath.o file.o \
float.o insnsa.o insnsb.o \
directiv.o \
assemble.o labels.o hashtbl.o crc64.o parser.o \
@@ -147,6 +147,7 @@ eval.o: eval.c compiler.h config.h directiv.h eval.h float.h insnsi.h \
labels.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
exprlib.o: exprlib.c compiler.h config.h directiv.h insnsi.h nasm.h \
nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
+file.o: file.c compiler.h config.h nasmlib.h
float.o: float.c compiler.h config.h directiv.h float.h insnsi.h nasm.h \
nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
hashtbl.o: hashtbl.c compiler.h config.h directiv.h hashtbl.h insnsi.h \
diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak
index 58e11883..7fd9b2f8 100644
--- a/Mkfiles/openwcom.mak
+++ b/Mkfiles/openwcom.mak
@@ -48,7 +48,7 @@ X = .exe
# Edit in Makefile.in, not here!
NASM = nasm.$(O) nasmlib.$(O) ver.$(O) &
raa.$(O) saa.$(O) rbtree.$(O) &
- realpath.$(O) &
+ realpath.$(O) file.$(O) &
float.$(O) insnsa.$(O) insnsb.$(O) &
directiv.$(O) &
assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) &
@@ -284,6 +284,7 @@ eval.$(O): eval.c compiler.h config.h directiv.h eval.h float.h insnsi.h &
labels.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
exprlib.$(O): exprlib.c compiler.h config.h directiv.h insnsi.h nasm.h &
nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
+file.$(O): file.c compiler.h config.h nasmlib.h
float.$(O): float.c compiler.h config.h directiv.h float.h insnsi.h nasm.h &
nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
hashtbl.$(O): hashtbl.c compiler.h config.h directiv.h hashtbl.h insnsi.h &
diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak
index af7577d2..c7a04a6f 100644
--- a/Mkfiles/owlinux.mak
+++ b/Mkfiles/owlinux.mak
@@ -59,7 +59,7 @@ X = .exe
# Edit in Makefile.in, not here!
NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \
raa.$(O) saa.$(O) rbtree.$(O) \
- realpath.$(O) \
+ realpath.$(O) file.$(O) \
float.$(O) insnsa.$(O) insnsb.$(O) \
directiv.$(O) \
assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \
@@ -253,6 +253,7 @@ eval.$(O): eval.c compiler.h directiv.h eval.h float.h insnsi.h labels.h \
nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h
exprlib.$(O): exprlib.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \
opflags.h pptok.h preproc.h regs.h tables.h
+file.$(O): file.c compiler.h nasmlib.h
float.$(O): float.c compiler.h directiv.h float.h insnsi.h nasm.h nasmlib.h \
opflags.h pptok.h preproc.h regs.h tables.h
hashtbl.$(O): hashtbl.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \
diff --git a/file.c b/file.c
new file mode 100644
index 00000000..a5a97a00
--- /dev/null
+++ b/file.c
@@ -0,0 +1,140 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 1996-2016 The NASM Authors - All Rights Reserved
+ * See the file AUTHORS included with the NASM distribution for
+ * the specific copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * 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
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include "compiler.h"
+#include "nasmlib.h"
+
+#include <errno.h>
+
+#ifdef HAVE_IO_H
+# include <io.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+void nasm_write(const void *ptr, size_t size, FILE *f)
+{
+ size_t n = fwrite(ptr, 1, size, f);
+ if (n != size || ferror(f) || feof(f))
+ nasm_fatal(0, "unable to write output: %s", strerror(errno));
+}
+
+#ifdef WORDS_LITTLEENDIAN
+
+void fwriteint16_t(uint16_t data, FILE * fp)
+{
+ nasm_write(&data, 2, fp);
+}
+
+void fwriteint32_t(uint32_t data, FILE * fp)
+{
+ nasm_write(&data, 4, fp);
+}
+
+void fwriteint64_t(uint64_t data, FILE * fp)
+{
+ nasm_write(&data, 8, fp);
+}
+
+void fwriteaddr(uint64_t data, int size, FILE * fp)
+{
+ 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
+
+
+#ifdef HAVE_FILENO /* Useless without fileno() */
+# ifdef HAVE__CHSIZE_S
+# define nasm_ftruncate(fd,size) _chsize_s(fd,size)
+# elif defined(HAVE__CHSIZE)
+# define nasm_ftruncate(fd,size) _chsize(fd,size)
+# elif defined(HAVE_FTRUNCATE)
+# define nasm_ftruncate(fd,size) ftruncate(fd,size)
+# endif
+#endif
+
+void fwritezero(size_t bytes, FILE *fp)
+{
+ size_t blksize;
+
+#ifdef nasm_ftruncate
+ if (bytes >= BUFSIZ && !ferror(fp) && !feof(fp)) {
+ off_t pos = ftello(fp);
+ if (pos >= 0) {
+ if (!fflush(fp) &&
+ !nasm_ftruncate(fileno(fp), pos + bytes) &&
+ !fseeko(fp, pos+bytes, SEEK_SET))
+ return;
+ }
+ }
+#endif
+
+ while (bytes) {
+ blksize = (bytes < ZERO_BUF_SIZE) ? bytes : ZERO_BUF_SIZE;
+
+ nasm_write(zero_buffer, blksize, fp);
+ bytes -= blksize;
+ }
+}
diff --git a/nasm.h b/nasm.h
index 00a5108b..94640292 100644
--- a/nasm.h
+++ b/nasm.h
@@ -479,10 +479,6 @@ enum vex_class {
* prefixes, we must ensure the enumerations for prefixes and
* register names do not overlap.
*/
-#ifdef P_WAIT
-# undef P_WAIT /* Macro defined on some Windows versions */
-#endif
-
enum prefixes { /* instruction prefixes */
P_none = 0,
PREFIX_ENUM_START = REG_ENUM_LIMIT,
diff --git a/nasmlib.c b/nasmlib.c
index 74466e8b..7bc1ffe5 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -162,13 +162,6 @@ no_return nasm_assert_failed(const char *file, int line, const char *msg)
exit(1);
}
-void nasm_write(const void *ptr, size_t size, FILE *f)
-{
- size_t n = fwrite(ptr, 1, size, f);
- if (n != size || ferror(f) || feof(f))
- nasm_fatal(0, "unable to write output: %s", strerror(errno));
-}
-
#ifndef nasm_stricmp
int nasm_stricmp(const char *s1, const char *s2)
{
@@ -405,94 +398,6 @@ int32_t seg_alloc(void)
return this_seg;
}
-#ifdef WORDS_LITTLEENDIAN
-
-void fwriteint16_t(uint16_t data, FILE * fp)
-{
- nasm_write(&data, 2, fp);
-}
-
-void fwriteint32_t(uint32_t data, FILE * fp)
-{
- nasm_write(&data, 4, fp);
-}
-
-void fwriteint64_t(uint64_t data, FILE * fp)
-{
- nasm_write(&data, 8, fp);
-}
-
-void fwriteaddr(uint64_t data, int size, FILE * fp)
-{
- 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
-
-#ifdef HAVE_FILENO /* Useless without fileno() */
-# ifdef HAVE__CHSIZE_S
-# define nasm_ftruncate(fd,size) _chsize_s(fd,size)
-# elif defined(HAVE__CHSIZE)
-# define nasm_ftruncate(fd,size) _chsize(fd,size)
-# elif defined(HAVE_FTRUNCATE)
-# define nasm_ftruncate(fd,size) ftruncate(fd,size)
-# endif
-#endif
-
-void fwritezero(size_t bytes, FILE *fp)
-{
- size_t blksize;
-
-#ifdef nasm_ftruncate
- if (bytes >= BUFSIZ && !ferror(fp) && !feof(fp)) {
- off_t pos = ftello(fp);
- if (pos >= 0) {
- if (!fflush(fp) &&
- !nasm_ftruncate(fileno(fp), pos + bytes) &&
- !fseeko(fp, pos+bytes, SEEK_SET))
- return;
- }
- }
-#endif
-
- while (bytes) {
- blksize = (bytes < ZERO_BUF_SIZE) ? bytes : ZERO_BUF_SIZE;
-
- nasm_write(zero_buffer, blksize, fp);
- bytes -= blksize;
- }
-}
-
void standard_extension(char *inname, char *outname, char *extension)
{
char *p, *q;
diff --git a/nasmlib.h b/nasmlib.h
index 534324db..74573bf4 100644
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -46,12 +46,6 @@
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
-#ifdef HAVE_IO_H
-# include <io.h>
-#endif
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
/*
* tolower table -- avoids a function call on some platforms.
diff --git a/rdoff/Makefile.in b/rdoff/Makefile.in
index 41fc5f1a..7efcc542 100644
--- a/rdoff/Makefile.in
+++ b/rdoff/Makefile.in
@@ -32,7 +32,7 @@ MKDIR = mkdir
LDRDFLIBS = rdoff.$(O) symtab.$(O) collectn.$(O) \
rdlib.$(O) segtab.$(O) hash.$(O)
RDXLIBS = rdoff.$(O) rdfload.$(O) symtab.$(O) collectn.$(O) hash.$(O)
-NASMLIB = ../nasmlib.$(O)
+NASMLIB = ../nasmlib.$(O) ../file.$(O)
# Binary suffixes
O = @OBJEXT@