From 89755f7344de571c4b1b7c68e90de39363a4d1ff Mon Sep 17 00:00:00 2001 From: Peter Breitenlohner Date: Wed, 20 Jul 2011 07:00:05 +0000 Subject: libs/t1lib + texk/ps2pkm: bug fix and update git-svn-id: svn://tug.org/texlive/trunk@23187 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/kpathsea/find-suffix.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'Build/source/texk/kpathsea/find-suffix.c') 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; -- cgit v1.2.3