OpenCoverage

ufuncs.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/lib/sh/ufuncs.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* ufuncs - sleep and alarm functions that understand fractional values */-
2-
3/* Copyright (C) 2008,2009 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne Again SHell.-
6-
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash is distributed in the hope that it will be useful,-
13 but WITHOUT ANY WARRANTY; without even the implied warranty of-
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21#include "config.h"-
22-
23#include "bashtypes.h"-
24-
25#if defined (TIME_WITH_SYS_TIME)-
26# include <sys/time.h>-
27# include <time.h>-
28#else-
29# if defined (HAVE_SYS_TIME_H)-
30# include <sys/time.h>-
31# else-
32# include <time.h>-
33# endif-
34#endif-
35-
36#if defined (HAVE_UNISTD_H)-
37#include <unistd.h>-
38#endif-
39-
40#include <errno.h>-
41#if !defined (errno)-
42extern int errno;-
43#endif /* !errno */-
44-
45#if defined (HAVE_SELECT)-
46# include "posixselect.h"-
47# include "quit.h"-
48# include "trap.h"-
49# include "stat-time.h"-
50#endif-
51-
52/* A version of `alarm' using setitimer if it's available. */-
53-
54#if defined (HAVE_SETITIMER)-
55unsigned int-
56falarm(secs, usecs)-
57 unsigned int secs, usecs;-
58{-
59 struct itimerval it, oit;-
60-
61 it.it_interval.tv_sec = 0;-
62 it.it_interval.tv_usec = 0;-
63-
64 it.it_value.tv_sec = secs;-
65 it.it_value.tv_usec = usecs;-
66-
67 if (setitimer(ITIMER_REAL, &it, &oit) < 0)
setitimer( ITI...&it, &oit) < 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-4
68 return (-1); /* XXX will be converted to unsigned */
never executed: return (-1);
0
69-
70 /* Backwards compatibility with alarm(3) */-
71 if (oit.it_value.tv_usec)
oit.it_value.tv_usecDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
1-3
72 oit.it_value.tv_sec++;
executed 1 time by 1 test: oit.it_value.tv_sec++;
Executed by:
  • Self test
1
73 return (oit.it_value.tv_sec);
executed 4 times by 1 test: return (oit.it_value.tv_sec);
Executed by:
  • Self test
4
74}-
75#else-
76int-
77falarm (secs, usecs)-
78 unsigned int secs, usecs;-
79{-
80 if (secs == 0 && usecs == 0)-
81 return (alarm (0));-
82-
83 if (secs == 0 || usecs >= 500000)-
84 {-
85 secs++;-
86 usecs = 0;-
87 }-
88 return (alarm (secs));-
89}-
90#endif /* !HAVE_SETITIMER */-
91-
92/* A version of sleep using fractional seconds and select. I'd like to use-
93 `usleep', but it's already taken */-
94-
95#if defined (HAVE_TIMEVAL) && (defined (HAVE_SELECT) || defined (HAVE_PSELECT))-
96int-
97fsleep(sec, usec)-
98 unsigned int sec, usec;-
99{-
100 int e, r;-
101 sigset_t blocked_sigs, prevmask;-
102#if defined (HAVE_PSELECT)-
103 struct timespec ts;-
104#else-
105 struct timeval tv;-
106#endif-
107-
108 sigemptyset (&blocked_sigs);-
109# if defined (SIGCHLD)-
110 sigaddset (&blocked_sigs, SIGCHLD);-
111# endif-
112-
113#if defined (HAVE_PSELECT)-
114 ts.tv_sec = sec;-
115 ts.tv_nsec = usec * 1000;-
116#else-
117 sigemptyset (&prevmask);-
118 tv.tv_sec = sec;-
119 tv.tv_usec = usec;-
120#endif /* !HAVE_PSELECT */-
121-
122 do-
123 {-
124#if defined (HAVE_PSELECT)-
125 r = pselect(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &ts, &blocked_sigs);-
126#else-
127 sigprocmask (SIG_SETMASK, &blocked_sigs, &prevmask);-
128 r = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv);-
129 sigprocmask (SIG_SETMASK, &prevmask, NULL);-
130#endif-
131 e = errno;-
132 if (r < 0 && errno == EINTR)
r < 0Description
TRUEnever evaluated
FALSEnever evaluated
(*__errno_location ()) == 4Description
TRUEnever evaluated
FALSEnever evaluated
0
133 QUIT; /* just signals, no traps */
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
never executed: end of block
terminating_signalDescription
TRUEnever evaluated
FALSEnever evaluated
interrupt_stateDescription
TRUEnever evaluated
FALSEnever evaluated
0
134 errno = e;-
135 }
never executed: end of block
0
136 while (r < 0 && errno == EINTR);
r < 0Description
TRUEnever evaluated
FALSEnever evaluated
(*__errno_location ()) == 4Description
TRUEnever evaluated
FALSEnever evaluated
0
137-
138 return r;
never executed: return r;
0
139}-
140#else /* !HAVE_TIMEVAL || !HAVE_SELECT */-
141int-
142fsleep(sec, usec)-
143 long sec, usec;-
144{-
145 if (usec >= 500000) /* round */-
146 sec++;-
147 return (sleep(sec));-
148}-
149#endif /* !HAVE_TIMEVAL || !HAVE_SELECT */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2