]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/basename.c
RISC-V: Add xfail test case for wv insn register overlap
[thirdparty/gcc.git] / libiberty / basename.c
CommitLineData
6599da04
JM
1/* Return the basename of a pathname.
2 This file is in the public domain. */
3
4/*
6599da04 5
aaa5f039 6@deftypefn Supplemental char* basename (const char *@var{name})
6599da04 7
aaa5f039
DD
8Returns a pointer to the last component of pathname @var{name}.
9Behavior is undefined if the pathname ends in a directory separator.
10
11@end deftypefn
6599da04 12
6599da04
JM
13*/
14
3c60ae5a
GDR
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
6599da04
JM
18#include "ansidecl.h"
19#include "libiberty.h"
f6bbde28 20#include "safe-ctype.h"
7f22ec2e
MK
21
22#ifndef DIR_SEPARATOR
23#define DIR_SEPARATOR '/'
24#endif
25
26#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
27 defined (__OS2__)
28#define HAVE_DOS_BASED_FILE_SYSTEM
29#ifndef DIR_SEPARATOR_2
30#define DIR_SEPARATOR_2 '\\'
31#endif
32#endif
33
34/* Define IS_DIR_SEPARATOR. */
35#ifndef DIR_SEPARATOR_2
36# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
37#else /* DIR_SEPARATOR_2 */
38# define IS_DIR_SEPARATOR(ch) \
39 (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
40#endif /* DIR_SEPARATOR_2 */
6599da04 41
6599da04 42char *
9486db4f 43basename (const char *name)
6599da04 44{
7f22ec2e 45 const char *base;
6599da04 46
7f22ec2e
MK
47#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
48 /* Skip over the disk name in MSDOS pathnames. */
f6bbde28 49 if (ISALPHA (name[0]) && name[1] == ':')
7f22ec2e
MK
50 name += 2;
51#endif
52
53 for (base = name; *name; name++)
6599da04 54 {
7f22ec2e 55 if (IS_DIR_SEPARATOR (*name))
6599da04 56 {
7f22ec2e 57 base = name + 1;
6599da04
JM
58 }
59 }
60 return (char *) base;
61}
7f22ec2e 62