From fa3bbfff58f982f5672639b420afa51f4e173e76 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Tue, 25 Jul 2023 23:40:30 -0700 Subject: [PATCH] Sleep in rust --- src/lib.rs | 9 +++++++++ src/nmseffect.c | 14 +------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1d87b77..7496232 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,15 @@ extern "C" { static mut maskBlank: c_int; } +///Sleep for the number of milliseconds indicated by argument +#[no_mangle] +pub extern "C" fn nmseffect_sleep(t: c_int) { + use std::time::Duration; + + let dur = Duration::from_millis(t as u64); + std::thread::sleep(dur); +} + /// Return a random character from charTable[]. #[no_mangle] pub extern "C" fn nmscharset_get_random() -> *const c_char { diff --git a/src/nmseffect.c b/src/nmseffect.c index f876a5b..1800ac4 100644 --- a/src/nmseffect.c +++ b/src/nmseffect.c @@ -47,7 +47,7 @@ struct charAttr { }; // Static function prototypes -static void nmseffect_sleep(int); +extern void nmseffect_sleep(int); /* * This function applies the data decryption effect to the character @@ -298,15 +298,3 @@ char nmseffect_exec(unsigned char *string, int string_len, int autoDecrypt) { void nmseffect_set_clearscr(int setting) { nmstermio_set_clearscr(setting); } - -/* - * Sleep for the number of milliseconds indicated by argument 't'. - */ -static void nmseffect_sleep(int t) { - struct timespec ts; - - ts.tv_sec = t / 1000; - ts.tv_nsec = (t % 1000) * 1000000; - - nanosleep(&ts, NULL); -}