1/* Copyright (C) 2011 Monty Program Ab
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16#include <my_global.h>
17#include <my_sys.h>
18/**
19 @brief retrieve last component of the filename.
20 Loosely based on Single Unix Spec definition.
21
22 @fn my_basename()
23 @param filename Filename
24*/
25const char *my_basename(const char *filename)
26{
27 const char *last;
28 const char *s=filename;
29
30 /* Handle basename()'s special cases, as per single unix spec */
31 if (!filename || !filename[0])
32 return ".";
33 if(filename[0] == '/' && filename[1]== '\0')
34 return filename;
35
36 for(last= s; *s; s++)
37 {
38 if (*s == '/' || *s == '\\')
39 last= s + 1;
40 }
41 return last;
42}
43