OpenCoverage

system.h

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/system.h
Source codeSwitch to Preprocessed file
LineSourceCount
1/* system-dependent definitions for coreutils-
2 Copyright (C) 1989-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation, either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17/* Include this file _after_ system headers if possible. */-
18-
19#include <alloca.h>-
20-
21#include <sys/stat.h>-
22-
23/* Commonly used file permission combination. */-
24#define MODE_RW_UGO (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)-
25-
26#if !defined HAVE_MKFIFO-
27# define mkfifo(name, mode) mknod (name, (mode) | S_IFIFO, 0)-
28#endif-
29-
30#if HAVE_SYS_PARAM_H-
31# include <sys/param.h>-
32#endif-
33-
34#include <unistd.h>-
35-
36#include <limits.h>-
37-
38#include "pathmax.h"-
39#ifndef PATH_MAX-
40# define PATH_MAX 8192-
41#endif-
42-
43#include "configmake.h"-
44-
45#include <sys/time.h>-
46#include <time.h>-
47-
48/* Since major is a function on SVR4, we can't use 'ifndef major'. */-
49#if MAJOR_IN_MKDEV-
50# include <sys/mkdev.h>-
51# define HAVE_MAJOR-
52#endif-
53#if MAJOR_IN_SYSMACROS-
54# include <sys/sysmacros.h>-
55# define HAVE_MAJOR-
56#endif-
57#ifdef major /* Might be defined in sys/types.h. */-
58# define HAVE_MAJOR-
59#endif-
60-
61#ifndef HAVE_MAJOR-
62# define major(dev) (((dev) >> 8) & 0xff)-
63# define minor(dev) ((dev) & 0xff)-
64# define makedev(maj, min) (((maj) << 8) | (min))-
65#endif-
66#undef HAVE_MAJOR-
67-
68#if ! defined makedev && defined mkdev-
69# define makedev(maj, min) mkdev (maj, min)-
70#endif-
71-
72#include <string.h>-
73#include <errno.h>-
74-
75/* Some systems don't define this; POSIX mentions it but says it is-
76 obsolete. gnulib defines it, but only on native Windows systems,-
77 and there only because MSVC 10 does. */-
78#ifndef ENODATA-
79# define ENODATA (-1)-
80#endif-
81-
82#include <stdbool.h>-
83#include <stdlib.h>-
84#include "version.h"-
85-
86/* Exit statuses for programs like 'env' that exec other programs. */-
87enum-
88{-
89 EXIT_TIMEDOUT = 124, /* Time expired before child completed. */-
90 EXIT_CANCELED = 125, /* Internal error prior to exec attempt. */-
91 EXIT_CANNOT_INVOKE = 126, /* Program located, but not usable. */-
92 EXIT_ENOENT = 127 /* Could not find program to exec. */-
93};-
94-
95#include "exitfail.h"-
96-
97/* Set exit_failure to STATUS if that's not the default already. */-
98static inline void-
99initialize_exit_failure (int status)-
100{-
101 if (status != EXIT_FAILURE)
status != 1Description
TRUEevaluated 7901 times by 15 tests
Evaluated by:
  • [
  • chroot
  • dir
  • env
  • expr
  • ls
  • nice
  • nohup
  • printenv
  • sort
  • stdbuf
  • test
  • timeout
  • tty
  • vdir
FALSEevaluated 27 times by 1 test
Evaluated by:
  • getlimits
27-7901
102 exit_failure = status;
executed 7901 times by 15 tests: exit_failure = status;
Executed by:
  • [
  • chroot
  • dir
  • env
  • expr
  • ls
  • nice
  • nohup
  • printenv
  • sort
  • stdbuf
  • test
  • timeout
  • tty
  • vdir
7901
103}
executed 7928 times by 16 tests: end of block
Executed by:
  • [
  • chroot
  • dir
  • env
  • expr
  • getlimits
  • ls
  • nice
  • nohup
  • printenv
  • sort
  • stdbuf
  • test
  • timeout
  • tty
  • vdir
7928
104-
105#include <fcntl.h>-
106-
107#include <dirent.h>-
108#ifndef _D_EXACT_NAMLEN-
109# define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name)-
110#endif-
111-
112enum-
113{-
114 NOT_AN_INODE_NUMBER = 0-
115};-
116-
117#ifdef D_INO_IN_DIRENT-
118# define D_INO(dp) (dp)->d_ino-
119#else-
120/* Some systems don't have inodes, so fake them to avoid lots of ifdefs. */-
121# define D_INO(dp) NOT_AN_INODE_NUMBER-
122#endif-
123-
124/* include here for SIZE_MAX. */-
125#include <inttypes.h>-
126-
127/* Redirection and wildcarding when done by the utility itself.-
128 Generally a noop, but used in particular for OS/2. */-
129#ifndef initialize_main-
130# ifndef __OS2__-
131# define initialize_main(ac, av)-
132# else-
133# define initialize_main(ac, av) \-
134 do { _wildcard (ac, av); _response (ac, av); } while (0)-
135# endif-
136#endif-
137-
138#include "stat-macros.h"-
139-
140#include "timespec.h"-
141-
142#include <ctype.h>-
143-
144/* ISDIGIT differs from isdigit, as follows:-
145 - Its arg may be any int or unsigned int; it need not be an unsigned char-
146 or EOF.-
147 - It's typically faster.-
148 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to-
149 isdigit unless it's important to use the locale's definition-
150 of 'digit' even when the host does not conform to POSIX. */-
151#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)-
152-
153/* Convert a possibly-signed character to an unsigned character. This is-
154 a bit safer than casting to unsigned char, since it catches some type-
155 errors that the cast doesn't. */-
156static
executed 2568664 times by 21 tests: return ch;
Executed by:
  • cut
  • dd
  • df
  • dir
  • dircolors
  • expand
  • fold
  • ls
  • numfmt
  • pr
  • printf
  • ptx
  • seq
  • sort
  • split
  • stat
  • test
  • tr
  • truncate
  • unexpand
  • wc
inline unsigned char to_uchar (char ch) { return ch; }
executed 2568664 times by 21 tests: return ch;
Executed by:
  • cut
  • dd
  • df
  • dir
  • dircolors
  • expand
  • fold
  • ls
  • numfmt
  • pr
  • printf
  • ptx
  • seq
  • sort
  • split
  • stat
  • test
  • tr
  • truncate
  • unexpand
  • wc
2568664
157-
158/* '\n' is considered a field separator with --zero-terminated. */-
159static inline bool-
160field_sep (unsigned char ch)-
161{-
162 return isblank (ch) || ch == '\n';
executed 392533 times by 4 tests: return ((*__ctype_b_loc ())[(int) (( ch ))] & (unsigned short int) _ISblank) || ch == '\n';
Executed by:
  • join
  • numfmt
  • sort
  • uniq
392533
163}-
164-
165#include <locale.h>-
166-
167/* Take care of NLS matters. */-
168-
169#include "gettext.h"-
170#if ! ENABLE_NLS-
171# undef textdomain-
172# define textdomain(Domainname) /* empty */-
173# undef bindtextdomain-
174# define bindtextdomain(Domainname, Dirname) /* empty */-
175#endif-
176-
177#define _(msgid) gettext (msgid)-
178#define N_(msgid) msgid-
179-
180/* Return a value that pluralizes the same way that N does, in all-
181 languages we know of. */-
182static inline unsigned long int-
183select_plural (uintmax_t n)-
184{-
185 /* Reduce by a power of ten, but keep it away from zero. The-
186 gettext manual says 1000000 should be safe. */-
187 enum { PLURAL_REDUCER = 1000000 };-
188 return (n <= ULONG_MAX ? n : n % PLURAL_REDUCER + PLURAL_REDUCER);
executed 94 times by 4 tests: return (n <= (0x7fffffffffffffffL * 2UL + 1UL) ? n : n % PLURAL_REDUCER + PLURAL_REDUCER);
Executed by:
  • dd
  • md5sum
  • rm
  • sort
94
189}-
190-
191#define STREQ(a, b) (strcmp (a, b) == 0)-
192#define STREQ_LEN(a, b, n) (strncmp (a, b, n) == 0)-
193#define STRPREFIX(a, b) (strncmp (a, b, strlen (b)) == 0)-
194-
195/* Just like strncmp, but the second argument must be a literal string-
196 and you don't specify the length; that comes from the literal. */-
197#define STRNCMP_LIT(s, lit) strncmp (s, "" lit "", sizeof (lit) - 1)-
198-
199#if !HAVE_DECL_GETLOGIN-
200char *getlogin (void);-
201#endif-
202-
203#if !HAVE_DECL_TTYNAME-
204char *ttyname (int);-
205#endif-
206-
207#if !HAVE_DECL_GETEUID-
208uid_t geteuid (void);-
209#endif-
210-
211#if !HAVE_DECL_GETPWUID-
212struct passwd *getpwuid (uid_t);-
213#endif-
214-
215#if !HAVE_DECL_GETGRGID-
216struct group *getgrgid (gid_t);-
217#endif-
218-
219/* Interix has replacements for getgr{gid,nam,ent}, that don't-
220 query the domain controller for group members when not required.-
221 This speeds up the calls tremendously (<1 ms vs. >3 s). */-
222/* To protect any system that could provide _nomembers functions-
223 other than interix, check for HAVE_SETGROUPS, as interix is-
224 one of the very few (the only?) platform that lacks it */-
225#if ! HAVE_SETGROUPS-
226# if HAVE_GETGRGID_NOMEMBERS-
227# define getgrgid(gid) getgrgid_nomembers(gid)-
228# endif-
229# if HAVE_GETGRNAM_NOMEMBERS-
230# define getgrnam(nam) getgrnam_nomembers(nam)-
231# endif-
232# if HAVE_GETGRENT_NOMEMBERS-
233# define getgrent() getgrent_nomembers()-
234# endif-
235#endif-
236-
237#if !HAVE_DECL_GETUID-
238uid_t getuid (void);-
239#endif-
240-
241#include "xalloc.h"-
242#include "verify.h"-
243-
244/* This is simply a shorthand for the common case in which-
245 the third argument to x2nrealloc would be 'sizeof *(P)'.-
246 Ensure that sizeof *(P) is *not* 1. In that case, it'd be-
247 better to use X2REALLOC, although not strictly necessary. */-
248#define X2NREALLOC(P, PN) ((void) verify_true (sizeof *(P) != 1), \-
249 x2nrealloc (P, PN, sizeof *(P)))-
250-
251/* Using x2realloc (when appropriate) usually makes your code more-
252 readable than using x2nrealloc, but it also makes it so your-
253 code will malfunction if sizeof *(P) ever becomes 2 or greater.-
254 So use this macro instead of using x2realloc directly. */-
255#define X2REALLOC(P, PN) ((void) verify_true (sizeof *(P) == 1), \-
256 x2realloc (P, PN))-
257-
258#include "unlocked-io.h"-
259#include "same-inode.h"-
260-
261#include "dirname.h"-
262#include "openat.h"-
263-
264static inline bool-
265dot_or_dotdot (char const *file_name)-
266{-
267 if (file_name[0] == '.')
file_name[0] == '.'Description
TRUEevaluated 112871 times by 3 tests
Evaluated by:
  • cp
  • mv
  • rm
FALSEevaluated 20510 times by 5 tests
Evaluated by:
  • cp
  • ginstall
  • ls
  • mv
  • rm
20510-112871
268 {-
269 char sep = file_name[(file_name[1] == '.') + 1];-
270 return (! sep || ISSLASH (sep));
executed 112871 times by 3 tests: return (! sep || ((sep) == '/'));
Executed by:
  • cp
  • mv
  • rm
112871
271 }-
272 else-
273 return false;
executed 20510 times by 5 tests: return 0 ;
Executed by:
  • cp
  • ginstall
  • ls
  • mv
  • rm
20510
274}-
275-
276/* A wrapper for readdir so that callers don't see entries for '.' or '..'. */-
277static inline struct dirent const *-
278readdir_ignoring_dot_and_dotdot (DIR *dirp)-
279{-
280 while (1)-
281 {-
282 struct dirent const *dp = readdir (dirp);-
283 if (dp == NULL || ! dot_or_dotdot (dp->d_name))
dp == ((void *)0)Description
TRUEevaluated 40245 times by 2 tests
Evaluated by:
  • mv
  • rm
FALSEevaluated 129107 times by 2 tests
Evaluated by:
  • mv
  • rm
! dot_or_dotdot (dp->d_name)Description
TRUEevaluated 16242 times by 2 tests
Evaluated by:
  • mv
  • rm
FALSEevaluated 112865 times by 2 tests
Evaluated by:
  • mv
  • rm
16242-129107
284 return dp;
executed 56487 times by 2 tests: return dp;
Executed by:
  • mv
  • rm
56487
285 }
executed 112865 times by 2 tests: end of block
Executed by:
  • mv
  • rm
112865
286}
never executed: end of block
0
287-
288/* Return true if DIR is determined to be an empty directory. */-
289static inline bool-
290is_empty_dir (int fd_cwd, char const *dir)-
291{-
292 DIR *dirp;-
293 struct dirent const *dp;-
294 int saved_errno;-
295 int fd = openat (fd_cwd, dir,-
296 (O_RDONLY | O_DIRECTORY-
297 | O_NOCTTY | O_NOFOLLOW | O_NONBLOCK));-
298-
299 if (fd < 0)
fd < 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • rm
FALSEevaluated 56487 times by 2 tests
Evaluated by:
  • mv
  • rm
5-56487
300 return false;
executed 5 times by 1 test: return 0 ;
Executed by:
  • rm
5
301-
302 dirp = fdopendir (fd);-
303 if (dirp == NULL)
dirp == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 56487 times by 2 tests
Evaluated by:
  • mv
  • rm
0-56487
304 {-
305 close (fd);-
306 return false;
never executed: return 0 ;
0
307 }-
308-
309 errno = 0;-
310 dp = readdir_ignoring_dot_and_dotdot (dirp);-
311 saved_errno = errno;-
312 closedir (dirp);-
313 if (dp != NULL)
dp != ((void *)0)Description
TRUEevaluated 16242 times by 2 tests
Evaluated by:
  • mv
  • rm
FALSEevaluated 40245 times by 2 tests
Evaluated by:
  • mv
  • rm
16242-40245
314 return false;
executed 16242 times by 2 tests: return 0 ;
Executed by:
  • mv
  • rm
16242
315 return saved_errno == 0 ? true : false;
executed 40245 times by 2 tests: return saved_errno == 0 ? 1 : 0 ;
Executed by:
  • mv
  • rm
40245
316}-
317-
318/* Factor out some of the common --help and --version processing code. */-
319-
320/* These enum values cannot possibly conflict with the option values-
321 ordinarily used by commands, including CHAR_MAX + 1, etc. Avoid-
322 CHAR_MIN - 1, as it may equal -1, the getopt end-of-options value. */-
323enum-
324{-
325 GETOPT_HELP_CHAR = (CHAR_MIN - 2),-
326 GETOPT_VERSION_CHAR = (CHAR_MIN - 3)-
327};-
328-
329#define GETOPT_HELP_OPTION_DECL \-
330 "help", no_argument, NULL, GETOPT_HELP_CHAR-
331#define GETOPT_VERSION_OPTION_DECL \-
332 "version", no_argument, NULL, GETOPT_VERSION_CHAR-
333#define GETOPT_SELINUX_CONTEXT_OPTION_DECL \-
334 "context", optional_argument, NULL, 'Z'-
335-
336#define case_GETOPT_HELP_CHAR \-
337 case GETOPT_HELP_CHAR: \-
338 usage (EXIT_SUCCESS); \-
339 break;-
340-
341/* Program_name must be a literal string.-
342 Usually it is just PROGRAM_NAME. */-
343#define USAGE_BUILTIN_WARNING \-
344 _("\n" \-
345"NOTE: your shell may have its own version of %s, which usually supersedes\n" \-
346"the version described here. Please refer to your shell's documentation\n" \-
347"for details about the options it supports.\n")-
348-
349#define HELP_OPTION_DESCRIPTION \-
350 _(" --help display this help and exit\n")-
351#define VERSION_OPTION_DESCRIPTION \-
352 _(" --version output version information and exit\n")-
353-
354#include "closein.h"-
355#include "closeout.h"-
356-
357#define emit_bug_reporting_address unused__emit_bug_reporting_address-
358#include "version-etc.h"-
359#undef emit_bug_reporting_address-
360-
361#include "propername.h"-
362/* Define away proper_name (leaving proper_name_utf8, which affects far-
363 fewer programs), since it's not worth the cost of adding ~17KB to-
364 the x86_64 text size of every single program. This avoids a 40%-
365 (almost ~2MB) increase in the on-disk space utilization for the set-
366 of the 100 binaries. */-
367#define proper_name(x) (x)-
368-
369#include "progname.h"-
370-
371#define case_GETOPT_VERSION_CHAR(Program_name, Authors) \-
372 case GETOPT_VERSION_CHAR: \-
373 version_etc (stdout, Program_name, PACKAGE_NAME, Version, Authors, \-
374 (char *) NULL); \-
375 exit (EXIT_SUCCESS); \-
376 break;-
377-
378#ifndef MAX-
379# define MAX(a, b) ((a) > (b) ? (a) : (b))-
380#endif-
381-
382#ifndef MIN-
383# define MIN(a,b) (((a) < (b)) ? (a) : (b))-
384#endif-
385-
386#include "intprops.h"-
387-
388#ifndef SSIZE_MAX-
389# define SSIZE_MAX TYPE_MAXIMUM (ssize_t)-
390#endif-
391-
392#ifndef OFF_T_MIN-
393# define OFF_T_MIN TYPE_MINIMUM (off_t)-
394#endif-
395-
396#ifndef OFF_T_MAX-
397# define OFF_T_MAX TYPE_MAXIMUM (off_t)-
398#endif-
399-
400#ifndef UID_T_MAX-
401# define UID_T_MAX TYPE_MAXIMUM (uid_t)-
402#endif-
403-
404#ifndef GID_T_MAX-
405# define GID_T_MAX TYPE_MAXIMUM (gid_t)-
406#endif-
407-
408#ifndef PID_T_MAX-
409# define PID_T_MAX TYPE_MAXIMUM (pid_t)-
410#endif-
411-
412/* Use this to suppress gcc's '...may be used before initialized' warnings. */-
413#ifdef lint-
414# define IF_LINT(Code) Code-
415#else-
416# define IF_LINT(Code) /* empty */-
417#endif-
418-
419#ifndef __attribute__-
420# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)-
421# define __attribute__(x) /* empty */-
422# endif-
423#endif-
424-
425#ifndef ATTRIBUTE_NORETURN-
426# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))-
427#endif-
428-
429/* The warn_unused_result attribute appeared first in gcc-3.4.0 */-
430#undef ATTRIBUTE_WARN_UNUSED_RESULT-
431#if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)-
432# define ATTRIBUTE_WARN_UNUSED_RESULT /* empty */-
433#else-
434# define ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))-
435#endif-
436-
437#ifdef __GNUC__-
438# define LIKELY(cond) __builtin_expect ((cond), 1)-
439# define UNLIKELY(cond) __builtin_expect ((cond), 0)-
440#else-
441# define LIKELY(cond) (cond)-
442# define UNLIKELY(cond) (cond)-
443#endif-
444-
445-
446#if defined strdupa-
447# define ASSIGN_STRDUPA(DEST, S) \-
448 do { DEST = strdupa (S); } while (0)-
449#else-
450# define ASSIGN_STRDUPA(DEST, S) \-
451 do \-
452 { \-
453 const char *s_ = (S); \-
454 size_t len_ = strlen (s_) + 1; \-
455 char *tmp_dest_ = alloca (len_); \-
456 DEST = memcpy (tmp_dest_, s_, len_); \-
457 } \-
458 while (0)-
459#endif-
460-
461#if ! HAVE_SYNC-
462# define sync() /* empty */-
463#endif-
464-
465/* Compute the greatest common divisor of U and V using Euclid's-
466 algorithm. U and V must be nonzero. */-
467-
468static inline size_t _GL_ATTRIBUTE_CONST-
469gcd (size_t u, size_t v)-
470{-
471 do-
472 {-
473 size_t t = u % v;-
474 u = v;-
475 v = t;-
476 }
executed 1507 times by 1 test: end of block
Executed by:
  • od
1507
477 while (v);
vDescription
TRUEevaluated 542 times by 1 test
Evaluated by:
  • od
FALSEevaluated 965 times by 1 test
Evaluated by:
  • od
542-965
478-
479 return u;
executed 965 times by 1 test: return u;
Executed by:
  • od
965
480}-
481-
482/* Compute the least common multiple of U and V. U and V must be-
483 nonzero. There is no overflow checking, so callers should not-
484 specify outlandish sizes. */-
485-
486static inline size_t _GL_ATTRIBUTE_CONST-
487lcm (size_t u, size_t v)-
488{-
489 return u * (v / gcd (u, v));
executed 965 times by 1 test: return u * (v / gcd (u, v));
Executed by:
  • od
965
490}-
491-
492/* Return PTR, aligned upward to the next multiple of ALIGNMENT.-
493 ALIGNMENT must be nonzero. The caller must arrange for ((char *)-
494 PTR) through ((char *) PTR + ALIGNMENT - 1) to be addressable-
495 locations. */-
496-
497static inline void *-
498ptr_align (void const *ptr, size_t alignment)-
499{-
500 char const *p0 = ptr;-
501 char const *p1 = p0 + alignment - 1;-
502 return (void *) (p1 - (size_t) p1 % alignment);
executed 8681 times by 14 tests: return (void *) (p1 - (size_t) p1 % alignment);
Executed by:
  • b2sum
  • cat
  • cp
  • dd
  • ginstall
  • md5sum
  • mv
  • sha1sum
  • sha224sum
  • sha256sum
  • sha384sum
  • sha512sum
  • shred
  • split
8681
503}-
504-
505/* Return whether the buffer consists entirely of NULs.-
506 Based on memeqzero in CCAN by Rusty Russell under CC0 (Public domain). */-
507-
508static inline bool _GL_ATTRIBUTE_PURE-
509is_nul (void const *buf, size_t length)-
510{-
511 const unsigned char *p = buf;-
512/* Using possibly unaligned access for the first 16 bytes-
513 saves about 30-40 cycles, though it is strictly undefined behavior-
514 and so would need __attribute__ ((__no_sanitize_undefined__))-
515 to avoid -fsanitize=undefined warnings.-
516 Considering coreutils is mainly concerned with relatively-
517 large buffers, we'll just use the defined behavior. */-
518#if 0 && (_STRING_ARCH_unaligned || _STRING_INLINE_unaligned)-
519 unsigned long word;-
520#else-
521 unsigned char word;-
522#endif-
523-
524 if (! length)
! lengthDescription
TRUEnever evaluated
FALSEevaluated 8017 times by 2 tests
Evaluated by:
  • cp
  • dd
0-8017
525 return true;
never executed: return 1 ;
0
526-
527 /* Check len bytes not aligned on a word. */-
528 while (UNLIKELY (length & (sizeof word - 1)))
__builtin_expe...word - 1)), 0)Description
TRUEnever evaluated
FALSEevaluated 8017 times by 2 tests
Evaluated by:
  • cp
  • dd
