diff options
author | H. Peter Anvin <hpa@zytor.com> | 2007-10-02 21:53:51 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2007-10-02 21:53:51 -0700 |
commit | fe501957c09a80347b1eb005ba1b1bc0fce14b0d (patch) | |
tree | 6747b0e256b60819125c652dd58577b12c71556e | |
parent | 4a8daf06074351df2588a9f5cd2b4a558bde9935 (diff) | |
download | nasm-fe501957c09a80347b1eb005ba1b1bc0fce14b0d.tar.gz |
Portability fixes
Concentrate compiler dependencies to compiler.h; make sure compiler.h
is included first in every .c file (since some prototypes may depend
on the presence of feature request macros.)
Actually use the conditional inclusion of various functions (totally
broken in previous releases.)
-rw-r--r-- | assemble.c | 2 | ||||
-rw-r--r-- | compiler.h | 18 | ||||
-rw-r--r-- | configure.in | 7 | ||||
-rw-r--r-- | crc64.c | 1 | ||||
-rw-r--r-- | disasm.c | 2 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | float.c | 2 | ||||
-rw-r--r-- | hashtbl.c | 2 | ||||
-rw-r--r-- | labels.c | 2 | ||||
-rw-r--r-- | lib/snprintf.c | 2 | ||||
-rw-r--r-- | lib/vsnprintf.c | 2 | ||||
-rw-r--r-- | listing.c | 2 | ||||
-rw-r--r-- | macros.pl | 2 | ||||
-rw-r--r-- | nasm.c | 2 | ||||
-rw-r--r-- | nasm.h | 3 | ||||
-rw-r--r-- | nasmlib.c | 8 | ||||
-rw-r--r-- | nasmlib.h | 25 | ||||
-rw-r--r-- | ndisasm.c | 2 | ||||
-rw-r--r-- | outform.c | 2 | ||||
-rw-r--r-- | output/outaout.c | 2 | ||||
-rw-r--r-- | output/outas86.c | 2 | ||||
-rw-r--r-- | output/outbin.c | 2 | ||||
-rw-r--r-- | output/outcoff.c | 2 | ||||
-rw-r--r-- | output/outdbg.c | 2 | ||||
-rw-r--r-- | output/outelf32.c | 2 | ||||
-rw-r--r-- | output/outelf64.c | 2 | ||||
-rw-r--r-- | output/outieee.c | 2 | ||||
-rw-r--r-- | output/outmacho.c | 2 | ||||
-rw-r--r-- | output/outobj.c | 2 | ||||
-rw-r--r-- | output/outrdf.c | 2 | ||||
-rw-r--r-- | output/outrdf2.c | 2 | ||||
-rw-r--r-- | parser.c | 2 | ||||
-rwxr-xr-x | pptok.pl | 1 | ||||
-rw-r--r-- | preproc.c | 2 | ||||
-rw-r--r-- | rdoff/collectn.c | 3 | ||||
-rw-r--r-- | rdoff/hash.c | 2 | ||||
-rw-r--r-- | rdoff/ldrdf.c | 2 | ||||
-rw-r--r-- | rdoff/rdf2bin.c | 2 | ||||
-rw-r--r-- | rdoff/rdf2ihx.c | 2 | ||||
-rw-r--r-- | rdoff/rdfdump.c | 2 | ||||
-rw-r--r-- | rdoff/rdflib.c | 2 | ||||
-rw-r--r-- | rdoff/rdfload.c | 2 | ||||
-rw-r--r-- | rdoff/rdlar.c | 2 | ||||
-rw-r--r-- | rdoff/rdlib.c | 2 | ||||
-rw-r--r-- | rdoff/rdoff.c | 2 | ||||
-rw-r--r-- | rdoff/rdx.c | 2 | ||||
-rw-r--r-- | rdoff/segtab.c | 2 | ||||
-rw-r--r-- | rdoff/symtab.c | 3 | ||||
-rwxr-xr-x | regs.pl | 5 | ||||
-rw-r--r-- | stdscan.c | 2 | ||||
-rw-r--r-- | sync.c | 2 | ||||
-rwxr-xr-x | tokhash.pl | 1 |
52 files changed, 133 insertions, 24 deletions
@@ -82,6 +82,8 @@ * used for conditional jump over longer jump */ +#include "compiler.h" + #include <stdio.h> #include <string.h> #include <inttypes.h> @@ -13,15 +13,25 @@ * * Compiler-specific macros for NASM. Feel free to add support for * other compilers in here. + * + * This header file should be included before any other header. */ -#ifndef COMPILER_H -#define COMPILER_H 1 +#ifndef NASM_COMPILER_H +#define NASM_COMPILER_H 1 #ifdef HAVE_CONFIG_H # include "config.h" #endif +/* Request as many features as we can */ +#define _GNU_SOURCE +#define _ISO99_SOURCE +#define _POSIX_SOURCE +#define _POSIX_C_SOURCE 200112L +#define _XOPEN_SOURCE 600 +#define _XOPEN_SOURCE_EXTENDED + #ifdef __GNUC__ # if __GNUC__ >= 4 # define HAVE_GNUC_4 @@ -38,9 +48,9 @@ #endif /* Some versions of MSVC have these only with underscores in front */ -#include <stdio.h> #include <stddef.h> #include <stdarg.h> +#include <stdio.h> #ifndef HAVE_SNPRINTF # ifdef HAVE__SNPRINTF @@ -58,4 +68,4 @@ int vsnprintf(char *, size_t, const char *, va_list); # endif #endif -#endif /* COMPILER_H */ +#endif /* NASM_COMPILER_H */ diff --git a/configure.in b/configure.in index b97f536c..009720a2 100644 --- a/configure.in +++ b/configure.in @@ -82,6 +82,9 @@ fi dnl Check for <inttypes.h> or add a substitute version AC_CHECK_HEADERS(inttypes.h, , CFLAGS="$CFLAGS -I\$(top_srcdir)/inttypes") +dnl The standard header for str*casecmp is <strings.h> +AC_CHECK_HEADERS(strings.h) + dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_TYPE_SIZE_T @@ -107,6 +110,10 @@ if $missing; then XOBJS="$XOBJS lib/snprintf.o" fi +AC_CHECK_FUNCS(strcasecmp stricmp) +AC_CHECK_FUNCS(strncasecmp strnicmp) +AC_CHECK_FUNCS(strsep) + AC_CHECK_FUNCS(getuid) AC_CHECK_FUNCS(getgid) @@ -1,3 +1,4 @@ +#include "compiler.h" #include <inttypes.h> #include <ctype.h> @@ -8,6 +8,8 @@ * initial version 27/iii/95 by Simon Tatham */ +#include "compiler.h" + #include <stdio.h> #include <string.h> #include <limits.h> @@ -8,6 +8,8 @@ * initial version 27/iii/95 by Simon Tatham */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <stddef.h> @@ -8,6 +8,8 @@ * initial version 13/ix/96 by Simon Tatham */ +#include "compiler.h" + #include <ctype.h> #include <stdio.h> #include <stdlib.h> @@ -4,6 +4,8 @@ * Efficient dictionary hash table class. */ +#include "compiler.h" + #include <inttypes.h> #include <string.h> #include "nasm.h" @@ -6,6 +6,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <string.h> #include <stdlib.h> diff --git a/lib/snprintf.c b/lib/snprintf.c index f56a492a..de4d96da 100644 --- a/lib/snprintf.c +++ b/lib/snprintf.c @@ -4,6 +4,8 @@ * Implement snprintf() in terms of vsnprintf() */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <stdarg.h> diff --git a/lib/vsnprintf.c b/lib/vsnprintf.c index 2c9399a0..976b0eac 100644 --- a/lib/vsnprintf.c +++ b/lib/vsnprintf.c @@ -5,6 +5,8 @@ * that don't have them... */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <stdarg.h> @@ -8,6 +8,8 @@ * initial version 2/vii/97 by Simon Tatham */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <stddef.h> @@ -19,7 +19,7 @@ undef $tasm_count; open(OUTPUT,">macros.c") or die "unable to open macros.c\n"; print OUTPUT "/* This file auto-generated from standard.mac by macros.pl" . -" - don't edit it */\n\n#include <stddef.h>\n\nstatic const char *stdmac[] = {\n"; +" - don't edit it */\n\n#include \"compiler.h\"\n\nstatic const char *stdmac[] = {\n"; foreach $fname ( @ARGV ) { open(INPUT,$fname) or die "unable to open $fname\n"; @@ -6,6 +6,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdarg.h> #include <stdlib.h> @@ -11,10 +11,11 @@ #ifndef NASM_NASM_H #define NASM_NASM_H +#include "compiler.h" + #include <stdio.h> #include <inttypes.h> #include "version.h" /* generated NASM version macros */ -#include "compiler.h" #include "nasmlib.h" #include "insnsi.h" /* For enum opcode */ @@ -6,6 +6,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -144,7 +146,7 @@ char *nasm_strndup(char *s, size_t len) return p; } -#if !defined(stricmp) && !defined(strcasecmp) +#ifndef nasm_stricmp int nasm_stricmp(const char *s1, const char *s2) { while (*s1 && tolower(*s1) == tolower(*s2)) @@ -158,7 +160,7 @@ int nasm_stricmp(const char *s1, const char *s2) } #endif -#if !defined(strnicmp) && !defined(strncasecmp) +#ifndef nasm_strnicmp int nasm_strnicmp(const char *s1, const char *s2, int n) { while (n > 0 && *s1 && tolower(*s1) == tolower(*s2)) @@ -172,7 +174,7 @@ int nasm_strnicmp(const char *s1, const char *s2, int n) } #endif -#if !defined(strsep) +#ifndef nasm_strsep char *nasm_strsep(char **stringp, const char *delim) { char *s = *stringp; @@ -9,9 +9,14 @@ #ifndef NASM_NASMLIB_H #define NASM_NASMLIB_H +#include "compiler.h" + #include <inttypes.h> #include <stdio.h> -#include "compiler.h" +#include <string.h> +#ifdef HAVE_STRINGS_H +#include <strings.h> +#endif /* * If this is defined, the wrappers around malloc et al will @@ -98,27 +103,23 @@ char *nasm_strndup_log(char *, int, char *, size_t); * ANSI doesn't guarantee the presence of `stricmp' or * `strcasecmp'. */ -#if defined(stricmp) || defined(strcasecmp) -#if defined(stricmp) -#define nasm_stricmp stricmp -#else +#if defined(HAVE_STRCASECMP) #define nasm_stricmp strcasecmp -#endif +#elif defined(HAVE_STRICMP) +#define nasm_stricmp stricmp #else int nasm_stricmp(const char *, const char *); #endif -#if defined(strnicmp) || defined(strncasecmp) -#if defined(strnicmp) -#define nasm_strnicmp strnicmp -#else +#if defined(HAVE_STRNCASECMP) #define nasm_strnicmp strncasecmp -#endif +#elif defined(HAVE_STRNICMP) +#define nasm_strnicmp strnicmp #else int nasm_strnicmp(const char *, const char *, int); #endif -#if defined(strsep) +#if defined(HAVE_STRSEP) #define nasm_strsep strsep #else char *nasm_strsep(char **stringp, const char *delim); @@ -6,6 +6,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdarg.h> #include <stdlib.h> @@ -9,6 +9,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <string.h> #include <inttypes.h> diff --git a/output/outaout.c b/output/outaout.c index d5358b4c..6c9bf242 100644 --- a/output/outaout.c +++ b/output/outaout.c @@ -7,6 +7,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/output/outas86.c b/output/outas86.c index 135ddda3..4bfbb04b 100644 --- a/output/outas86.c +++ b/output/outas86.c @@ -7,6 +7,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/output/outbin.c b/output/outbin.c index a1c51c8f..b5a7524c 100644 --- a/output/outbin.c +++ b/output/outbin.c @@ -44,6 +44,8 @@ */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/output/outcoff.c b/output/outcoff.c index 8eb8c061..44a41e5a 100644 --- a/output/outcoff.c +++ b/output/outcoff.c @@ -7,6 +7,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/output/outdbg.c b/output/outdbg.c index 0dda75a6..43c6504a 100644 --- a/output/outdbg.c +++ b/output/outdbg.c @@ -7,6 +7,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/output/outelf32.c b/output/outelf32.c index fbc98d60..ca918487 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -7,6 +7,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/output/outelf64.c b/output/outelf64.c index e87d8bdc..5f77bb12 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -7,6 +7,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/output/outieee.c b/output/outieee.c index 19b25755..145fcafe 100644 --- a/output/outieee.c +++ b/output/outieee.c @@ -36,6 +36,8 @@ * * David Lindauer, LADsoft */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/output/outmacho.c b/output/outmacho.c index 86700f8e..545fa27f 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -10,6 +10,8 @@ /* Most of this file is, like Mach-O itself, based on a.out. For more * guidelines see outaout.c. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/output/outobj.c b/output/outobj.c index c411edd9..2f7079ef 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -7,6 +7,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/output/outrdf.c b/output/outrdf.c index cd311de5..d3fbb927 100644 --- a/output/outrdf.c +++ b/output/outrdf.c @@ -12,6 +12,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/output/outrdf2.c b/output/outrdf2.c index c98beadd..82ac0ecb 100644 --- a/output/outrdf2.c +++ b/output/outrdf2.c @@ -9,6 +9,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -8,6 +8,8 @@ * initial version 27/iii/95 by Simon Tatham */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <stddef.h> @@ -138,6 +138,7 @@ if ($what eq 'c') { die if ($n & ($n-1)); + print OUT "#include \"compiler.h\"\n"; print OUT "#include <inttypes.h>\n"; print OUT "#include <ctype.h>\n"; print OUT "#include \"nasmlib.h\"\n"; @@ -34,6 +34,8 @@ * detoken is used to convert the line back to text */ +#include "compiler.h" + #include <stdio.h> #include <stdarg.h> #include <stdlib.h> diff --git a/rdoff/collectn.c b/rdoff/collectn.c index ad43d856..317c5286 100644 --- a/rdoff/collectn.c +++ b/rdoff/collectn.c @@ -4,8 +4,9 @@ * This file is public domain. */ -#include "collectn.h" +#include "compiler.h" #include <stdlib.h> +#include "collectn.h" void collection_init(Collection * c) { diff --git a/rdoff/hash.c b/rdoff/hash.c index 34a8edc1..8b1d3cf8 100644 --- a/rdoff/hash.c +++ b/rdoff/hash.c @@ -8,6 +8,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include "hash.h" const uint32_t consttab[] = { diff --git a/rdoff/ldrdf.c b/rdoff/ldrdf.c index e28f2842..cd07fe72 100644 --- a/rdoff/ldrdf.c +++ b/rdoff/ldrdf.c @@ -24,6 +24,8 @@ * under DOS. '#define STINGY_MEMORY' may help a little. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/rdoff/rdf2bin.c b/rdoff/rdf2bin.c index e5561863..0b3f9999 100644 --- a/rdoff/rdf2bin.c +++ b/rdoff/rdf2bin.c @@ -2,6 +2,8 @@ * rdf2bin.c - convert an RDOFF object file to flat binary */ +#include "compiler.h" + #include <stdlib.h> #include <stdio.h> #include <string.h> diff --git a/rdoff/rdf2ihx.c b/rdoff/rdf2ihx.c index a0238dad..94ba1cb3 100644 --- a/rdoff/rdf2ihx.c +++ b/rdoff/rdf2ihx.c @@ -4,6 +4,8 @@ * Note that this program only writes 16-bit HEX. */ +#include "compiler.h" + #include <stdlib.h> #include <stdio.h> #include <string.h> diff --git a/rdoff/rdfdump.c b/rdoff/rdfdump.c index 691241d5..83305570 100644 --- a/rdoff/rdfdump.c +++ b/rdoff/rdfdump.c @@ -2,6 +2,8 @@ * rdfdump.c - dump RDOFF file header. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/rdoff/rdflib.c b/rdoff/rdflib.c index 6abd13cf..b4bf6d60 100644 --- a/rdoff/rdflib.c +++ b/rdoff/rdflib.c @@ -23,6 +23,8 @@ * content size, followed by data. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <errno.h> diff --git a/rdoff/rdfload.c b/rdoff/rdfload.c index cd24c2de..063724e7 100644 --- a/rdoff/rdfload.c +++ b/rdoff/rdfload.c @@ -17,6 +17,8 @@ * - support for segment relocations (hard to do in ANSI C) */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/rdoff/rdlar.c b/rdoff/rdlar.c index df813d12..1d4cd431 100644 --- a/rdoff/rdlar.c +++ b/rdoff/rdlar.c @@ -3,6 +3,8 @@ * Copyright (c) 2002 RET & COM Research. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <ctype.h> diff --git a/rdoff/rdlib.c b/rdoff/rdlib.c index c094a565..a6ae1568 100644 --- a/rdoff/rdlib.c +++ b/rdoff/rdlib.c @@ -2,6 +2,8 @@ * rdlib.c - routines for manipulating RDOFF libraries (.rdl) */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/rdoff/rdoff.c b/rdoff/rdoff.c index ac722795..25394996 100644 --- a/rdoff/rdoff.c +++ b/rdoff/rdoff.c @@ -15,6 +15,8 @@ * make it portable. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/rdoff/rdx.c b/rdoff/rdx.c index 82210a65..26be0c41 100644 --- a/rdoff/rdx.c +++ b/rdoff/rdx.c @@ -12,6 +12,8 @@ files. You can use these files in your own program to load RDOFF objects and execute the code in them in a similar way to what is shown here. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> diff --git a/rdoff/segtab.c b/rdoff/segtab.c index 8ee1b7b3..e1a3ddf2 100644 --- a/rdoff/segtab.c +++ b/rdoff/segtab.c @@ -1,3 +1,5 @@ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include "segtab.h" diff --git a/rdoff/symtab.c b/rdoff/symtab.c index 6026ccd8..ce54d8ea 100644 --- a/rdoff/symtab.c +++ b/rdoff/symtab.c @@ -7,6 +7,9 @@ * redistributable under the licence given in the file "Licence" * distributed in the NASM archive. */ + +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -78,7 +78,7 @@ close(REGS); if ( $fmt eq 'h' ) { # Output regs.h - print "/* automatically generated from $file - do not edit */\n"; + print "/* automatically generated from $file - do not edit */\n\n"; $expr_regs = 1; printf "#define EXPR_REG_START %d\n", $expr_regs; print "enum reg_enum {\n"; @@ -101,7 +101,8 @@ if ( $fmt eq 'h' ) { print "\n"; } elsif ( $fmt eq 'c' ) { # Output regs.c - print "/* automatically generated from $file - do not edit */\n"; + print "/* automatically generated from $file - do not edit */\n\n"; + print "#include \"compiler.h\"\n\n"; print "static const char * const reg_names[] = "; $ch = '{'; # This one has no dummy entry for 0 foreach $reg ( sort(keys(%regs)) ) { @@ -1,3 +1,5 @@ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -6,6 +6,8 @@ * distributed in the NASM archive. */ +#include "compiler.h" + #include <stdio.h> #include <stdlib.h> #include <limits.h> @@ -168,6 +168,7 @@ if ($output eq 'h') { print " */\n"; print "\n"; + print "#include \"compiler.h\"\n"; print "#include <string.h>\n"; print "#include \"nasm.h\"\n"; print "#include \"hashtbl.h\"\n"; |