Sleep in rust

This commit is contained in:
Greg Shuflin 2023-07-25 23:40:30 -07:00
parent 4fc23d0a76
commit fa3bbfff58
2 changed files with 10 additions and 13 deletions

View File

@ -17,6 +17,15 @@ extern "C" {
static mut maskBlank: c_int; 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[]. /// Return a random character from charTable[].
#[no_mangle] #[no_mangle]
pub extern "C" fn nmscharset_get_random() -> *const c_char { pub extern "C" fn nmscharset_get_random() -> *const c_char {

View File

@ -47,7 +47,7 @@ struct charAttr {
}; };
// Static function prototypes // Static function prototypes
static void nmseffect_sleep(int); extern void nmseffect_sleep(int);
/* /*
* This function applies the data decryption effect to the character * 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) { void nmseffect_set_clearscr(int setting) {
nmstermio_set_clearscr(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);
}