From 257ce0c78588e60147026634e6828f3a962ad034 Mon Sep 17 00:00:00 2001 From: Werner LEMBERG Date: Sat, 2 Apr 2005 12:49:11 +0000 Subject: [PATCH] Add binary relocation support for Windows platforms. * src/include/Makefile.sub (defs.h): Add `INSTALLPATH'. * src/include/relocate.h, src/libs/libgroff/relocate.cpp: New files. * src/libs/libgroff/searchpath.cpp: Handle `relocate'. (search_path::search_path, search_path::open_file_cautious): Use `relocate'. * src/libs/libgroff/Makefile.sub (OBJS, CCSRCS), src/include/Makefile.sub (HDRS): Updated. * src/devices/grohtml/post-html.cpp: Don't use strdup/free but strsave/a_delete. * src/libs/libgroff/font.cpp: Replace strdup with strsave. * src/libs/libgroff/maxfilename.cpp: Don't include limits.h since lib.h already does it. * src/libs/libgroff/maxpathname.cpp: New file, defining path_name_max. * src/include/lib.h: Add prototype for path_name_max. * src/libs/libgroff/Makefile.sub (OBJS, CCSRCS): Updated. * src/include/nonposix.h (PATH_EXT): New macro. --- ChangeLog | 35 ++++ src/devices/grohtml/post-html.cpp | 42 ++-- src/include/Makefile.sub | 2 + src/include/lib.h | 1 + src/include/nonposix.h | 9 +- src/include/relocate.h | 27 +++ src/libs/libgroff/Makefile.sub | 4 + src/libs/libgroff/font.cpp | 4 +- src/libs/libgroff/maxfilename.cpp | 6 +- .../libgroff/{maxfilename.cpp => maxpathname.cpp} | 50 ++--- src/libs/libgroff/relocate.cpp | 232 +++++++++++++++++++++ src/libs/libgroff/searchpath.cpp | 34 ++- 12 files changed, 381 insertions(+), 65 deletions(-) create mode 100644 src/include/relocate.h copy src/libs/libgroff/{maxfilename.cpp => maxpathname.cpp} (58%) create mode 100644 src/libs/libgroff/relocate.cpp diff --git a/ChangeLog b/ChangeLog index 1c168afe..42419d0e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,38 @@ +2005-04-01 Kees Zeelenberg + Werner LEMBERG + + Add binary relocation support for Windows platforms. + + * src/include/Makefile.sub (defs.h): Add `INSTALLPATH'. + + * src/include/relocate.h, src/libs/libgroff/relocate.cpp: New files. + + * src/libs/libgroff/searchpath.cpp: Handle `relocate'. + (search_path::search_path, search_path::open_file_cautious): Use + `relocate'. + + * src/libs/libgroff/Makefile.sub (OBJS, CCSRCS), + src/include/Makefile.sub (HDRS): Updated. + +2005-04-01 Werner LEMBERG + + * src/devices/grohtml/post-html.cpp: Don't use strdup/free but + strsave/a_delete. + + * src/libs/libgroff/font.cpp: Replace strdup with strsave. + + * src/libs/libgroff/maxfilename.cpp: Don't include limits.h since + lib.h already does it. + + * src/libs/libgroff/maxpathname.cpp: New file, defining + path_name_max. + + * src/include/lib.h: Add prototype for path_name_max. + + * src/libs/libgroff/Makefile.sub (OBJS, CCSRCS): Updated. + + * src/include/nonposix.h (PATH_EXT): New macro. + 2005-03-28 Werner LEMBERG Add support for double- and zero-width characters in grotty. diff --git a/src/devices/grohtml/post-html.cpp b/src/devices/grohtml/post-html.cpp index 65249713..5c5abea9 100644 --- a/src/devices/grohtml/post-html.cpp +++ b/src/devices/grohtml/post-html.cpp @@ -1740,9 +1740,9 @@ void assert_state::add (assert_pos **h, } t->id = i; t->val = v; - free((void *)c); - free((void *)f); - free((void *)l); + a_delete c; + a_delete f; + a_delete l; } } @@ -1797,7 +1797,7 @@ void assert_state::close (const char *c) const char *replace_negate_str (const char *before, char *after) { if (before != NULL) - free((void *)before); + a_delete before; if (strlen(after) > 0) { int d = atoi(after); @@ -1818,7 +1818,7 @@ const char *replace_negate_str (const char *before, char *after) const char *replace_str (const char *before, const char *after) { if (before != NULL) - free((void *)before); + a_delete before; return after; } @@ -1833,29 +1833,29 @@ void assert_state::set (const char *c, const char *v, // fprintf(stderr, "%s:%s:setting %s to %s\n", f, l, c, v); if (strcmp(c, "sp") == 0) { check_sp_flag = 1; - val_sp = replace_str(val_sp, strdup(v)); - file_sp = replace_str(file_sp, strdup(f)); - line_sp = replace_str(line_sp, strdup(l)); + val_sp = replace_str(val_sp, strsave(v)); + file_sp = replace_str(file_sp, strsave(f)); + line_sp = replace_str(line_sp, strsave(l)); } else if (strcmp(c, "br") == 0) { check_br_flag = 1; - val_br = replace_str(val_br, strdup(v)); - file_br = replace_str(file_br, strdup(f)); - line_br = replace_str(line_br, strdup(l)); + val_br = replace_str(val_br, strsave(v)); + file_br = replace_str(file_br, strsave(f)); + line_br = replace_str(line_br, strsave(l)); } else if (strcmp(c, "fi") == 0) { check_fi_flag = 1; - val_fi = replace_str(val_fi, strdup(v)); - file_fi = replace_str(file_fi, strdup(f)); - line_fi = replace_str(line_fi, strdup(l)); + val_fi = replace_str(val_fi, strsave(v)); + file_fi = replace_str(file_fi, strsave(f)); + line_fi = replace_str(line_fi, strsave(l)); } else if (strcmp(c, "nf") == 0) { check_fi_flag = 1; - val_fi = replace_negate_str(val_fi, strdup(v)); - file_fi = replace_str(file_fi, strdup(f)); - line_fi = replace_str(line_fi, strdup(l)); + val_fi = replace_negate_str(val_fi, strsave(v)); + file_fi = replace_str(file_fi, strsave(f)); + line_fi = replace_str(line_fi, strsave(l)); } else if (strcmp(c, "ce") == 0) { check_ce_flag = 1; - val_ce = replace_str(val_ce, strdup(v)); - file_ce = replace_str(file_ce, strdup(f)); - line_ce = replace_str(line_ce, strdup(l)); + val_ce = replace_str(val_ce, strsave(v)); + file_ce = replace_str(file_ce, strsave(f)); + line_ce = replace_str(line_ce, strsave(l)); } } @@ -4751,7 +4751,7 @@ char *make_val (char *s, int v, char *id, char *f, char *l) char buf[30]; sprintf(buf, "%d", v); - return strdup(buf); + return strsave(buf); } else { /* diff --git a/src/include/Makefile.sub b/src/include/Makefile.sub index 9fceb0fc..62aecb2c 100644 --- a/src/include/Makefile.sub +++ b/src/include/Makefile.sub @@ -21,6 +21,7 @@ HDRS=\ printer.h \ ptable.h \ refid.h \ + relocate.h \ search.h \ searchpath.h \ stringclass.h \ @@ -35,6 +36,7 @@ defs.h: FORCE @$(SHELL) $(top_srcdir)/gendef.sh defs.h \ "PROG_PREFIX=\"$(g)\"" \ "DEVICE=\"$(DEVICE)\"" \ + "INSTALLPATH=\"$(prefix)\"" \ "BINPATH=\"$(bindir)\"" \ "FONTPATH=\"$(fontpath)\"" \ "MACROPATH=\"$(tmacpath)\"" \ diff --git a/src/include/lib.h b/src/include/lib.h index 4c0e2476..e560c0d2 100644 --- a/src/include/lib.h +++ b/src/include/lib.h @@ -101,6 +101,7 @@ extern "C" { int pclose (FILE *); } #endif /* NEED_DECLARATION_PCLOSE */ size_t file_name_max(const char *fname); +size_t path_name_max(); int interpret_lf_args(const char *p); diff --git a/src/include/nonposix.h b/src/include/nonposix.h index 706729d0..af3c6207 100644 --- a/src/include/nonposix.h +++ b/src/include/nonposix.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 + Free Software Foundation, Inc. Written by Eli Zaretskii (eliz@is.elta.co.il) This file is part of groff. @@ -101,6 +102,9 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* The executable extension. */ # define EXE_EXT ".exe" +/* Possible executable extensions. */ +# define PATH_EXT ".com;.exe;.bat;.cmd" + /* The system null device. */ # define NULL_DEV "NUL" @@ -209,6 +213,9 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef EXE_EXT # define EXE_EXT "" #endif +#ifndef PATH_EXT +# define PATH_EXT "" +#endif #ifndef NULL_DEV # define NULL_DEV "/dev/null" #endif diff --git a/src/include/relocate.h b/src/include/relocate.h new file mode 100644 index 00000000..5664eca0 --- /dev/null +++ b/src/include/relocate.h @@ -0,0 +1,27 @@ +// -*- C++ -*- +/* Provide relocation for macro and font files. + Copyright (C) 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + USA. */ + +extern char *curr_prefix; +extern size_t curr_prefix_len; + +void set_current_prefix (); +char *xdirname (char *s); +char *searchpath (const char *name, const char *pathp); +char *relocatep (const char *path); +char *relocate (const char *path); diff --git a/src/libs/libgroff/Makefile.sub b/src/libs/libgroff/Makefile.sub index b4233497..805292a7 100644 --- a/src/libs/libgroff/Makefile.sub +++ b/src/libs/libgroff/Makefile.sub @@ -26,6 +26,7 @@ OBJS=\ macropath.$(OBJEXT) \ matherr.$(OBJEXT) \ maxfilename.$(OBJEXT) \ + maxpathname.$(OBJEXT) \ mksdir.$(OBJEXT) \ nametoindex.$(OBJEXT) \ new.$(OBJEXT) \ @@ -34,6 +35,7 @@ OBJS=\ progname.$(OBJEXT) \ ptable.$(OBJEXT) \ quotearg.$(OBJEXT) \ + relocate.$(OBJEXT) \ searchpath.$(OBJEXT) \ spawnvp.$(OBJEXT) \ string.$(OBJEXT) \ @@ -68,6 +70,7 @@ CCSRCS=\ $(srcdir)/lineno.cpp \ $(srcdir)/macropath.cpp \ $(srcdir)/maxfilename.cpp \ + $(srcdir)/maxpathname.cpp \ $(srcdir)/mksdir.cpp \ $(srcdir)/mkstemp.cpp \ $(srcdir)/nametoindex.cpp \ @@ -75,6 +78,7 @@ CCSRCS=\ $(srcdir)/paper.cpp \ $(srcdir)/prime.cpp \ $(srcdir)/ptable.cpp \ + $(srcdir)/relocate.cpp \ $(srcdir)/searchpath.cpp \ $(srcdir)/string.cpp \ $(srcdir)/strsave.cpp \ diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp index 6f7a83a3..6e303fbf 100644 --- a/src/libs/libgroff/font.cpp +++ b/src/libs/libgroff/font.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -999,7 +999,7 @@ int font::load_desc() t.error("image_generator command requires an argument"); return 0; } - image_generator = strdup(p); + image_generator = strsave(p); } else if (strcmp("charset", p) == 0) break; diff --git a/src/libs/libgroff/maxfilename.cpp b/src/libs/libgroff/maxfilename.cpp index 25f55499..f4aec7f7 100644 --- a/src/libs/libgroff/maxfilename.cpp +++ b/src/libs/libgroff/maxfilename.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1992, 2001, 2003 Free Software Foundation, Inc. +/* Copyright (C) 1992, 2001, 2003, 2005 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -37,10 +37,6 @@ size_t file_name_max(const char *fname) #else /* not _POSIX_VERSION */ -#ifdef HAVE_CC_LIMITS_H -#include -#endif /* HAVE_CC_LIMITS_H */ - #ifdef HAVE_DIRENT_H #include #else /* not HAVE_DIRENT_H */ diff --git a/src/libs/libgroff/maxfilename.cpp b/src/libs/libgroff/maxpathname.cpp similarity index 58% copy from src/libs/libgroff/maxfilename.cpp copy to src/libs/libgroff/maxpathname.cpp index 25f55499..69b62de3 100644 --- a/src/libs/libgroff/maxfilename.cpp +++ b/src/libs/libgroff/maxpathname.cpp @@ -1,6 +1,6 @@ // -*- C++ -*- -/* Copyright (C) 1992, 2001, 2003 Free Software Foundation, Inc. - Written by James Clark (jjc@jclark.com) +/* Copyright (C) 2005 Free Software Foundation, Inc. + Written by Werner Lemberg (wl@gnu.org) This file is part of groff. @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with groff; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* file_name_max(dir) does the same as pathconf(dir, _PC_NAME_MAX) */ +/* path_name_max(dir) does the same as pathconf(dir, _PC_PATH_MAX) */ #include "lib.h" @@ -30,40 +30,36 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef _POSIX_VERSION -size_t file_name_max(const char *fname) +size_t path_name_max() { - return pathconf(fname, _PC_NAME_MAX); + return pathconf("/", _PC_PATH_MAX) < 1 ? 1024 : pathconf("/",_PC_PATH_MAX); } #else /* not _POSIX_VERSION */ -#ifdef HAVE_CC_LIMITS_H -#include -#endif /* HAVE_CC_LIMITS_H */ - #ifdef HAVE_DIRENT_H -#include +# include #else /* not HAVE_DIRENT_H */ -#ifdef HAVE_SYS_DIR_H -#include -#endif /* HAVE_SYS_DIR_H */ +# ifdef HAVE_SYS_DIR_H +# include +# endif /* HAVE_SYS_DIR_H */ #endif /* not HAVE_DIRENT_H */ -#ifndef NAME_MAX -#ifdef MAXNAMLEN -#define NAME_MAX MAXNAMLEN -#else /* !MAXNAMLEN */ -#ifdef MAXNAMELEN -#define NAME_MAX MAXNAMELEN -#else /* !MAXNAMELEN */ -#define NAME_MAX 14 -#endif /* !MAXNAMELEN */ -#endif /* !MAXNAMLEN */ -#endif /* !NAME_MAX */ - -size_t file_name_max(const char *) +#ifndef PATH_MAX +# ifdef MAXPATHLEN +# define PATH_MAX MAXPATHLEN +# else /* !MAXPATHLEN */ +# ifdef MAX_PATH +# define PATH_MAX MAX_PATH +# else /* !MAX_PATH */ +# define PATH_MAX 255 +# endif /* !MAX_PATH */ +# endif /* !MAXPATHLEN */ +#endif /* !PATH_MAX */ + +size_t path_name_max() { - return NAME_MAX; + return PATH_MAX; } #endif /* not _POSIX_VERSION */ diff --git a/src/libs/libgroff/relocate.cpp b/src/libs/libgroff/relocate.cpp new file mode 100644 index 00000000..4e0821f4 --- /dev/null +++ b/src/libs/libgroff/relocate.cpp @@ -0,0 +1,232 @@ +// -*- C++ -*- +/* Provide relocation for macro and font files. + Copyright (C) 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + USA. */ + +// Made after relocation code in kpathsea and gettext. + +#include "lib.h" + +#include +#include + +#include "defs.h" +#include "posix.h" +#include "nonposix.h" +#include "relocate.h" + +#if defined _WIN32 +# define WIN32_LEAN_AND_MEAN +# include +#endif + +#define INSTALLPATHLEN (sizeof(INSTALLPATH) - 1) +#define DEBUG 0 + +extern "C" const char *program_name; + +// The prefix (parent directory) corresponding to the binary. +char *curr_prefix = 0; +size_t curr_prefix_len = 0; + +// Return the directory part of a filename, or `.' if no path separators. +char *xdirname(char *s) +{ + static const char dot[] = "."; + if (!s) + return 0; + // DIR_SEPS[] are possible directory separator characters, see nonposix.h. + // We want the rightmost separator of all possible ones. + // Example: d:/foo\\bar. + char *p = strrchr(s, DIR_SEPS[0]); + const char *sep = &DIR_SEPS[1]; + while (*sep) { + char *p1 = strrchr(s, *sep); + if (p1 && (!p || p1 > p)) + p = p1; + sep++; + } + if (p) + *p = '\0'; + else + s = (char *)dot; + return s; +} + +// Return the full path of NAME along the path PATHP. +// Adapted from search_path::open_file in searchpath.cpp. +char *searchpath(const char *name, const char *pathp) +{ + char *path; + if (!name || !*name) + return 0; +#if DEBUG + fprintf(stderr, "searchpath: pathp: `%s'\n", pathp); + fprintf(stderr, "searchpath: trying `%s'\n", name); +#endif + // Try first NAME as such; success if NAME is an absolute filename, + // or if NAME is found in the current directory. + if (!access (name, F_OK)) { + path = new char[path_name_max()]; + path = realpath(name, path); +#if DEBUG + fprintf(stderr, "searchpath: found `%s'\n", path); +#endif + return path; + } + // Secondly, try the current directory. + // Now search along PATHP. + size_t namelen = strlen(name); + char *p = (char *)pathp; + for (;;) { + char *end = strchr(p, PATH_SEP_CHAR); + if (!end) + end = strchr(p, '\0'); + int need_slash = end > p && strchr(DIR_SEPS, end[-1]) == 0; + path = new char[end - p + need_slash + namelen + 1]; + memcpy(path, p, end - p); + if (need_slash) + path[end - p] = '/'; + strcpy(path + (end - p) + need_slash, name); +#if DEBUG + fprintf(stderr, "searchpath: trying `%s'\n", path); +#endif + if (!access(path, F_OK)) { +#if DEBUG + fprintf(stderr, "searchpath: found `%s'\n", name); +#endif + return path; + } + a_delete path; + if (*end == '\0') + break; + p = end + 1; + } + return 0; +} + +// Search NAME along PATHP with the elements of PATHEXT in turn added. +char *searchpathext(const char *name, const char *pathext, const char *pathp) +{ + char *found = 0; + char *tmpathext = strsave(pathext); // strtok modifies this string, + // so make a copy + char *ext = strtok(tmpathext, PATH_SEP); + while (ext) { + char *namex = new char[strlen(name) + strlen(ext) + 1]; + strcpy(namex, name); + strcat(namex, ext); + found = searchpath(namex, pathp); + a_delete namex; + if (found) + break; + ext = strtok(0, PATH_SEP); + } + a_delete tmpathext; + return found; +} + +// Convert an MS path to a POSIX path. +char *msw2posixpath(char *path) +{ + char *s = path; + while (*s) { + if (*s == '\\') + *s = '/'; + *s++; + } + return path; +} + +// Compute the current prefix. +void set_current_prefix() +{ + char *pathextstr; + curr_prefix = new char[path_name_max()]; + // Obtain the full path of the current binary; + // using GetModuleFileName on MS-Windows, + // and searching along PATH on other systems. +#ifdef _WIN32 + int len = GetModuleFileName(0, curr_prefix, MAX_PATH); + if (len) + len = GetShortPathName(curr_prefix, curr_prefix, MAX_PATH); +# if DEBUG + fprintf(stderr, "curr_prefix: %s\n", curr_prefix); +# endif /* DEBUG */ +#else /* _WIN32 */ + curr_prefix = searchpath(program_name, getenv("PATH")); + if (!curr_prefix && !strchr(program_name, '.')) { // try with extensions + pathextstr = strsave(getenv("PATHEXT")); + if (!pathextstr) + pathextstr = strsave(PATH_EXT); + curr_prefix = searchpathext(program_name, pathextstr, getenv("PATH")); + a_delete pathextstr; + } + if (!curr_prefix) + return; +#endif /* _WIN32 */ + msw2posixpath(curr_prefix); +#if DEBUG + fprintf(stderr, "curr_prefix: %s\n", curr_prefix); +#endif + curr_prefix = xdirname(curr_prefix); // directory of executable + curr_prefix = xdirname(curr_prefix); // parent directory of executable + curr_prefix_len = strlen(curr_prefix); +#if DEBUG + fprintf(stderr, "curr_prefix: %s\n", curr_prefix); + fprintf(stderr, "curr_prefix_len: %d\n", curr_prefix_len); +#endif +} + +// Strip the installation prefix and replace it +// with the current installation prefix; return the relocated path. +char *relocatep(const char *path) +{ +#if DEBUG + fprintf(stderr, "relocatep: path = %s\n", path); + fprintf(stderr, "relocatep: INSTALLPATH = %s\n", INSTALLPATH); + fprintf(stderr, "relocatep: INSTALLPATHLEN = %d\n", INSTALLPATHLEN); +#endif + if (!curr_prefix) + set_current_prefix(); + if (strncmp(INSTALLPATH, path, INSTALLPATHLEN)) + return strsave(path); + char *relative_path = (char *)path + INSTALLPATHLEN; + size_t relative_path_len = strlen(relative_path); + char *relocated_path = new char[curr_prefix_len + relative_path_len + 1]; + strcpy(relocated_path, curr_prefix); + strcat(relocated_path, relative_path); +#if DEBUG + fprintf(stderr, "relocated_path: %s\n", relocated_path); +#endif /* DEBUG */ + return relocated_path; +} + +// Return the original pathname if it exists; +// otherwise return the relocated path. +char *relocate(const char *path) +{ + char *p; + if (access(path, F_OK)) + p = relocatep(path); + else + p = strsave(path); +#if DEBUG + fprintf (stderr, "relocate: %s\n", p); +#endif + return p; +} diff --git a/src/libs/libgroff/searchpath.cpp b/src/libs/libgroff/searchpath.cpp index 122f8e56..b14e2a84 100644 --- a/src/libs/libgroff/searchpath.cpp +++ b/src/libs/libgroff/searchpath.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2003 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -28,6 +28,12 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "searchpath.h" #include "nonposix.h" +#ifdef _WIN32 +# include "relocate.h" +#else +# define relocate(path) strsave(path) +#endif + search_path::search_path(const char *envvar, const char *standard, int add_home, int add_current) { @@ -108,11 +114,16 @@ FILE *search_path::open_file(const char *name, char **pathp) if (!end) end = strchr(p, '\0'); int need_slash = end > p && strchr(DIR_SEPS, end[-1]) == 0; - char *path = new char[(end - p) + need_slash + namelen + 1]; - memcpy(path, p, end - p); + char *origpath = new char[(end - p) + need_slash + namelen + 1]; + memcpy(origpath, p, end - p); if (need_slash) - path[end - p] = '/'; - strcpy(path + (end - p) + need_slash, name); + origpath[end - p] = '/'; + strcpy(origpath + (end - p) + need_slash, name); +#if 0 + fprintf(stderr, "origpath `%s'\n", origpath); +#endif + char *path = relocate(origpath); + a_delete origpath; #if 0 fprintf(stderr, "trying `%s'\n", path); #endif @@ -160,11 +171,16 @@ FILE *search_path::open_file_cautious(const char *name, char **pathp, if (!end) end = strchr(p, '\0'); int need_slash = end > p && strchr(DIR_SEPS, end[-1]) == 0; - char *path = new char[(end - p) + need_slash + namelen + 1]; - memcpy(path, p, end - p); + char *origpath = new char[(end - p) + need_slash + namelen + 1]; + memcpy(origpath, p, end - p); if (need_slash) - path[end - p] = '/'; - strcpy(path + (end - p) + need_slash, name); + origpath[end - p] = '/'; + strcpy(origpath + (end - p) + need_slash, name); +#if 0 + fprintf(stderr, "origpath `%s'\n", origpath); +#endif + char *path = relocate(origpath); + a_delete origpath; #if 0 fprintf(stderr, "trying `%s'\n", path); #endif -- 2.11.4.GIT