0-8017
529 {-
530 if (*p)
*pDescription
TRUEnever evaluated
FALSEnever evaluated
0
531 return false;
never executed: return 0 ;
0
532 p++;-
533 length--;-
534 if (! length)
! lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
535 return true;
never executed: return 1 ;
0
536 }
never executed: end of block
0
537-
538 /* Check up to 16 bytes a word at a time. */-
539 for (;;)-
540 {-
541 memcpy (&word, p, sizeof word);-
542 if (word)
wordDescription
TRUEevaluated 5237 times by 2 tests
Evaluated by:
  • cp
  • dd
FALSEevaluated 44405 times by 2 tests
Evaluated by:
  • cp
  • dd
5237-44405
543 return false;
executed 5237 times by 2 tests: return 0 ;
Executed by:
  • cp
  • dd
5237
544 p += sizeof word;-
545 length -= sizeof word;-
546 if (! length)
! lengthDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 44400 times by 2 tests
Evaluated by:
  • cp
  • dd
5-44400
547 return true;
executed 5 times by 1 test: return 1 ;
Executed by:
  • dd
5
548 if (UNLIKELY (length & 15) == 0)
__builtin_expe...& 15), 0) == 0Description
TRUEevaluated 2775 times by 2 tests
Evaluated by:
  • cp
  • dd
