OpenCoverage

sleep.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/sleep.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* sleep - delay for a specified amount of time.-
2 Copyright (C) 1984-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 <config.h>-
18#include <stdio.h>-
19#include <sys/types.h>-
20#include <getopt.h>-
21-
22#include "system.h"-
23#include "c-strtod.h"-
24#include "die.h"-
25#include "error.h"-
26#include "long-options.h"-
27#include "quote.h"-
28#include "xnanosleep.h"-
29#include "xstrtod.h"-
30-
31/* The official name of this program (e.g., no 'g' prefix). */-
32#define PROGRAM_NAME "sleep"-
33-
34#define AUTHORS \-
35 proper_name ("Jim Meyering"), \-
36 proper_name ("Paul Eggert")-
37-
38static struct option const long_options[] =-
39{-
40 {NULL, 0, NULL, 0}-
41};-
42-
43void-
44usage (int status)-
45{-
46 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • sleep
FALSEevaluated 3 times by 1 test
Evaluated by:
  • sleep
3-10
47 emit_try_help ();
executed 10 times by 1 test: end of block
Executed by:
  • sleep
10
48 else-
49 {-
50 printf (_("\-
51Usage: %s NUMBER[SUFFIX]...\n\-
52 or: %s OPTION\n\-
53Pause for NUMBER seconds. SUFFIX may be 's' for seconds (the default),\n\-
54'm' for minutes, 'h' for hours or 'd' for days. Unlike most implementations\n\-
55that require NUMBER be an integer, here NUMBER may be an arbitrary floating\n\-
56point number. Given two or more arguments, pause for the amount of time\n\-
57specified by the sum of their values.\n\-
58\n\-
59"),-
60 program_name, program_name);-
61 fputs (HELP_OPTION_DESCRIPTION, stdout);-
62 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
63 emit_ancillary_info (PROGRAM_NAME);-
64 }
executed 3 times by 1 test: end of block
Executed by:
  • sleep
3
65 exit (status);
executed 13 times by 1 test: exit (status);
Executed by:
  • sleep
13
66}-
67-
68/* Given a floating point value *X, and a suffix character, SUFFIX_CHAR,-
69 scale *X by the multiplier implied by SUFFIX_CHAR. SUFFIX_CHAR may-
70 be the NUL byte or 's' to denote seconds, 'm' for minutes, 'h' for-
71 hours, or 'd' for days. If SUFFIX_CHAR is invalid, don't modify *X-
72 and return false. Otherwise return true. */-
73-
74static bool-
75apply_suffix (double *x, char suffix_char)-
76{-
77 int multiplier;-
78-
79 switch (suffix_char)-
80 {-
81 case 0:
executed 200 times by 1 test: case 0:
Executed by:
  • sleep
200
82 case 's':
executed 1 time by 1 test: case 's':
Executed by:
  • sleep
1
83 multiplier = 1;-
84 break;
executed 201 times by 1 test: break;
Executed by:
  • sleep
201
85 case 'm':
executed 2 times by 1 test: case 'm':
Executed by:
  • sleep
2
86 multiplier = 60;-
87 break;
executed 2 times by 1 test: break;
Executed by:
  • sleep
2
88 case 'h':
executed 1 time by 1 test: case 'h':
Executed by:
  • sleep
1
89 multiplier = 60 * 60;-
90 break;
executed 1 time by 1 test: break;
Executed by:
  • sleep
1
91 case 'd':
executed 2 times by 1 test: case 'd':
Executed by:
  • sleep
2
92 multiplier = 60 * 60 * 24;-
93 break;
executed 2 times by 1 test: break;
Executed by:
  • sleep
2
94 default:
executed 1 time by 1 test: default:
Executed by:
  • sleep
1
95 return false;
executed 1 time by 1 test: return 0 ;
Executed by:
  • sleep
1
96 }-
97-
98 *x *= multiplier;-
99-
100 return true;
executed 206 times by 1 test: return 1 ;
Executed by:
  • sleep
206
101}-
102-
103int-
104main (int argc, char **argv)-
105{-
106 double seconds = 0.0;-
107 bool ok = true;-
108-
109 initialize_main (&argc, &argv);-
110 set_program_name (argv[0]);-
111 setlocale (LC_ALL, "");-
112 bindtextdomain (PACKAGE, LOCALEDIR);-
113 textdomain (PACKAGE);-
114-
115 atexit (close_stdout);-
116-
117 parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,-
118 usage, AUTHORS, (char const *) NULL);-
119 if (getopt_long (argc, argv, "", long_options, NULL) != -1)
getopt_long (a...d *)0) ) != -1Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • sleep
FALSEevaluated 209 times by 1 test
Evaluated by:
  • sleep
