Support OS X by moving to gettimeofday(2) and adding poll compat from OpenSSH.

This commit is contained in:
Nicholas Marriott
2008-08-28 17:45:30 +00:00
parent 0abb4ca413
commit 33aa931541
18 changed files with 287 additions and 88 deletions

View File

@ -1,4 +1,4 @@
/* $Id: tty-keys.c,v 1.9 2008-07-24 21:42:40 nicm Exp $ */
/* $Id: tty-keys.c,v 1.10 2008-08-28 17:45:28 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -17,9 +17,9 @@
*/
#include <sys/types.h>
#include <sys/time.h>
#include <string.h>
#include <time.h>
#include "tmux.h"
@ -299,7 +299,7 @@ tty_keys_next(struct tty *tty, int *code)
{
struct tty_key *tk;
size_t size;
struct timespec ts;
struct timeval tv;
size = BUFFER_USED(tty->in);
if (size == 0)
@ -324,20 +324,20 @@ tty_keys_next(struct tty *tty, int *code)
/* Escape but no key string. If the timer isn't started, start it. */
if (!(tty->flags & TTY_ESCAPE)) {
ts.tv_sec = 0;
ts.tv_nsec = 500 * 1000000L;
if (clock_gettime(CLOCK_REALTIME, &tty->key_timer) != 0)
fatal("clock_gettime");
timespecadd(&tty->key_timer, &ts, &tty->key_timer);
tv.tv_sec = 0;
tv.tv_usec = 500 * 1000L;
if (gettimeofday(&tty->key_timer, NULL) != 0)
fatal("gettimeofday");
timeradd(&tty->key_timer, &tv, &tty->key_timer);
tty->flags |= TTY_ESCAPE;
return (1);
}
/* Otherwise, if the timer hasn't expired, wait. */
if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
fatal("clock_gettime");
if (!timespeccmp(&tty->key_timer, &ts, >))
if (gettimeofday(&tv, NULL) != 0)
fatal("gettimeofday");
if (!timercmp(&tty->key_timer, &tv, >))
return (1);
tty->flags &= ~TTY_ESCAPE;