LIBS = @LIBS@
PERL = perl -I$(srcdir)/perllib
+XOBJS = @XOBJS@
+
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
all: nasm$(X) ndisasm$(X) nasm.man ndisasm.man
cd rdoff && $(MAKE) all
-nasm$(X): $(NASM)
- $(CC) $(LDFLAGS) -o nasm$(X) $(NASM) $(LIBS)
+nasm$(X): $(NASM) $(XOBJS)
+ $(CC) $(LDFLAGS) -o nasm$(X) $(NASM) $(XOBJS) $(LIBS)
-ndisasm$(X): $(NDISASM)
- $(CC) $(LDFLAGS) -o ndisasm$(X) $(NDISASM) $(LIBS)
+ndisasm$(X): $(NDISASM) $(XOBJS)
+ $(CC) $(LDFLAGS) -o ndisasm$(X) $(NDISASM) $(XOBJS) $(LIBS)
# These source files are automagically generated from a single
# instruction-table file by a Perl script. They're distributed,
#
alldeps: perlreq
$(PERL) mkdep.pl -M Makefile.in Mkfiles/*.mak -- \
- . output
+ . output lib
./config.status
#-- Magic hints to mkdep.pl --#
insnsn.$(O): insnsn.c
labels.$(O): labels.c compiler.h config.h hashtbl.h insnsi.h nasm.h \
nasmlib.h regs.h version.h
+lib/snprintf.$(O): lib/snprintf.c compiler.h config.h nasmlib.h
+lib/vsnprintf.$(O): lib/vsnprintf.c compiler.h config.h nasmlib.h
listing.$(O): listing.c compiler.h config.h insnsi.h listing.h nasm.h \
nasmlib.h regs.h version.h
macros.$(O): macros.c
insnsn.$(O): insnsn.c
labels.$(O): labels.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h regs.h \
version.h
+lib/snprintf.$(O): lib/snprintf.c compiler.h nasmlib.h
+lib/vsnprintf.$(O): lib/vsnprintf.c compiler.h nasmlib.h
listing.$(O): listing.c compiler.h insnsi.h listing.h nasm.h nasmlib.h \
regs.h version.h
macros.$(O): macros.c
CC = wcl386
CFLAGS = -3 -bcl=$(TARGET) -ox -wx -ze -fpi
BUILD_CFLAGS = $(CFLAGS) # -I$(srcdir)/inttypes
-INTERNAL_CFLAGS = -I$(srcdir) -I.
+INTERNAL_CFLAGS = -I$(srcdir) -I. -DHAVE_SNPRINTF -DHAVE_VSNPRINTF
ALL_CFLAGS = $(BUILD_CFLAGS) $(INTERNAL_CFLAGS)
LD = $(CC)
LDFLAGS = $(ALL_CFLAGS)
insnsn.$(O): insnsn.c
labels.$(O): labels.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h regs.h &
version.h
+lib\snprintf.$(O): lib\snprintf.c compiler.h nasmlib.h
+lib\vsnprintf.$(O): lib\vsnprintf.c compiler.h nasmlib.h
listing.$(O): listing.c compiler.h insnsi.h listing.h nasm.h nasmlib.h &
regs.h version.h
macros.$(O): macros.c
CC = wcl386
CFLAGS = -3 -bcl=$(TARGET) -ox -wx -ze -fpi
BUILD_CFLAGS = $(CFLAGS) # -I$(srcdir)/inttypes
-INTERNAL_CFLAGS = -I$(srcdir) -I.
+INTERNAL_CFLAGS = -I$(srcdir) -I. -DHAVE_SNPRINTF -DHAVE_VSNPRINTF
ALL_CFLAGS = $(BUILD_CFLAGS) $(INTERNAL_CFLAGS)
LD = $(CC)
LDFLAGS = $(ALL_CFLAGS)
insnsn.$(O): insnsn.c
labels.$(O): labels.c compiler.h hashtbl.h insnsi.h nasm.h nasmlib.h regs.h \
version.h
+lib/snprintf.$(O): lib/snprintf.c compiler.h nasmlib.h
+lib/vsnprintf.$(O): lib/vsnprintf.c compiler.h nasmlib.h
listing.$(O): listing.c compiler.h insnsi.h listing.h nasm.h nasmlib.h \
regs.h version.h
macros.$(O): macros.c
#endif
/* Some versions of MSVC have these only with underscores in front */
-
-#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
-# define snprintf _snprintf
+#include <stdio.h>
+#include <stddef.h>
+#include <stdarg.h>
+
+#ifndef HAVE_SNPRINTF
+# ifdef HAVE__SNPRINTF
+# define snprintf _snprintf
+# else
+int snprintf(char *, size_t, const char *, ...);
+# endif
#endif
-#if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
-# define vsnprintf _vsnprintf
+#ifndef HAVE_VSNPRINTF
+# ifdef HAVE__VSNPRINT
+# define vsnprintf _vsnprintf
+# else
+int vsnprintf(char *, size_t, const char *, va_list);
+# endif
#endif
#endif /* COMPILER_H */
AC_TYPE_SIZE_T
dnl Checks for library functions.
+AC_SUBST_FILE(XOBJS)
AC_CHECK_FUNCS(strcspn, ,
AC_MSG_ERROR([NASM requires ANSI C (specifically, "strcspn")]))
AC_MSG_ERROR([NASM requires ANSI C (specifically, "strspn")]))
missing=true
-AC_CHECK_FUNCS([snprintf _snprintf], missing=false)
+AC_CHECK_FUNCS([vsnprintf _vsnprintf], missing=false)
if $missing; then
- AC_MSG_ERROR([NASM requires ISO C99 (specifically, "snprintf")])
+ XOBJS="$XOBJS lib/vsnprintf.o"
fi
missing=true
-AC_CHECK_FUNCS([vsnprintf _vsnprintf], missing=false)
+AC_CHECK_FUNCS([snprintf _snprintf], missing=false)
if $missing; then
- AC_MSG_ERROR([NASM requires ISO C99 (specifically, "vsnprintf")])
+ XOBJS="$XOBJS lib/snprintf.o"
fi
AC_CHECK_FUNCS(getuid)
--- /dev/null
+/*
+ * snprintf()
+ *
+ * Implement snprintf() in terms of vsnprintf()
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "nasmlib.h"
+
+int snprintf(char *str, size_t size, const char *format, ...)
+{
+ va_list ap;
+ int rv;
+
+ va_start(ap, format);
+ rv = vsnprintf(str, size, format, ap);
+ va_end(ap);
+
+ return rv;
+}
+
--- /dev/null
+/*
+ * vsnprintf()
+ *
+ * Poor substitute for a real vsnprintf() function for systems
+ * that don't have them...
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+
+#include "nasmlib.h"
+
+extern efunc nasm_malloc_error;
+
+#define BUFFER_SIZE 65536 /* Bigger than any string we might print... */
+
+static char snprintf_buffer[BUFFER_SIZE];
+
+int vsnprintf(char *str, size_t size, const char *format, va_list ap)
+{
+ int rv, bytes;
+
+ if (size > BUFFER_SIZE) {
+ nasm_malloc_error(ERR_PANIC|ERR_NOFILE,
+ "snprintf: size (%d) > BUFFER_SIZE (%d)",
+ size, BUFFER_SIZE);
+ size = BUFFER_SIZE;
+ }
+
+ rv = vsprintf(snprintf_buffer, format, ap);
+ if (rv > BUFFER_SIZE) {
+ nasm_malloc_error(ERR_PANIC|ERR_NOFILE,
+ "snprintf buffer overflow");
+ }
+
+ if (rv < (int)size-1)
+ bytes = rv;
+ else
+ bytes = size-1;
+
+ if (size > 0) {
+ memcpy(str, snprintf_buffer, bytes);
+ str[bytes] = '\0';
+ }
+
+ return rv;
+}
#include "insns.h"
int globalbits = 0; /* defined in nasm.h, works better here for ASM+DISASM */
-static efunc nasm_malloc_error;
+efunc nasm_malloc_error; /* Exported for the benefit of vsnprintf.c */
#ifdef LOGALLOC
static FILE *logfp;