#include "fatal.h"
#include "sudo_debug.h"
#include "sudo_event.h"
+#include "sudo_util.h"
/* XXX - use non-exiting allocators? */
ev->timeout.tv_sec += timo->tv_sec;
ev->timeout.tv_usec += timo->tv_usec;
TAILQ_FOREACH(evtmp, &base->timeouts, timeouts_entries) {
- if (timevalcmp(timo, &evtmp->timeout, <))
+ if (sudo_timevalcmp(timo, &evtmp->timeout, <))
break;
}
if (evtmp != NULL) {
/* Timed out, activate timeout events. */
gettimeofday(&now, NULL);
while ((ev = TAILQ_FIRST(&base->timeouts)) != NULL) {
- if (timevalcmp(&ev->timeout, &now, >))
+ if (sudo_timevalcmp(&ev->timeout, &now, >))
break;
/* Remove from timeouts list. */
CLR(ev->flags, SUDO_EVQ_TIMEOUTS);
debug_decl(sudo_ev_get_timeleft, SUDO_DEBUG_EVENT)
if (!ISSET(ev->flags, SUDO_EVQ_TIMEOUTS)) {
- timevalclear(tv);
+ sudo_timevalclear(tv);
debug_return_int(-1);
}
gettimeofday(&now, NULL);
- *tv = ev->timeout;
- timevalsub(tv, &now);
+ sudo_timevalsub(&ev->timeout, &now, tv);
if (tv->tv_sec < 0 || (tv->tv_sec == 0 && tv->tv_usec < 0))
- timevalclear(tv);
+ sudo_timevalclear(tv);
debug_return_int(0);
}
#include "fatal.h"
#include "sudo_debug.h"
#include "sudo_event.h"
+#include "sudo_util.h"
/* XXX - use non-exiting allocators? */
if ((ev = TAILQ_FIRST(&base->timeouts)) != NULL) {
gettimeofday(&now, NULL);
- tv = ev->timeout;
- timevalsub(&tv, &now);
+ sudo_timevalsub(&ev->timeout, &now, &tv);
if (tv.tv_sec < 0 || (tv.tv_sec == 0 && tv.tv_usec < 0))
- timevalclear(&tv);
+ sudo_timevalclear(&tv);
timeout = &tv;
} else {
if (ISSET(flags, SUDO_EVLOOP_NONBLOCK)) {
- timevalclear(&tv);
+ sudo_timevalclear(&tv);
timeout = &tv;
} else {
timeout = NULL;
extern int errno;
#endif /* !HAVE_DECL_ERRNO */
-#ifndef timevalclear
-# define timevalclear(tv) ((tv)->tv_sec = (tv)->tv_usec = 0)
-#endif
-#ifndef timevalisset
-# define timevalisset(tv) ((tv)->tv_sec || (tv)->tv_usec)
-#endif
-#ifndef timevalcmp
-# define timevalcmp(tv1, tv2, op) \
- (((tv1)->tv_sec == (tv2)->tv_sec) ? \
- ((tv1)->tv_usec op (tv2)->tv_usec) : \
- ((tv1)->tv_sec op (tv2)->tv_sec))
-#endif
-#ifndef timevaladd
-# define timevaladd(tv1, tv2) \
- do { \
- (tv1)->tv_sec += (tv2)->tv_sec; \
- (tv1)->tv_usec += (tv2)->tv_usec; \
- if ((tv1)->tv_usec >= 1000000) { \
- (tv1)->tv_sec++; \
- (tv1)->tv_usec -= 1000000; \
- } \
- } while (0)
-#endif
-#ifndef timevalsub
-# define timevalsub(tv1, tv2) \
- do { \
- (tv1)->tv_sec -= (tv2)->tv_sec; \
- (tv1)->tv_usec -= (tv2)->tv_usec; \
- if ((tv1)->tv_usec < 0) { \
- (tv1)->tv_sec--; \
- (tv1)->tv_usec += 1000000; \
- } \
- } while (0)
-#endif
-
/* Not all systems define NSIG in signal.h */
#if !defined(NSIG)
# if defined(_NSIG)
else
#endif
ignore_result(fwrite(buf, 1, len, io_log_files[idx].fd.f));
- delay.tv_sec = now.tv_sec;
- delay.tv_usec = now.tv_usec;
- timevalsub(&delay, &last_time);
+ sudo_timevalsub(&now, &last_time, &delay);
#ifdef HAVE_ZLIB_H
if (iolog_compress)
gzprintf(io_log_files[IOFD_TIMING].fd.g, "%d %f %u\n", idx,
if (!paused) {
/* Determine remaining timeout, if any. */
sudo_ev_get_timeleft(ev, &tv);
- if (!timevalisset(&tv)) {
+ if (!sudo_timevalisset(&tv)) {
/* No time left, event is done. */
debug_return;
}
goto done;
}
- /* Set modified bit if use changed the file. */
+ /* Set modified bit if the user changed the file. */
modified = true;
mtim_get(&sb, &tv);
- if (orig_size == sb.st_size && timevalcmp(&orig_mtim, &tv, ==)) {
+ if (orig_size == sb.st_size && sudo_timevalcmp(&orig_mtim, &tv, ==)) {
/*
* If mtime and size match but the user spent no measurable
* time in the editor we can't tell if the file was changed.
*/
- timevalsub(&tv1, &tv2);
- if (timevalisset(&tv2))
+ if (sudo_timevalcmp(&tv1, &tv2, !=))
modified = false;
}
continue;
}
mtim_get(&sb, &tv);
- if (tf[i].osize == sb.st_size && timevalcmp(&tf[i].omtim, &tv, ==)) {
+ if (tf[i].osize == sb.st_size && sudo_timevalcmp(&tf[i].omtim, &tv, ==)) {
/*
* If mtime and size match but the user spent no measurable
* time in the editor we can't tell if the file was changed.
*/
- timevalsub(&tv1, &tv2);
- if (timevalisset(&tv2)) {
+ if (sudo_timevalcmp(&tv1, &tv2, !=)) {
warningx(U_("%s unchanged"), tf[i].ofile);
unlink(tf[i].tfile);
close(tfd);