View | Details | Raw Unified | Return to bug 37442 | Differences between
and this patch

Collapse All | Expand All

(-)Makefile (-1 / +3 lines)
Lines 1-6 Link Here
1
#	@(#)Makefile	8.1 (Berkeley) 5/31/93
1
#	@(#)Makefile	8.1 (Berkeley) 5/31/93
2
# $FreeBSD: src/bin/sleep/Makefile,v 1.8 2001/12/04 01:57:46 obrien Exp $
2
# $FreeBSD: src/bin/sleep/Makefile,v 1.5.2.1 2001/08/01 05:23:25 obrien Exp $
3
3
4
PROG=	sleep
4
PROG=	sleep
5
6
LDADD= -lm
5
7
6
.include <bsd.prog.mk>
8
.include <bsd.prog.mk>
(-)sleep.1 (-2 / +12 lines)
Lines 33-39 Link Here
33
.\" SUCH DAMAGE.
33
.\" SUCH DAMAGE.
34
.\"
34
.\"
35
.\"	@(#)sleep.1	8.3 (Berkeley) 4/18/94
35
.\"	@(#)sleep.1	8.3 (Berkeley) 4/18/94
36
.\" $FreeBSD: src/bin/sleep/sleep.1,v 1.17 2001/08/07 15:48:27 ru Exp $
36
.\" $FreeBSD: src/bin/sleep/sleep.1,v 1.15.2.2 2001/08/16 10:01:09 ru Exp $
37
.\"
37
.\"
38
.Dd April 18, 1994
38
.Dd April 18, 1994
39
.Dt SLEEP 1
39
.Dt SLEEP 1
Lines 44-55 Link Here
44
.Sh SYNOPSIS
44
.Sh SYNOPSIS
45
.Nm
45
.Nm
46
.Ar seconds
46
.Ar seconds
47
.Nm
48
.Ar number[multiplier]
47
.Sh DESCRIPTION
49
.Sh DESCRIPTION
48
The
50
The
49
.Nm
51
.Nm
50
command
52
command
51
suspends execution for a minimum of
53
suspends execution for a minimum of
52
.Ar seconds .
54
.Ar seconds
55
or for the time specified by
56
.Ar number[multiplier] .
57
The multiplier can be `s' for seconds, `m' for minutes, `h' for
58
hours and `d' for days.
53
.Pp
59
.Pp
54
If the
60
If the
55
.Nm
61
.Nm
Lines 85-90 Link Here
85
number seconds later:
91
number seconds later:
86
.Pp
92
.Pp
87
.Dl (sleep 1800; sh command_file >& errors)&
93
.Dl (sleep 1800; sh command_file >& errors)&
94
.Pp
95
or
96
.Pp
97
.Dl (sleep .5h; sh command_file >& errors)&
88
.Pp
98
.Pp
89
This incantation would wait a half hour before
99
This incantation would wait a half hour before
90
running the script command_file.
100
running the script command_file.
(-)sleep.c (-27 / +39 lines)
Lines 42-48 Link Here
42
static char sccsid[] = "@(#)sleep.c	8.3 (Berkeley) 4/2/94";
42
static char sccsid[] = "@(#)sleep.c	8.3 (Berkeley) 4/2/94";
43
#endif
43
#endif
44
static const char rcsid[] =
44
static const char rcsid[] =
45
  "$FreeBSD: src/bin/sleep/sleep.c,v 1.11 2002/02/02 06:50:56 imp Exp $";
45
  "$FreeBSD: src/bin/sleep/sleep.c,v 1.9.2.1 2001/08/01 05:23:25 obrien Exp $";
46
#endif /* not lint */
46
#endif /* not lint */
47
47
48
#include <ctype.h>
48
#include <ctype.h>
Lines 51-56 Link Here
51
#include <stdlib.h>
51
#include <stdlib.h>
52
#include <time.h>
52
#include <time.h>
53
#include <unistd.h>
53
#include <unistd.h>
54
#include <math.h>
54
55
55
void usage(void);
56
void usage(void);
56
57
Lines 58-64 Link Here
58
main(int argc, char *argv[])
59
main(int argc, char *argv[])
59
{
60
{
60
	struct timespec time_to_sleep;
61
	struct timespec time_to_sleep;
61
	long l;
62
	double d;
62
	int ch, neg;
63
	int ch, neg;
63
	char *p;
64
	char *p;
64
65
Lines 92-124 Link Here
92
	else if (*p == '+')
93
	else if (*p == '+')
93
		++p;
94
		++p;
94
95
95
	/* Calculate seconds. */
96
	d = atof(p);
96
	if (isdigit((unsigned char)*p)) {
97
	while (*p != 0) {
97
		l = strtol(p, &p, 10);
98
		if (!isdigit(*p) && *p != '.')
98
		if (l > INT_MAX) {
99
			break;
99
			/*
100
		p++;
100
			 * Avoid overflow when `seconds' is huge.  This assumes
101
			 * that the maximum value for a time_t is >= INT_MAX.
102
			 */
103
			l = INT_MAX;
104
		}
105
	} else
106
		l = 0;
107
	time_to_sleep.tv_sec = (time_t)l;
108
109
	/* Calculate nanoseconds. */
110
	time_to_sleep.tv_nsec = 0;
111
112
	if (*p == '.') {		/* Decimal point. */
113
		l = 100000000L;
114
		do {
115
			if (isdigit((unsigned char)*++p))
116
				time_to_sleep.tv_nsec += (*p - '0') * l;
117
			else
118
				break;
119
		} while (l /= 10);
120
	}
101
	}
121
102
103
	/* Do multiplier trick. */
104
	switch (*p) {
105
	case 0:
106
	case 's':
107
		break;
108
	case 'm':
109
		d *= 60;
110
		break;
111
	case 'h':
112
		d *= 60 * 60;
113
		break;
114
	case 'd':
115
		d *= 24 * 60 * 60;
116
		break;
117
	default:
118
		usage();
119
		/* NOTREACHED */
120
	}
121
122
	if (d > INT_MAX)
123
		d = INT_MAX;
124
125
	/*
126
	 * Split up the double into an integer (seconds) and
127
	 * fractional (nanoseconds) part.
128
	 */
129
	time_to_sleep.tv_sec = (time_t)floor(d);
130
	time_to_sleep.tv_nsec =
131
			(time_t)1000000000L * (d - time_to_sleep.tv_sec);
132
122
	if (!neg && (time_to_sleep.tv_sec > 0 || time_to_sleep.tv_nsec > 0))
133
	if (!neg && (time_to_sleep.tv_sec > 0 || time_to_sleep.tv_nsec > 0))
123
		(void)nanosleep(&time_to_sleep, (struct timespec *)NULL);
134
		(void)nanosleep(&time_to_sleep, (struct timespec *)NULL);
124
135
Lines 130-134 Link Here
130
{
141
{
131
142
132
	(void)fprintf(stderr, "usage: sleep seconds\n");
143
	(void)fprintf(stderr, "usage: sleep seconds\n");
144
	(void)fprintf(stderr, "   or: sleep number[multiplier]\n");
133
	exit(1);
145
	exit(1);
134
}
146
}

Return to bug 37442