OpenCoverage

basename-lgpl.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/basename-lgpl.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* basename.c -- return the last element in a file name-
2-
3 Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2018 Free Software-
4 Foundation, Inc.-
5-
6 This program is free software: you can redistribute it and/or modify-
7 it under the terms of the GNU General Public License as published by-
8 the Free Software Foundation; either version 3 of the License, or-
9 (at your option) any later version.-
10-
11 This program is distributed in the hope that it will be useful,-
12 but WITHOUT ANY WARRANTY; without even the implied warranty of-
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
14 GNU General Public License for more details.-
15-
16 You should have received a copy of the GNU General Public License-
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
18-
19#include <config.h>-
20-
21#include "dirname.h"-
22-
23#include <string.h>-
24-
25/* Return the address of the last file name component of NAME. If-
26 NAME has no relative file name components because it is a file-
27 system root, return the empty string. */-
28-
29char *-
30last_component (char const *name)-
31{-
32 char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);-
33 char const *p;-
34 bool saw_slash = false;-
35-
36 while (ISSLASH (*base))
((*base) == '/')Description
TRUEevaluated 12632 times by 12 tests
Evaluated by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • mktemp
  • mv
  • rm
  • rmdir
  • stdbuf
  • tac
FALSEevaluated 147069 times by 17 tests
Evaluated by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rm
  • rmdir
  • shred
  • split
  • stdbuf
  • tac
  • tail
  • vdir
12632-147069
37 base++;
executed 12632 times by 12 tests: base++;
Executed by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • mktemp
  • mv
  • rm
  • rmdir
  • stdbuf
  • tac
12632
38-
39 for (p = base; *p; p++)
*pDescription
TRUEevaluated 4194796 times by 17 tests
Evaluated by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rm
  • rmdir
  • shred
  • split
  • stdbuf
  • tac
  • tail
  • vdir
FALSEevaluated 147069 times by 17 tests
Evaluated by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rm
  • rmdir
  • shred
  • split
  • stdbuf
  • tac
  • tail
  • vdir
147069-4194796
40 {-
41 if (ISSLASH (*p))
((*p) == '/')Description
TRUEevaluated 115906 times by 15 tests
Evaluated by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rm
  • rmdir
  • split
  • stdbuf
  • tac
  • tail
FALSEevaluated 4078890 times by 17 tests
Evaluated by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rm
  • rmdir
  • shred
  • split
  • stdbuf
  • tac
  • tail
  • vdir
115906-4078890
42 saw_slash = true;
executed 115906 times by 15 tests: saw_slash = 1 ;
Executed by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rm
  • rmdir
  • split
  • stdbuf
  • tac
  • tail
115906
43 else if (saw_slash)
saw_slashDescription
TRUEevaluated 115839 times by 15 tests
Evaluated by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rm
  • rmdir
  • split
  • stdbuf
  • tac
  • tail
FALSEevaluated 3963051 times by 17 tests
Evaluated by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rm
  • rmdir
  • shred
  • split
  • stdbuf
  • tac
  • tail
  • vdir
115839-3963051
44 {-
45 base = p;-
46 saw_slash = false;-
47 }
executed 115839 times by 15 tests: end of block
Executed by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rm
  • rmdir
  • split
  • stdbuf
  • tac
  • tail
115839
48 }
executed 4194796 times by 17 tests: end of block
Executed by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rm
  • rmdir
  • shred
  • split
  • stdbuf
  • tac
  • tail
  • vdir
4194796
49-
50 return (char *) base;
executed 147069 times by 17 tests: return (char *) base;
Executed by:
  • basename
  • cp
  • dircolors
  • dirname
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rm
  • rmdir
  • shred
  • split
  • stdbuf
  • tac
  • tail
  • vdir
147069
51}-
52-
53/* Return the length of the basename NAME. Typically NAME is the-
54 value returned by base_name or last_component. Act like strlen-
55 (NAME), except omit all trailing slashes. */-
56-
57size_t-
58base_len (char const *name)-
59{-
60 size_t len;-
61 size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);-
62-
63 for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
1 < lenDescription
TRUEevaluated 136549 times by 9 tests
Evaluated by:
  • basename
  • cp
  • ginstall
  • ln
  • mktemp
  • mv
  • rmdir
  • shred
  • tac
FALSEevaluated 518 times by 9 tests
Evaluated by:
  • basename
  • cp
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rmdir
  • shred
((name[len - 1]) == '/')Description
TRUEevaluated 52 times by 6 tests
Evaluated by:
  • basename
  • cp
  • ginstall
  • ln
  • mv
  • rmdir
FALSEevaluated 136497 times by 9 tests
Evaluated by:
  • basename
  • cp
  • ginstall
  • ln
  • mktemp
  • mv
  • rmdir
  • shred
  • tac
52-136549
64 continue;
executed 52 times by 6 tests: continue;
Executed by:
  • basename
  • cp
  • ginstall
  • ln
  • mv
  • rmdir
52
65-
66 if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
dead code: len == 1
-
67 && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
dead code: ((name[0]) == '/')
dead code: ((name[1]) == '/')
dead code: ! name[2]
dead code: return 2;
-
68 return 2;
dead code: return 2;
-
69-
70 if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
dead code: prefix_len
-
71 && len == prefix_len && ISSLASH (name[prefix_len]))
dead code: len == prefix_len
dead code: ((name[prefix_len]) == '/')
dead code: return prefix_len + 1;
-
72 return prefix_len + 1;
dead code: return prefix_len + 1;
-
73-
74 return len;
executed 137015 times by 10 tests: return len;
Executed by:
  • basename
  • cp
  • ginstall
  • ln
  • ls
  • mktemp
  • mv
  • rmdir
  • shred
  • tac
137015
75}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2