diff options
author | Gary V. Vaughan <gary@gnu.org> | 2014-11-21 18:39:23 +0000 |
---|---|---|
committer | Gary V. Vaughan <gary@gnu.org> | 2014-11-21 18:39:23 +0000 |
commit | 2c19e82d5d813565abfc2aca0085e1da339416fd (patch) | |
tree | 6fdc251e2a6e22cc7439880cec5c3e5198afc90f | |
parent | 3285293706f3a2af3a3c5c97ec48c59a0b8bf63f (diff) | |
download | m4-2c19e82d5d813565abfc2aca0085e1da339416fd.tar.gz |
modules: support 8.3 truncated filenames.
* m4/path.c (TRUNCATE_FILENAME): New macro, defined on OS2.
(path_truncate): New function when TRUNCATE_FILENAME is defined,
otherwise a null-operation macro. Trim the basename to no more
than 8 characters, followed by the extension.
(m4_path_search): Use it.
Reported by Ko Myung-Hun
Signed-off-by: Gary V. Vaughan <gary@gnu.org>
-rw-r--r-- | m4/path.c | 45 |
1 files changed, 43 insertions, 2 deletions
@@ -34,6 +34,10 @@ #include "dirname.h" #include "filenamecat.h" +#if OS2 /* Any others? */ +# define TRUNCATE_FILENAME 1 +#endif + /* Define this to see runtime debug info. Implied by DEBUG. */ /*#define DEBUG_INCL */ @@ -127,6 +131,43 @@ include_env_init (m4 *context) } +#if TRUNCATE_FILENAME +/* Destructively modify PATH to contain no more than 8 non-`.' + characters, optionally followed by a `.' and a filenname extension + of 3 characters or fewer. */ +static char * +path_truncate (char *path) +{ + char *p, *beg = path; /* following final '/' */ + for (p = path; *p != '\0'; ++p) + { + if (ISSLASH (*p)) + beg = 1+ p; + } + + char *end = strchr (beg, '.'); /* first period */ + char *ext = strrchr (beg, '.'); /* last period */ + + size_t len = (size_t) (end - beg); /* length of filename element */ + if (len > 8) + end = beg + 8; + + if (ext == NULL) + { + *end = '\0'; + } + else if (ext != end) + { + stpncpy (end, ext, 4); + } + + return path; +} +#else +# define path_truncate(path) (path) +#endif + + /* Functions for normal input path search */ @@ -186,7 +227,7 @@ m4_path_search (m4 *context, const char *filename, const char **suffixes) size_t mem = strlen (filename); /* Try appending each of the suffixes we were given. */ - filepath = strncpy (xmalloc (mem + max_suffix_len +1), filename, mem); + filepath = path_truncate (strncpy (xmalloc (mem + max_suffix_len +1), filename, mem)); for (i = 0; suffixes && suffixes[i]; ++i) { strcpy (filepath + mem, suffixes[i]); @@ -227,7 +268,7 @@ m4_path_search (m4 *context, const char *filename, const char **suffixes) /* Capture errno only when searching `.'. */ e = errno; - filepath = strncpy (xmalloc (mem + max_suffix_len +1), pathname, mem); + filepath = path_truncate (strncpy (xmalloc (mem + max_suffix_len +1), pathname, mem)); free (pathname); for (i = 0; suffixes && suffixes[i]; ++i) |