1 /* find-suffix.c: return the stuff after a dot.
3 Copyright 1992, 1993, 1995, 2008, 2011 Karl Berry.
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this library; if not, see <http://www.gnu.org/licenses/>. */
18 #include <kpathsea/config.h>
20 #include <kpathsea/c-pathch.h>
23 /* Return pointer to first character after `.' in last directory element
24 of NAME. If the name is `foo' or `/foo.bar/baz', we have no extension. */
26 /* The the result of strrchr(NAME, '.'), when not NULL, is a non-const
27 pointer into the string NAME. However, this is cheating (motivated
28 by limitations of the C language) when the argument NAME is a
29 const string, because in that case the (technically non-const) result
30 from strrchr() is certainly not modifiable.
32 We do not want to repeat this kind of cheating for find_suffix() and
33 therefore declare find_suffix(NAME) as const. When find_suffix(NAME)
34 is non-NULL and the argument NAME is modifiable (i.e., non-const)
35 then NAME+(find_suffix(NAME)-NAME) is an equivalent modifiable string
36 and the pointer arithmetic is optimized away by modern compilers. */
39 find_suffix (const_string name
)
41 const_string dot_pos
= strrchr (name
, '.');
47 for (p
= dot_pos
+ 1; *p
; p
++) {