repo.or.cz
/
thunix.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
kbd: use a better get_key method
[thunix.git]
/
fs
/
fslib.c
blob
8e239e182d872c09730780f1cceedf811d732270
1
#include <stdio.h>
2
#include <string.h>
3
#include <malloc.h>
4
5
const char
*
get_base_name
(
const char
*
path_org
)
6
{
7
char
*
p
;
8
char
*
path
=
strdup
(
path_org
);
9
10
p
=
strrchr
(
path
,
'/'
);
11
if
(!
p
) {
12
free
(
path
);
13
return
path_org
;
14
}
15
/* the /linux/hello/ case */
16
if
(*(
p
+
1
) ==
0
) {
17
*
p
=
0
;
18
p
--;
19
while
(*
p
!=
'/'
&&
p
>=
path
) {
20
*
p
=
0
;
21
p
--;
22
}
23
if
(
p
<
path
)
24
return
NULL
;
25
}
26
27
return
p
+
1
;
28
}