diff --git a/Makefile.in b/Makefile.in index 56f3589f..568549d6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -74,6 +74,7 @@ endif #-- Begin File Lists --# NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ raa.$(O) saa.$(O) rbtree.$(O) \ + realpath.$(O) \ float.$(O) insnsa.$(O) insnsb.$(O) \ directiv.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ @@ -84,15 +85,16 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ output/outelfx32.$(O) \ output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \ output/outdbg.$(O) output/outieee.$(O) output/outmac32.$(O) \ - output/outmac64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \ + output/outmac64.$(O) \ + md5c.$(O) output/codeview.$(O) \ + preproc.$(O) quote.$(O) pptok.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \ ilog2.$(O) \ lib/strlcpy.$(O) \ preproc-nop.$(O) \ disp8.$(O) \ - iflag.$(O) \ - md5c.$(O) output/codeview.$(O) + iflag.$(O) NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \ insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O) \ @@ -343,6 +345,7 @@ listing.$(O): listing.c compiler.h config.h directiv.h insnsi.h listing.h \ macros.$(O): macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h \ nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h \ tables.h +md5c.$(O): md5c.c md5.h nasm.$(O): nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h \ iflag.h iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h \ opflags.h output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h \ @@ -353,6 +356,9 @@ nasmlib.$(O): nasmlib.c compiler.h config.h directiv.h iflag.h iflaggen.h \ ndisasm.$(O): ndisasm.c compiler.h config.h directiv.h disasm.h iflag.h \ iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h \ regs.h sync.h tables.h tokens.h +output/codeview.$(O): output/codeview.c compiler.h config.h directiv.h \ + insnsi.h md5.h nasm.h nasmlib.h opflags.h output/outlib.h output/pecoff.h \ + pptok.h preproc.h regs.h saa.h tables.h version.h output/nulldbg.$(O): output/nulldbg.c compiler.h config.h directiv.h \ insnsi.h nasm.h nasmlib.h opflags.h output/outlib.h pptok.h preproc.h \ regs.h tables.h @@ -423,6 +429,9 @@ preproc.$(O): preproc.c compiler.h config.h directiv.h eval.h hashtbl.h \ quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h config.h rbtree.h +realpath.$(O): realpath.c compiler.h config.h directiv.h iflag.h iflaggen.h \ + insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h \ + tables.h tokens.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h config.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index a2bae67e..93e910e0 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -25,7 +25,8 @@ CC = cl LD = link CFLAGS = $(CFLAGS) /W2 BUILD_CFLAGS = $(CFLAGS) /I$(srcdir)/inttypes -INTERNAL_CFLAGS = /I$(srcdir) /I. /DHAVE__SNPRINTF /DHAVE__VSNPRINTF +INTERNAL_CFLAGS = /I$(srcdir) /I. \ + /DHAVE__SNPRINTF /DHAVE__VSNPRINTF /DHAVE__FULLPATH ALL_CFLAGS = $(BUILD_CFLAGS) $(INTERNAL_CFLAGS) LDFLAGS = $(LDFLAGS) /SUBSYSTEM:CONSOLE LIBS = @@ -44,6 +45,7 @@ X = .exe # Edit in Makefile.in, not here! NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ raa.$(O) saa.$(O) rbtree.$(O) \ + realpath.$(O) \ float.$(O) insnsa.$(O) insnsb.$(O) \ directiv.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ @@ -54,15 +56,16 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ output/outelfx32.$(O) \ output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \ output/outdbg.$(O) output/outieee.$(O) output/outmac32.$(O) \ - output/outmac64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \ + output/outmac64.$(O) \ + md5c.$(O) output/codeview.$(O) \ + preproc.$(O) quote.$(O) pptok.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \ ilog2.$(O) \ lib/strlcpy.$(O) \ preproc-nop.$(O) \ disp8.$(O) \ - iflag.$(O) \ - md5c.$(O) output/codeview.$(O) + iflag.$(O) NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \ insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O) \ @@ -263,6 +266,7 @@ listing.$(O): listing.c compiler.h directiv.h insnsi.h listing.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h macros.$(O): macros.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h tables.h +md5c.$(O): md5c.c md5.h nasm.$(O): nasm.c assemble.h compiler.h directiv.h eval.h float.h iflag.h \ iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h \ output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \ @@ -273,6 +277,9 @@ nasmlib.$(O): nasmlib.c compiler.h directiv.h iflag.h iflaggen.h insns.h \ ndisasm.$(O): ndisasm.c compiler.h directiv.h disasm.h iflag.h iflaggen.h \ insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h sync.h \ tables.h tokens.h +output/codeview.$(O): output/codeview.c compiler.h directiv.h insnsi.h md5.h \ + nasm.h nasmlib.h opflags.h output/outlib.h output/pecoff.h pptok.h \ + preproc.h regs.h saa.h tables.h version.h output/nulldbg.$(O): output/nulldbg.c compiler.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h tables.h output/nullout.$(O): output/nullout.c compiler.h directiv.h insnsi.h nasm.h \ @@ -337,6 +344,9 @@ preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h \ quote.$(O): quote.c compiler.h nasmlib.h quote.h raa.$(O): raa.c compiler.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h rbtree.h +realpath.$(O): realpath.c compiler.h directiv.h iflag.h iflaggen.h insns.h \ + insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h \ + tokens.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \ opflags.h pptok.h preproc.h regs.h tables.h diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak index 0bc23e58..68a2118f 100644 --- a/Mkfiles/netware.mak +++ b/Mkfiles/netware.mak @@ -32,6 +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 \ float.o insnsa.o insnsb.o \ directiv.o \ assemble.o labels.o hashtbl.o crc64.o parser.o \ @@ -42,7 +43,9 @@ NASM = nasm.o nasmlib.o ver.o \ outelfx32.o \ outobj.o outas86.o outrdf2.o \ outdbg.o outieee.o outmac32.o \ - outmac64.o preproc.o quote.o pptok.o \ + outmac64.o \ + md5c.o codeview.o \ + preproc.o quote.o pptok.o \ macros.o listing.o eval.o exprlib.o stdscan.o \ strfunc.o tokhash.o regvals.o regflags.o \ ilog2.o \ @@ -171,6 +174,7 @@ listing.o: listing.c compiler.h config.h directiv.h insnsi.h listing.h \ nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h macros.o: macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h nasm.h \ nasmlib.h opflags.h outform.h pptok.h preproc.h regs.h tables.h +md5c.o: md5c.c md5.h nasm.o: nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h \ iflag.h iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h \ opflags.h outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \ @@ -181,6 +185,9 @@ nasmlib.o: nasmlib.c compiler.h config.h directiv.h iflag.h iflaggen.h \ ndisasm.o: ndisasm.c compiler.h config.h directiv.h disasm.h iflag.h \ iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h \ regs.h sync.h tables.h tokens.h +codeview.o: codeview.c compiler.h config.h directiv.h insnsi.h md5.h nasm.h \ + nasmlib.h opflags.h outlib.h pecoff.h pptok.h preproc.h regs.h saa.h \ + tables.h version.h nulldbg.o: nulldbg.c compiler.h config.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h outlib.h pptok.h preproc.h regs.h tables.h nullout.o: nullout.c compiler.h config.h directiv.h insnsi.h nasm.h \ @@ -241,6 +248,9 @@ preproc.o: preproc.c compiler.h config.h directiv.h eval.h hashtbl.h \ quote.o: quote.c compiler.h config.h nasmlib.h quote.h raa.o: raa.c compiler.h config.h nasmlib.h raa.h rbtree.o: rbtree.c compiler.h config.h rbtree.h +realpath.o: realpath.c compiler.h config.h directiv.h iflag.h iflaggen.h \ + insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h \ + tables.h tokens.h regdis.o: regdis.c regdis.h regs.h regflags.o: regflags.c compiler.h config.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index 2d85eba8..7f69f7d8 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -48,6 +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) & float.$(O) insnsa.$(O) insnsb.$(O) & directiv.$(O) & assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) & @@ -58,7 +59,9 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) & output/outelfx32.$(O) & output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) & output/outdbg.$(O) output/outieee.$(O) output/outmac32.$(O) & - output/outmac64.$(O) preproc.$(O) quote.$(O) pptok.$(O) & + output/outmac64.$(O) & + md5c.$(O) output/codeview.$(O) & + preproc.$(O) quote.$(O) pptok.$(O) & macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) & strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) & ilog2.$(O) & @@ -309,6 +312,7 @@ listing.$(O): listing.c compiler.h config.h directiv.h insnsi.h listing.h & macros.$(O): macros.c compiler.h config.h directiv.h hashtbl.h insnsi.h & nasm.h nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h & tables.h +md5c.$(O): md5c.c md5.h nasm.$(O): nasm.c assemble.h compiler.h config.h directiv.h eval.h float.h & iflag.h iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h & opflags.h output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h & @@ -319,6 +323,9 @@ nasmlib.$(O): nasmlib.c compiler.h config.h directiv.h iflag.h iflaggen.h & ndisasm.$(O): ndisasm.c compiler.h config.h directiv.h disasm.h iflag.h & iflaggen.h insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h & regs.h sync.h tables.h tokens.h +output/codeview.$(O): output/codeview.c compiler.h config.h directiv.h & + insnsi.h md5.h nasm.h nasmlib.h opflags.h output/outlib.h output/pecoff.h & + pptok.h preproc.h regs.h saa.h tables.h version.h output/nulldbg.$(O): output/nulldbg.c compiler.h config.h directiv.h & insnsi.h nasm.h nasmlib.h opflags.h output/outlib.h pptok.h preproc.h & regs.h tables.h @@ -389,6 +396,9 @@ preproc.$(O): preproc.c compiler.h config.h directiv.h eval.h hashtbl.h & quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h config.h rbtree.h +realpath.$(O): realpath.c compiler.h config.h directiv.h iflag.h iflaggen.h & + insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h & + tables.h tokens.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h config.h directiv.h insnsi.h nasm.h & nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak index 85ad1b8e..90c7b357 100644 --- a/Mkfiles/owlinux.mak +++ b/Mkfiles/owlinux.mak @@ -59,6 +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) \ float.$(O) insnsa.$(O) insnsb.$(O) \ directiv.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ @@ -69,7 +70,9 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \ output/outelfx32.$(O) \ output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \ output/outdbg.$(O) output/outieee.$(O) output/outmac32.$(O) \ - output/outmac64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \ + output/outmac64.$(O) \ + md5c.$(O) output/codeview.$(O) \ + preproc.$(O) quote.$(O) pptok.$(O) \ macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \ ilog2.$(O) \ @@ -277,6 +280,7 @@ listing.$(O): listing.c compiler.h directiv.h insnsi.h listing.h nasm.h \ nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h macros.$(O): macros.c compiler.h directiv.h hashtbl.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outform.h pptok.h preproc.h regs.h tables.h +md5c.$(O): md5c.c md5.h nasm.$(O): nasm.c assemble.h compiler.h directiv.h eval.h float.h iflag.h \ iflaggen.h insns.h insnsi.h labels.h listing.h nasm.h nasmlib.h opflags.h \ output/outform.h parser.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \ @@ -287,6 +291,9 @@ nasmlib.$(O): nasmlib.c compiler.h directiv.h iflag.h iflaggen.h insns.h \ ndisasm.$(O): ndisasm.c compiler.h directiv.h disasm.h iflag.h iflaggen.h \ insns.h insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h sync.h \ tables.h tokens.h +output/codeview.$(O): output/codeview.c compiler.h directiv.h insnsi.h md5.h \ + nasm.h nasmlib.h opflags.h output/outlib.h output/pecoff.h pptok.h \ + preproc.h regs.h saa.h tables.h version.h output/nulldbg.$(O): output/nulldbg.c compiler.h directiv.h insnsi.h nasm.h \ nasmlib.h opflags.h output/outlib.h pptok.h preproc.h regs.h tables.h output/nullout.$(O): output/nullout.c compiler.h directiv.h insnsi.h nasm.h \ @@ -351,6 +358,9 @@ preproc.$(O): preproc.c compiler.h directiv.h eval.h hashtbl.h insnsi.h \ quote.$(O): quote.c compiler.h nasmlib.h quote.h raa.$(O): raa.c compiler.h nasmlib.h raa.h rbtree.$(O): rbtree.c compiler.h rbtree.h +realpath.$(O): realpath.c compiler.h directiv.h iflag.h iflaggen.h insns.h \ + insnsi.h nasm.h nasmlib.h opflags.h pptok.h preproc.h regs.h tables.h \ + tokens.h regdis.$(O): regdis.c regdis.h regs.h regflags.$(O): regflags.c compiler.h directiv.h insnsi.h nasm.h nasmlib.h \ opflags.h pptok.h preproc.h regs.h tables.h diff --git a/configure.in b/configure.in index fba5d323..f3274263 100644 --- a/configure.in +++ b/configure.in @@ -126,6 +126,12 @@ AC_CHECK_HEADERS(strings.h) dnl Look for AC_CHECK_HEADERS(stdbool.h) +dnl Look for +AC_CHECK_HEADERS(unistd.h) + +dnl Look for +AC_CHECK_HEADERS(sys/param.h) + dnl Checks for library functions. AC_SUBST(XOBJS) @@ -155,6 +161,11 @@ AC_CHECK_FUNCS(strlcpy) AC_CHECK_FUNCS(getuid) AC_CHECK_FUNCS(getgid) +AC_CHECK_FUNCS(realpath) +AC_CHECK_FUNCS(canonicalize_file_name) +AC_CHECK_FUNCS(_fullpath) +AC_CHECK_FUNCS(pathconf) + dnl Check for functions that might not be declared in the headers for dnl various idiotic reasons (mostly because of library authors dnl abusing the meaning of __STRICT_ANSI__) diff --git a/nasmlib.c b/nasmlib.c index 9d57adbc..ecd6d8df 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -696,18 +696,6 @@ char *nasm_opt_val(char *p, char **val, char **next) return p; } -#ifdef _WIN32 -char *nasm_realpath(const char *rel_path) -{ - return _fullpath(NULL, rel_path, 0); -} -#else -char *nasm_realpath(const char *rel_path) -{ - return realpath(rel_path, NULL); -} -#endif - /* * initialized data bytes length from opcode */ diff --git a/realpath.c b/realpath.c new file mode 100644 index 00000000..a1c21010 --- /dev/null +++ b/realpath.c @@ -0,0 +1,131 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 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. + * + * ----------------------------------------------------------------------- */ + +/* + * realpath.c As system-independent as possible implementation of realpath() + */ + +#include "compiler.h" + +#include +#include +#include +#ifdef HAVE_UNISTD_H +# include +#endif +#ifdef HAVE_SYS_PARAM_H +# include +#endif + +#include "nasmlib.h" + +#if 0 /* def HAVE_CANONICALIZE_FILE_NAME */ + +/* + * GNU-specific, but avoids the realpath(..., NULL) + * portability problem if it exists. + */ +char *nasm_realpath(const char *rel_path) +{ + return canonicalize_file_name(rel_path); +} + +#elif defined(HAVE_REALPATH) + +/* + * POSIX.1-2008 defines realpath(..., NULL); POSIX.1-2001 doesn't guarantee + * that a NULL second argument is supported. + */ + +char *nasm_realpath(const char *rel_path) +{ + char *buf; + + buf = realpath(rel_path, NULL); + if (buf) + return buf; + + /* Not all implemetations of realpath() support a NULL second argument */ + if (errno == EINVAL) { + int path_max = -1; + char *buf; + +# ifdef PATH_MAX + path_max = PATH_MAX; /* SUSv2 */ +# elif defined(MAXPATHLEN) + path_max = MAXPATHLEN; /* Solaris */ +# elif defined(HAVE_PATHCONF) && defined(_PC_PATH_MAX) + path_max = pathconf(path, _PC_PATH_MAX); /* POSIX */ +# endif + if (path_max < 0) + path_max = 65536; /* Crazily high, we hope */ + + buf = nasm_malloc(path_max); + + if (!realpath(rel_path, buf)) { + nasm_free(buf); + buf = NULL; + } else { + /* On some systems, pathconf() can return a very large value */ + + buf[path_max - 1] = '\0'; /* Just in case overrun is possible */ + buf = nasm_realloc(buf, strlen(buf) + 1); + } + } + + return buf; +} + +#elif defined(HAVE__FULLPATH) + +/* + * win32/win64 API + */ + +char *nasm_realpath(const char *rel_path) +{ + return _fullpath(NULL, rel_path, 0); +} + +#else + +/* + * There is nothing we know how to do here, so hope it just works anyway. + */ + +char *nasm_realpath(const char *rel_path) +{ + return nasm_strdup(rel_path); +} + +#endif