diff --git a/src/include/tio/time.h b/src/include/tio/time.h index 04d1bf2..fe15558 100644 --- a/src/include/tio/time.h +++ b/src/include/tio/time.h @@ -23,5 +23,6 @@ #define TIME_H char * current_time(void); +void delay(long ms); #endif diff --git a/src/time.c b/src/time.c index 5dd7fcb..fd609b8 100644 --- a/src/time.c +++ b/src/time.c @@ -23,6 +23,7 @@ #include #include #include "tio/error.h" +#include "tio/print.h" char * current_time(void) { @@ -42,3 +43,13 @@ char * current_time(void) return time_string; } + +void delay(long ms) +{ + struct timespec ts; + + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000000; + + nanosleep(&ts, NULL); +} diff --git a/src/tty.c b/src/tty.c index 33bbed9..b02e4e6 100644 --- a/src/tty.c +++ b/src/tty.c @@ -32,7 +32,6 @@ #include #include #include -#include #include "tio/tty.h" #include "tio/print.h" #include "tio/options.h" @@ -309,8 +308,6 @@ int connect_tty(void) if (forward) { - struct timespec ts; - /* Send output to tty device */ status = write(fd, &output_char, 1); if (status < 0) @@ -324,11 +321,7 @@ int connect_tty(void) tx_total++; /* Insert output delay */ - ts.tv_sec = 0; - ts.tv_nsec = option.output_delay * 1000000; - if (option.output_delay) - nanosleep(&ts, NULL); - + delay(option.output_delay); } /* Save previous key */