| 1 |
/* rm-suffix.c: remove any suffix. |
| 2 |
|
| 3 |
Copyright 2008, 2011, 2012 Karl Berry. |
| 4 |
Copyright 1992, 1993, 1995 Free Software Foundation, Inc. |
| 5 |
Modified for kpathsea by Karl Berry. |
| 6 |
|
| 7 |
This library is free software; you can redistribute it and/or |
| 8 |
modify it under the terms of the GNU Lesser General Public |
| 9 |
License as published by the Free Software Foundation; either |
| 10 |
version 2.1 of the License, or (at your option) any later version. |
| 11 |
|
| 12 |
This library is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
Lesser General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU Lesser General Public License |
| 18 |
along with this library; if not, see <http://www.gnu.org/licenses/>. */ |
| 19 |
|
| 20 |
#include <kpathsea/config.h> |
| 21 |
|
| 22 |
|
| 23 |
string |
| 24 |
remove_suffix (const_string s) |
| 25 |
{ |
| 26 |
string ret; |
| 27 |
const_string suffix = find_suffix (s); |
| 28 |
|
| 29 |
if (suffix) |
| 30 |
{ |
| 31 |
/* Back up to before the dot. */ |
| 32 |
suffix--; |
| 33 |
ret = (string) xmalloc (suffix - s + 1); |
| 34 |
strncpy (ret, s, suffix - s); |
| 35 |
ret[suffix - s] = 0; |
| 36 |
} |
| 37 |
else |
| 38 |
ret = xstrdup (s); |
| 39 |
|
| 40 |
return ret; |
| 41 |
} |