3-209
120 usage (EXIT_FAILURE);
executed 3 times by 1 test: usage ( 1 );
Executed by:
  • sleep
3
121-
122 if (argc == 1)
argc == 1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • sleep
FALSEevaluated 208 times by 1 test
Evaluated by:
  • sleep
1-208
123 {-
124 error (0, 0, _("missing operand"));-
125 usage (EXIT_FAILURE);-
126 }
never executed: end of block
0
127-
128 for (int i = optind; i < argc; i++)
i < argcDescription
TRUEevaluated 212 times by 1 test
Evaluated by:
  • sleep
FALSEevaluated 208 times by 1 test
Evaluated by:
  • sleep
208-212
129 {-
130 double s;-
131 const char *p;-
132 if (! (xstrtod (argv[i], &p, &s, c_strtod) || errno == ERANGE)
xstrtod (argv[... &s, c_strtod)Description
TRUEevaluated 209 times by 1 test
Evaluated by:
  • sleep
FALSEevaluated 3 times by 1 test
Evaluated by:
  • sleep
(*__errno_location ()) == 34Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • sleep
FALSEevaluated 2 times by 1 test
Evaluated by:
  • sleep
1-209
133 /* Nonnegative interval. */-
134 || ! (0 <= s)
! (0 <= s)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • sleep
FALSEevaluated 208 times by 1 test
Evaluated by:
  • sleep
2-208
135 /* No extra chars after the number and an optional s,m,h,d char. */-
136 || (*p && *(p+1))
*pDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • sleep
FALSEevaluated 200 times by 1 test
Evaluated by:
  • sleep
*(p+1)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • sleep
FALSEevaluated 7 times by 1 test
Evaluated by:
  • sleep
1-200
137 /* Check any suffix char and update S based on the suffix. */-
138 || ! apply_suffix (&s, *p))
! apply_suffix (&s, *p)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • sleep
FALSEevaluated 206 times by 1 test
Evaluated by:
  • sleep
1-206
139 {-
140 error (0, 0, _("invalid time interval %s"), quote (argv[i]));-
141 ok = false;-
142 }
executed 6 times by 1 test: end of block
Executed by:
  • sleep
6
143-
144 seconds += s;-
145 }
executed 212 times by 1 test: end of block
Executed by:
  • sleep
212
146-
147 if (!ok)
!okDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • sleep
FALSEevaluated 202 times by 1 test
Evaluated by:
  • sleep
6-202
148 usage (EXIT_FAILURE);
executed 6 times by 1 test: usage ( 1 );
Executed by:
  • sleep
6
149-
150 if (xnanosleep (seconds))
xnanosleep (seconds)Description
TRUEnever evaluated
FALSEevaluated 190 times by 1 test
Evaluated by:
  • sleep
0-190
151 die (EXIT_FAILURE, errno, _("cannot read realtime clock"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"cannot read realtime clock\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot read realtime clock" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot read realtime clock" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
152-
153 return EXIT_SUCCESS;
executed 190 times by 1 test: return 0 ;
Executed by:
  • sleep
190
154}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2