M STATUS => STATUS +1 -1
@@ 122,7 122,7 @@ T rm
W sccs
T sed
N sh
-T sleep
+ D sleep
T sort
T split
T strings
M doc/meson.build => doc/meson.build +1 -0
@@ 20,6 20,7 @@ man_files = [
'logname.1',
'nice.1',
'rmdir.1',
+ 'sleep.1',
'true.1',
'tty.1',
'uname.1',
A doc/sleep.1.scd => doc/sleep.1.scd +21 -0
@@ 0,0 1,21 @@
+sleep(1) "ctools"
+
+# NAME
+
+sleep - suspend execution for an interval
+
+# SYNOPSIS
+
+*sleep* time
+
+# DESCRIPTION
+
+The sleep utility suspends execution for at least the integral
+number of seconds specified by the time operand.
+
+# DISCLAIMER
+
+This command is part of ctools and is compatible with POSIX-1.2017, and may
+optionally support XSI extensions. This man page is not intended to be a
+complete reference, and where it disagrees with the specification, the
+specification takes precedence.
M meson.build => meson.build +1 -0
@@ 28,6 28,7 @@ oneshots = [
'rmdir',
'true',
'tty',
+ 'sleep',
'uname',
]
A src/sleep.c => src/sleep.c +39 -0
@@ 0,0 1,39 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static void
+usage(void)
+{
+ fprintf(stderr, "usage: sleep time\n");
+}
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int secs;
+ const char *nptr;
+ char *endptr = NULL;
+
+ if (getopt(argc, argv, "") != -1 || optind != argc - 1) {
+ usage();
+ return 1;
+ }
+
+ errno = 0;
+ nptr = argv[1];
+ secs = strtol(nptr, &endptr, 10);
+
+ if (nptr == endptr || (errno == 0 && *endptr != 0)){
+ fprintf(stderr, "error: invalid number\n");
+ return 1;
+ } else if (errno != 0) {
+ perror("strtol");
+ return 1;
+ }
+
+ sleep(secs);
+
+ return 0;
+}
M test/meson.build => test/meson.build +1 -0
@@ 16,6 16,7 @@ test_files = [
'logname',
'nice',
'rmdir',
+ 'sleep',
'true',
'tty',
'uname',
A test/sleep => test/sleep +18 -0
@@ 0,0 1,18 @@
+#!/bin/sh
+tool="true"
+. "$HARNESS"
+
+should_return_zero() {
+ sleep 1
+}
+
+should_return_error() {
+ if ! sleep hans; then
+ return 0
+ fi
+ return 1
+}
+
+runtests \
+ should_return_zero \
+ should_return_error