blob: 8d9b6fc4110544a81f9521a542f2330f29d6b94c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
/* ISC license. */
#include <sys/types.h>
#include <skalibs/bytestr.h>
#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>
int sabasename (stralloc *sa, char const *s, size_t len)
{
if (!len) return stralloc_catb(sa, ".", 1) ;
while (len && (s[len-1] == '/')) len-- ;
if (!len) return stralloc_catb(sa, "/", 1) ;
{
size_t i = byte_rchr(s, len, '/') ;
i = (i == len) ? 0 : i+1 ;
return stralloc_catb(sa, s + i, len - i) ;
}
}
|