summaryrefslogtreecommitdiff
path: root/Build/source/texk/kpathsea/find-suffix.c
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2011-07-20 07:00:05 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2011-07-20 07:00:05 +0000
commit89755f7344de571c4b1b7c68e90de39363a4d1ff (patch)
treed735587f7030f0536272048df7a4b53cefc133a4 /Build/source/texk/kpathsea/find-suffix.c
parent713aef9b071ca2b5dd68d014e99897f0e5e2036c (diff)
libs/t1lib + texk/ps2pkm: bug fix and update
git-svn-id: svn://tug.org/texlive/trunk@23187 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/kpathsea/find-suffix.c')
-rw-r--r--Build/source/texk/kpathsea/find-suffix.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/Build/source/texk/kpathsea/find-suffix.c b/Build/source/texk/kpathsea/find-suffix.c
index 6fbb1f28c6b..107e1917de0 100644
--- a/Build/source/texk/kpathsea/find-suffix.c
+++ b/Build/source/texk/kpathsea/find-suffix.c
@@ -23,11 +23,23 @@
/* Return pointer to first character after `.' in last directory element
of NAME. If the name is `foo' or `/foo.bar/baz', we have no extension. */
-string
+/* The the result of strrchr(NAME, '.'), when not NULL, is a non-const
+ pointer into the string NAME. However, this is cheating (motivated
+ by limitations of the C language) when the argument NAME is a
+ const string, because in that case the (technically non-const) result
+ from strrchr() is certainly not modifiable.
+
+ We do not want to repeat this kind of cheating for find_suffix() and
+ therefore declare find_suffix(NAME) as const. When find_suffix(NAME)
+ is non-NULL and the argument NAME is modifiable (i.e., non-const)
+ then NAME+(find_suffix(NAME)-NAME) is an equivalent modifiable string
+ and the pointer arithmetic is optimized away by modern compilers. */
+
+const_string
find_suffix (const_string name)
{
const_string slash_pos;
- string dot_pos = strrchr (name, '.');
+ const_string dot_pos = strrchr (name, '.');
if (dot_pos == NULL)
return NULL;