Skip to content

Commit

Permalink
avoid using math.h and floor()
Browse files Browse the repository at this point in the history
  • Loading branch information
hanslub42 committed Apr 29, 2021
1 parent b588693 commit d67ac37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/rlwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include <signal.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <inttypes.h> /* stdint.h is not on AIX, inttypes.h is in ISO C 1999 */

#include <errno.h>
Expand Down
9 changes: 6 additions & 3 deletions src/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,14 @@ static int myalarm_was_set = FALSE;

void myalarm(int msecs) {
#ifdef HAVE_SETITIMER
int retval;
struct itimerval awhile = {{0,0},{0,0}};
awhile.it_value.tv_sec = floor(msecs/1000);
awhile.it_value.tv_usec = (msecs - awhile.it_value.tv_sec * 1000) * 1000;
int secs = msecs/1000;
awhile.it_value.tv_sec = secs;
awhile.it_value.tv_usec = (msecs - secs * 1000) * 1000;
received_sigALRM = FALSE;
setitimer(ITIMER_REAL, &awhile, NULL);
retval = setitimer(ITIMER_REAL, &awhile, NULL);
DPRINTF3(DEBUG_AD_HOC, "setitimer() = %d (tv_sec = %d, tv_usec=%ld)", retval, secs, awhile.it_value.tv_usec);
#else
received_sigALRM = FALSE;
alarm(msecs == 0 ? 0 : 1 + msecs/1000));
Expand Down

0 comments on commit d67ac37

Please sign in to comment.