Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
ba55c4c8e7
|
|||
|
003f5aeb1f
|
|||
|
327c71c8ae
|
|||
|
b06c1d5488
|
|||
|
82f6c46b64
|
|||
|
81c657ec3e
|
|||
|
6132c9bf47
|
|||
|
919b171400
|
|||
|
8e38db92c7
|
|||
|
adc9dbded5
|
|||
|
488351da39
|
|||
|
82a941eee3
|
|||
|
e674027b3e
|
9
Makefile
9
Makefile
@@ -28,7 +28,7 @@ RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \
|
||||
CFLAGS += -I$(SYSEXITS)
|
||||
|
||||
.PHONY: all
|
||||
all: dj false fop hru intcmp mm npc rpn scrut str strcmp swab true
|
||||
all: dj false fop hru intcmp mm npc rpn scrut sleep str strcmp swab true
|
||||
|
||||
build:
|
||||
# keep build/include until bindgen(1) has stdin support
|
||||
@@ -118,6 +118,13 @@ scrut: build/bin/scrut
|
||||
build/bin/scrut: src/scrut.c build
|
||||
$(CC) $(CFLAGS) -o $@ src/scrut.c
|
||||
|
||||
.PHONY: sleep
|
||||
sleep: build/bin/sleep
|
||||
build/bin/sleep: src/sleep.rs build rustlibs
|
||||
$(RUSTC) $(RUSTFLAGS) \
|
||||
--extern sysexits=build/o/libsysexits.rlib \
|
||||
-o $@ src/sleep.rs
|
||||
|
||||
.PHONY: str
|
||||
str: build/bin/str
|
||||
build/bin/str: src/str.c build
|
||||
|
||||
53
docs/sleep.1
Normal file
53
docs/sleep.1
Normal file
@@ -0,0 +1,53 @@
|
||||
.\" Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||
.\"
|
||||
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||
|
||||
.TH SLEEP 1
|
||||
|
||||
.SH NAME
|
||||
|
||||
sleep \(en wait a moment
|
||||
|
||||
.SH SYNOPSIS
|
||||
|
||||
sleep
|
||||
.RB [ seconds ]
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
Sleep waits the given amount of seconds before exiting.
|
||||
|
||||
.SH DIAGNOSTICS
|
||||
|
||||
Sleep exits successfully when the time specified has elapsed, or unsuccessfully
|
||||
if the time fails to elapse or if invoked incorrectly. In the latter scenario
|
||||
sleep will also print a usage synopsis.
|
||||
|
||||
.SH BUGS
|
||||
|
||||
User may still be tired after invoking sleep.
|
||||
|
||||
.SH EXAMPLES
|
||||
|
||||
The following invocation sleeps for five seconds.
|
||||
|
||||
.RS
|
||||
.R sleep 5
|
||||
.RE
|
||||
|
||||
The following sh(1p) command line sleeps for five minutes, or for sixty
|
||||
seconds, five times, using rpn(1) and xargs(1p).
|
||||
|
||||
.RS
|
||||
.R $ rpn 60 5 '*' | xargs sleep
|
||||
.RE
|
||||
|
||||
.SH COPYRIGHT
|
||||
|
||||
Copyright (c) 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
||||
<https://gnu.org/licenses/gpl.html>.
|
||||
|
||||
.SH SEE ALSO
|
||||
|
||||
sleep(3)
|
||||
15
src/scrut.c
15
src/scrut.c
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2023 DTB <trinity@trinity.moe>
|
||||
* Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
||||
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
@@ -17,13 +18,15 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h> /* fprintf(3), stderr, NULL */
|
||||
#include <stdlib.h> /* EXIT_FAILURE */
|
||||
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS */
|
||||
#include <string.h> /* memset(3), strchr(3) */
|
||||
#ifndef EX_USAGE
|
||||
# include <sysexits.h>
|
||||
#endif
|
||||
#include <unistd.h> /* access(3), getopt(3), F_OK, R_OK, W_OK, X_OK */
|
||||
#include <sys/stat.h> /* lstat(3), stat struct, S_ISBLK, S_ISCHR, S_ISDIR,
|
||||
* S_ISFIFO, S_ISGID, S_ISREG, S_ISLNK, S_ISSOCK,
|
||||
* S_ISUID, S_ISVTX */
|
||||
#include <sysexits.h>
|
||||
|
||||
static char args[] = "bcdefghkprsuwxLS";
|
||||
static char ops[(sizeof args) / (sizeof *args)];
|
||||
@@ -57,7 +60,7 @@ int main(int argc, char *argv[]){
|
||||
|
||||
argv += optind;
|
||||
do{ if(access(*argv, F_OK) != 0 || lstat(*argv, &buf) == -1)
|
||||
return 1; /* doesn't exist or isn't stattable */
|
||||
return EXIT_FAILURE; /* doesn't exist or isn't stattable */
|
||||
|
||||
for(i = 0; ops[i] != '\0'; ++i)
|
||||
if(ops[i] == 'e')
|
||||
@@ -97,8 +100,8 @@ usage: fprintf(stderr, "Usage: %s (-%s) [file...]\n",
|
||||
&& !S_ISLNK(buf.st_mode))
|
||||
|| (ops[i] == 'S'
|
||||
&& !S_ISSOCK(buf.st_mode)))
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}while(*++argv != NULL);
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
47
src/sleep.rs
Normal file
47
src/sleep.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
use std::{
|
||||
env::args,
|
||||
process::ExitCode,
|
||||
thread::sleep,
|
||||
time::Duration
|
||||
};
|
||||
|
||||
extern crate sysexits;
|
||||
use sysexits::EX_USAGE;
|
||||
|
||||
fn usage(s: &str) -> ExitCode {
|
||||
eprintln!("Usage: {} [seconds]", s);
|
||||
ExitCode::from(EX_USAGE as u8)
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let argv = args().collect::<Vec<String>>();
|
||||
|
||||
if argv.len() == 2 {
|
||||
if let Ok(s) = argv[1].parse::<u64>() {
|
||||
sleep(Duration::from_secs(s));
|
||||
ExitCode::SUCCESS
|
||||
} else {
|
||||
usage(&argv[0])
|
||||
}
|
||||
} else {
|
||||
usage(&argv[0])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user