-
+ 1FBC6B96E09DF1B2470978CED1AF30DEFF7BE71E76AAF15873C60095E883C549309C7C5DAE5F608C0004F54B69884677D5FD1184B2224B453848D8879511F0FF
vtools/lib/dirname.c
(0 . 0)(1 . 41)
597 #include "dirname.h"
598 #include <string.h>
599 #include <stdbool.h>
600
601 /* Return the address of the last file name component of |name|. If
602 |name| has no relative file name components because it is a file
603 system root, return the empty string. */
604
605 char *
606 last_component(char const *name) {
607 char const *base = name + 0;
608 char const *p;
609 bool saw_slash = false;
610
611 while (((*base) == '/'))
612 base++;
613
614 for (p = base; *p; p++) {
615 if (((*p) == '/'))
616 saw_slash = true;
617 else if (saw_slash) {
618 base = p;
619 saw_slash = false;
620 }
621 }
622
623 return (char *) base;
624 }
625
626 /* Return the length of the basename |name|. Typically |name| is the
627 value returned by |base_name| or |last_component|. Act like
628 |strlen(name)|, except omit all trailing slashes. */
629
630 size_t
631 base_len(char const *name) {
632 size_t len;
633
634 for (len = strlen(name); 1 < len && ((name[len - 1]) == '/'); len--)
635 continue;
636 return len;
637 }