Wed, 08 May 2019 19:22:06 +0200
reduces code complexity of util_resource_name()
libidav/utils.c | file | annotate | diff | comparison | revisions |
--- a/libidav/utils.c Mon Apr 22 14:04:37 2019 +0200 +++ b/libidav/utils.c Wed May 08 19:22:06 2019 +0200 @@ -529,29 +529,16 @@ } char* util_resource_name(char *url) { - int si = 0; - int osi = 0; - int i = 0; - int p = 0; - char c; - while((c = url[i]) != 0) { - if(c == '/') { - osi = si; - si = i; - p = 1; - } - i++; + sstr_t urlstr = sstr(url); + if(urlstr.ptr[urlstr.length-1] == '/') { + urlstr.length--; } - - char *name = url + si + p; - if(name[0] == 0) { - name = url + osi + p; - if(name[0] == 0) { - return url; - } + sstr_t resname = sstrrchr(urlstr, '/'); + if(resname.length > 1) { + return resname.ptr+1; + } else { + return url; } - - return name; } int util_mkdir(char *path, mode_t mode) {