1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:47:45 +00:00

Userland: Port sleep(1) to Core::ArgsParser

This commit is contained in:
Sergey Bugaev 2020-05-26 13:35:09 +03:00 committed by Andreas Kling
parent 27360f1f20
commit 62283ade91

View file

@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <AK/String.h> #include <LibCore/ArgsParser.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -41,16 +41,12 @@ int main(int argc, char** argv)
return 1; return 1;
} }
if (argc != 2) { int secs;
printf("usage: sleep <seconds>\n");
return 1; Core::ArgsParser args_parser;
} args_parser.add_positional_argument(secs, "Number of seconds to sleep for", "num-seconds");
bool ok; args_parser.parse(argc, argv);
unsigned secs = String(argv[1]).to_uint(ok);
if (!ok) {
fprintf(stderr, "Not a valid number of seconds: \"%s\"\n", argv[1]);
return 1;
}
struct sigaction sa; struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction)); memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = handle_sigint; sa.sa_handler = handle_sigint;