FALSEevaluated 41625 times by 2 tests
Evaluated by:
  • cp
  • dd
2775-41625
549 break;
executed 2775 times by 2 tests: break;
Executed by:
  • cp
  • dd
2775
550 }
executed 41625 times by 2 tests: end of block
Executed by:
  • cp
  • dd
41625
551-
552 /* Now we know first 16 bytes are NUL, memcmp with self. */-
553 return memcmp (buf, p, length) == 0;
executed 2775 times by 2 tests: return memcmp (buf, p, length) == 0;
Executed by:
  • cp
  • dd
2775
554}-
555-
556/* If 10*Accum + Digit_val is larger than the maximum value for Type,-
557 then don't update Accum and return false to indicate it would-
558 overflow. Otherwise, set Accum to that new value and return true.-
559 Verify at compile-time that Type is Accum's type, and that Type is-
560 unsigned. Accum must be an object, so that we can take its-
561 address. Accum and Digit_val may be evaluated multiple times.-
562-
563 The "Added check" below is not strictly required, but it causes GCC-
564 to return a nonzero exit status instead of merely a warning-
565 diagnostic, and that is more useful. */-
566-
567#define DECIMAL_DIGIT_ACCUMULATE(Accum, Digit_val, Type) \-
568 ( \-
569 (void) (&(Accum) == (Type *) NULL), /* The type matches. */ \-
570 (void) verify_true (! TYPE_SIGNED (Type)), /* The type is unsigned. */ \-
571 (void) verify_true (sizeof (Accum) == sizeof (Type)), /* Added check. */ \-
572 (((Type) -1 / 10 < (Accum) \-
573 || (Type) ((Accum) * 10 + (Digit_val)) < (Accum)) \-
574 ? false : (((Accum) = (Accum) * 10 + (Digit_val)), true)) \-
575 )-
576-
577static inline void-
578emit_stdin_note (void)-
579{-
580 fputs (_("\n\-
581With no FILE, or when FILE is -, read standard input.\n\-
582"), stdout);-
583}
executed 389 times by 29 tests: end of block
Executed by:
  • b2sum
  • base32
  • base64
  • cat
  • cut
  • expand
  • fmt
  • fold
  • head
  • md5sum
  • nl
  • od
  • paste
  • pr
  • ptx
  • sha1sum
  • sha224sum
  • sha256sum
  • sha384sum
  • sha512sum
  • shuf
  • sort
  • split
  • sum
  • tac
  • ...
389
584static inline void-
585emit_mandatory_arg_note (void)-
586{-
587 fputs (_("\n\-
588Mandatory arguments to long options are mandatory for short options too.\n\-
589"), stdout);-
590}
executed 848 times by 48 tests: end of block
Executed by:
  • base32
  • base64
  • basename
  • chcon
  • cp
  • csplit
  • cut
  • date
  • df
  • dir
  • du
  • env
  • expand
  • fmt
  • fold
  • ginstall
  • head
  • kill
  • ln
  • ls
  • mkdir
  • mkfifo
  • mknod
  • mv
  • nice
  • ...
848
591-
592static inline void-
593emit_size_note (void)-
594{-
595 fputs (_("\n\-
596The SIZE argument is an integer and optional unit (example: 10K is 10*1024).\n\-
597Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).\n\-
598"), stdout);-
599}
executed 246 times by 7 tests: end of block
Executed by:
  • df
  • dir
  • du
  • ls
  • split
  • truncate
  • vdir
246
600-
601static inline void-
602emit_blocksize_note (char const *program)-
603{-
604 printf (_("\n\-
605Display values are in units of the first available SIZE from --block-size,\n\-
606and the %s_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.\n\-
607Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).\n\-
608"), program);-
609}
executed 71 times by 2 tests: end of block
Executed by:
  • df
  • du
71
610-
611static inline void-
612emit_backup_suffix_note (void)-
613{-
614 fputs (_("\-
615\n\-
616The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\-
617The version control method may be selected via the --backup option or through\n\-
618the VERSION_CONTROL environment variable. Here are the values:\n\-
619\n\-
620"), stdout);-
621 fputs (_("\-
622 none, off never make backups (even if --backup is given)\n\-
623 numbered, t make numbered backups\n\-
624 existing, nil numbered if numbered backups exist, simple otherwise\n\-
625 simple, never always make simple backups\n\-
626"), stdout);-
627}
executed 129 times by 4 tests: end of block
Executed by:
  • cp
  • ginstall
  • ln
  • mv
129
628-
629static inline void-
630emit_ancillary_info (char const *program)-
631{-
632 struct infomap { char const *program; char const *node; } const infomap[] = {-
633 { "[", "test invocation" },-
634 { "coreutils", "Multi-call invocation" },-
635 { "sha224sum", "sha2 utilities" },-
636 { "sha256sum", "sha2 utilities" },-
637 { "sha384sum", "sha2 utilities" },-
638 { "sha512sum", "sha2 utilities" },-
639 { NULL, NULL }-
640 };-
641-
642 char const *node = program;-
643 struct infomap const *map_prog = infomap;-
644-
645 while (map_prog->program && ! STREQ (program, map_prog->program))
never executed: __result = (((const unsigned char *) (const char *) ( program ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( map_prog->program ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
map_prog->programDescription
TRUEevaluated 8012 times by 104 tests
Evaluated by:
  • [
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • ...
FALSEevaluated 1287 times by 99 tests
Evaluated by:
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • expand
  • ...
! ( __extensio...)))); }) == 0)Description
TRUEevaluated 7946 times by 103 tests
Evaluated by:
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • expand
  • ...
FALSEevaluated 66 times by 5 tests
Evaluated by:
  • [
  • sha224sum
  • sha256sum
  • sha384sum
  • sha512sum
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-8012
646 map_prog++;
executed 7946 times by 103 tests: map_prog++;
Executed by:
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • expand
  • ...
7946
647-
648 if (map_prog->node)
map_prog->nodeDescription
TRUEevaluated 66 times by 5 tests
Evaluated by:
  • [
  • sha224sum
  • sha256sum
  • sha384sum
  • sha512sum
FALSEevaluated 1287 times by 99 tests
Evaluated by:
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • expand
  • ...
66-1287
649 node = map_prog->node;
executed 66 times by 5 tests: node = map_prog->node;
Executed by:
  • [
  • sha224sum
  • sha256sum
  • sha384sum
  • sha512sum
66
650-
651 printf (_("\n%s online help: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);-
652-
653 /* Don't output this redundant message for English locales.-
654 Note we still output for 'C' so that it gets included in the man page. */-
655 const char *lc_messages = setlocale (LC_MESSAGES, NULL);-
656 if (lc_messages && STRNCMP_LIT (lc_messages, "en_"))
never executed: __result = (((const unsigned char *) (const char *) ( lc_messages ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "" "en_" "" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
lc_messagesDescription
TRUEevaluated 1353 times by 104 tests
Evaluated by:
  • [
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • ...
FALSEnever evaluated
(__extension__..."en_") - 1 )))Description
TRUEevaluated 1353 times by 104 tests
Evaluated by:
  • [
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • ...
FALSEnever evaluated
__builtin_cons... ("en_") - 1 )Description
TRUEevaluated 1353 times by 104 tests
Evaluated by:
  • [
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • ...
FALSEnever evaluated
__builtin_cons... lc_messages )Description
TRUEnever evaluated
FALSEevaluated 1353 times by 104 tests
Evaluated by:
  • [
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • ...
strlen ( lc_me...("en_") - 1 ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons... "" "en_" "" )Description
TRUEevaluated 1353 times by 104 tests
Evaluated by:
  • [
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • ...
FALSEnever evaluated
strlen ( "" "e...("en_") - 1 ))Description
TRUEnever evaluated
FALSEevaluated 1353 times by 104 tests
Evaluated by:
  • [
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • ...
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-1353
657 {-
658 /* TRANSLATORS: Replace LANG_CODE in this URL with your language code-
659 <https://translationproject.org/team/LANG_CODE.html> to form one of-
660 the URLs at https://translationproject.org/team/. Otherwise, replace-
661 the entire URL with your translation team's email address. */-
662 printf (_("Report %s translation bugs to "-
663 "<https://translationproject.org/team/>\n"), program);-
664 }
executed 1353 times by 104 tests: end of block
Executed by:
  • [
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • ...
1353
665 printf (_("Full documentation at: <%s%s>\n"),-
666 PACKAGE_URL, program);-
667 printf (_("or available locally via: info '(coreutils) %s%s'\n"),-
668 node, node == program ? " invocation" : "");-
669}
executed 1353 times by 104 tests: end of block
Executed by:
  • [
  • b2sum
  • base32
  • base64
  • basename
  • cat
  • chcon
  • chgrp
  • chmod
  • chown
  • chroot
  • cksum
  • comm
  • cp
  • csplit
  • cut
  • date
  • dd
  • df
  • dir
  • dircolors
  • dirname
  • du
  • echo
  • env
  • ...
1353
670-
671/* Use a macro rather than an inline function, as this references-
672 the global program_name, which causes dynamic linking issues-
673 in libstdbuf.so on some systems where unused functions-
674 are not removed by the linker. */-
675#define emit_try_help() \-
676 do \-
677 { \-
678 fprintf (stderr, _("Try '%s --help' for more information.\n"), \-
679 program_name); \-
680 } \-
681 while (0)-
682-
683#include "inttostr.h"-
684-
685static inline char *-
686timetostr (time_t t, char *buf)-
687{-
688 return (TYPE_SIGNED (time_t)
executed 1 time by 1 test: return ((! ((time_t) 0 < (time_t) -1)) ? imaxtostr (t, buf) : umaxtostr (t, buf));
Executed by:
  • du
1
689 ? imaxtostr (t, buf)
executed 1 time by 1 test: return ((! ((time_t) 0 < (time_t) -1)) ? imaxtostr (t, buf) : umaxtostr (t, buf));
Executed by:
  • du
1
690 : umaxtostr (t, buf));
executed 1 time by 1 test: return ((! ((time_t) 0 < (time_t) -1)) ? imaxtostr (t, buf) : umaxtostr (t, buf));
Executed by:
  • du
1
691}-
692-
693static inline char *-
694bad_cast (char const *s)-
695{-
696 return (char *) s;
executed 1904 times by 17 tests: return (char *) s;
Executed by:
  • b2sum
  • chown
  • date
  • dir
  • du
  • ls
  • md5sum
  • paste
  • sha1sum
  • sha224sum
  • sha256sum
  • sha384sum
  • sha512sum
  • split
  • tee
  • vdir
  • yes
1904
697}-
698-
699/* Return a boolean indicating whether SB->st_size is defined. */-
700static inline bool-
701usable_st_size (struct stat const *sb)-
702{-
703 return (S_ISREG (sb->st_mode) || S_ISLNK (sb->st_mode)
executed 2074 times by 7 tests: return ( (((( sb->st_mode )) & 0170000) == (0100000)) || (((( sb->st_mode )) & 0170000) == (0120000)) || (( sb )->st_mode - ( sb )->st_mode) || 0 );
Executed by:
  • dd
  • head
  • od
  • split
  • tail
  • truncate
  • wc
2074
704 || S_TYPEISSHM (sb) || S_TYPEISTMO (sb));
executed 2074 times by 7 tests: return ( (((( sb->st_mode )) & 0170000) == (0100000)) || (((( sb->st_mode )) & 0170000) == (0120000)) || (( sb )->st_mode - ( sb )->st_mode) || 0 );
Executed by:
  • dd
  • head
  • od
  • split
  • tail
  • truncate
  • wc
2074
705}-
706-
707void usage (int status) ATTRIBUTE_NORETURN;-
708-
709/* Like error(0, 0, ...), but without an implicit newline.-
710 Also a noop unless the global DEV_DEBUG is set. */-
711#define devmsg(...) \-
712 do \-
713 { \-
714 if (dev_debug) \-
715 fprintf (stderr, __VA_ARGS__); \-
716 } \-
717 while (0)-
718-
719#define emit_cycle_warning(file_name) \-
720 do \-
721 { \-
722 error (0, 0, _("\-
723WARNING: Circular directory structure.\n\-
724This almost certainly means that you have a corrupted file system.\n\-
725NOTIFY YOUR SYSTEM MANAGER.\n\-
726The following directory is part of the cycle:\n %s\n"), \-
727 quotef (file_name)); \-
728 } \-
729 while (0)-
730-
731/* Like stpncpy, but do ensure that the result is NUL-terminated,-
732 and do not NUL-pad out to LEN. I.e., when strnlen (src, len) == len,-
733 this function writes a NUL byte into dest[len]. Thus, the length-
734 of the destination buffer must be at least LEN + 1.-
735 The DEST and SRC buffers must not overlap. */-
736static inline char *-
737stzncpy (char *restrict dest, char const *restrict src, size_t len)-
738{-
739 char const *src_end = src + len;-
740 while (src < src_end && *src)
src < src_endDescription
TRUEevaluated 29 times by 2 tests
Evaluated by:
  • pinky
  • who
FALSEnever evaluated
*srcDescription
TRUEevaluated 24 times by 2 tests
Evaluated by:
  • pinky
  • who
FALSEevaluated 5 times by 2 tests
Evaluated by:
  • pinky
  • who
0-29
741 *dest++ = *src++;
executed 24 times by 2 tests: *dest++ = *src++;
Executed by:
  • pinky
  • who
24
742 *dest = 0;-
743 return dest;
executed 5 times by 2 tests: return dest;
Executed by:
  • pinky
  • who
5
744}-
745-
746#ifndef ARRAY_CARDINALITY-
747# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))-
748#endif-
749-
750/* Avoid const warnings by casting to more portable type.-
751 This is to cater for the incorrect const function declarations-
752 in selinux.h before libselinux-2.3 (May 2014).-
753 When version >= 2.3 is ubiquitous remove this function. */-
754static
never executed: return (char *) sctx;
inline char * se_const (char const * sctx) { return (char *) sctx; }
never executed: return (char *) sctx;
0
755-
756/* Return true if ERR is ENOTSUP or EOPNOTSUPP, otherwise false.-
757 This wrapper function avoids the redundant 'or'd comparison on-
758 systems like Linux for which they have the same value. It also-
759 avoids the gcc warning to that effect. */-
760static inline bool-
761is_ENOTSUP (int err)-
762{-
763 return err == EOPNOTSUPP || (ENOTSUP != EOPNOTSUPP && err == ENOTSUP);
executed 484 times by 2 tests: return err == 95 || ( 95 != 95 && err == 95 );
Executed by:
  • ls
  • vdir
484
764}-
765-
766-
767/* How coreutils quotes filenames, to minimize use of outer quotes,-
768 but also provide better support for copy and paste when used. */-
769#include "quotearg.h"-
770-
771/* Use these to shell quote only when necessary,-
772 when the quoted item is already delimited with colons. */-
773#define quotef(arg) \-
774 quotearg_n_style_colon (0, shell_escape_quoting_style, arg)-
775#define quotef_n(n, arg) \-
776 quotearg_n_style_colon (n, shell_escape_quoting_style, arg)-
777-
778/* Use these when there are spaces around the file name,-
779 in the error message. */-
780#define quoteaf(arg) \-
781 quotearg_style (shell_escape_always_quoting_style, arg)-
782#define quoteaf_n(n, arg) \-
783 quotearg_n_style (n, shell_escape_always_quoting_style, arg)-
784-
785#ifndef FALLTHROUGH-
786# if __GNUC__ < 7-
787# define FALLTHROUGH ((void) 0)-
788# else-
789# define FALLTHROUGH __attribute__ ((__fallthrough__))-
790# endif-
791#endif-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2