mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
select() to poll() conversions
ok tedu (... other games maintainer absent)
This commit is contained in:
parent
45200bc010
commit
5e64005729
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: extern.c,v 1.5 2009/10/27 23:59:26 deraadt Exp $ */
|
||||
/* $OpenBSD: extern.c,v 1.6 2014/11/03 22:14:54 deraadt Exp $ */
|
||||
/* $NetBSD: extern.c,v 1.3 1995/04/22 10:08:49 cgd Exp $ */
|
||||
|
||||
/*
|
||||
@ -62,7 +62,6 @@ int Score; /* Current score */
|
||||
int Start_level = 1; /* Level on which to start */
|
||||
int Wait_bonus; /* bonus for waiting */
|
||||
|
||||
fd_set rset; /* Needed if Real_time */
|
||||
struct timeval tv; /* how long to wait; could be an option */
|
||||
|
||||
COORD Max; /* Max area robots take up */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: main.c,v 1.18 2013/08/29 20:22:19 naddy Exp $ */
|
||||
/* $OpenBSD: main.c,v 1.19 2014/11/03 22:14:54 deraadt Exp $ */
|
||||
/* $NetBSD: main.c,v 1.5 1995/04/22 10:08:54 cgd Exp $ */
|
||||
|
||||
/*
|
||||
@ -71,7 +71,6 @@ main(int ac, char *av[])
|
||||
/* Could be a command-line option */
|
||||
tv.tv_sec = 3;
|
||||
tv.tv_usec = 0;
|
||||
FD_ZERO(&rset);
|
||||
break;
|
||||
case 'a':
|
||||
Start_level = 4;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: move.c,v 1.9 2009/10/27 23:59:26 deraadt Exp $ */
|
||||
/* $OpenBSD: move.c,v 1.10 2014/11/03 22:14:54 deraadt Exp $ */
|
||||
/* $NetBSD: move.c,v 1.4 1995/04/22 10:08:58 cgd Exp $ */
|
||||
|
||||
/*
|
||||
@ -90,8 +90,12 @@ get_move(void)
|
||||
else {
|
||||
over:
|
||||
if (Real_time) {
|
||||
FD_SET(STDIN_FILENO, &rset);
|
||||
retval = select(STDIN_FILENO + 1, &rset, NULL, NULL, &t);
|
||||
struct pollfd pfd[1];
|
||||
|
||||
pfd[0].fd = STDIN_FILENO;
|
||||
pfd[0].events = POLLIN;
|
||||
retval = poll(pfd, 1,
|
||||
t.tv_sec * 1000 + t.tv_usec / 1000);
|
||||
if (retval > 0)
|
||||
c = getchar();
|
||||
else /* Don't move if timed out or error */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: robots.h,v 1.6 2003/06/03 03:01:41 millert Exp $ */
|
||||
/* $OpenBSD: robots.h,v 1.7 2014/11/03 22:14:54 deraadt Exp $ */
|
||||
/* $NetBSD: robots.h,v 1.5 1995/04/24 12:24:54 cgd Exp $ */
|
||||
|
||||
/*
|
||||
@ -46,6 +46,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
|
||||
/*
|
||||
* miscellaneous constants
|
||||
@ -106,7 +107,6 @@ extern char Cnt_move, Field[Y_FIELDSIZE][X_FIELDSIZE], *Next_move,
|
||||
extern int Count, Level, Num_robots, Num_scores, Score,
|
||||
Start_level, Wait_bonus;
|
||||
|
||||
extern fd_set rset;
|
||||
extern struct timeval tv;
|
||||
|
||||
extern COORD Max, Min, My_pos, Robots[];
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: input.c,v 1.12 2005/04/13 02:33:08 deraadt Exp $ */
|
||||
/* $OpenBSD: input.c,v 1.13 2014/11/03 22:14:54 deraadt Exp $ */
|
||||
/* $NetBSD: input.c,v 1.3 1996/02/06 22:47:33 jtc Exp $ */
|
||||
|
||||
/*-
|
||||
@ -44,6 +44,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "input.h"
|
||||
@ -76,15 +77,10 @@ int
|
||||
rwait(struct timeval *tvp)
|
||||
{
|
||||
struct timeval starttv, endtv, *s;
|
||||
fd_set fds;
|
||||
struct pollfd pfd[1];
|
||||
|
||||
#define NILTZ ((struct timezone *)0)
|
||||
|
||||
/*
|
||||
* Someday, select() will do this for us.
|
||||
* Just in case that day is now, and no one has
|
||||
* changed this, we use a temporary.
|
||||
*/
|
||||
if (tvp) {
|
||||
(void) gettimeofday(&starttv, NILTZ);
|
||||
endtv = *tvp;
|
||||
@ -92,9 +88,9 @@ rwait(struct timeval *tvp)
|
||||
} else
|
||||
s = NULL;
|
||||
again:
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(STDIN_FILENO, &fds);
|
||||
switch (select(STDIN_FILENO + 1, &fds, (fd_set *)0, (fd_set *)0, s)) {
|
||||
pfd[0].fd = STDIN_FILENO;
|
||||
pfd[0].events = POLLIN;
|
||||
switch (poll(pfd, 1, s->tv_sec * 1000 + s->tv_usec / 1000)) {
|
||||
|
||||
case -1:
|
||||
if (tvp == 0)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: worm.c,v 1.26 2014/01/28 14:30:28 jmc Exp $ */
|
||||
/* $OpenBSD: worm.c,v 1.27 2014/11/03 22:14:54 deraadt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1993
|
||||
@ -43,6 +43,7 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
|
||||
#define HEAD '@'
|
||||
#define BODY 'o'
|
||||
@ -88,10 +89,9 @@ main(int argc, char **argv)
|
||||
int retval;
|
||||
struct timeval t, tod;
|
||||
struct timezone tz;
|
||||
fd_set rset;
|
||||
struct pollfd pfd[1];
|
||||
const char *errstr;
|
||||
|
||||
FD_ZERO(&rset);
|
||||
setbuf(stdout, outbuf);
|
||||
signal(SIGINT, leave);
|
||||
signal(SIGQUIT, leave);
|
||||
@ -159,8 +159,9 @@ main(int argc, char **argv)
|
||||
t.tv_sec = 1;
|
||||
t.tv_usec = 0;
|
||||
(void)gettimeofday(&tod, &tz);
|
||||
FD_SET(STDIN_FILENO, &rset);
|
||||
retval = select(STDIN_FILENO + 1, &rset, NULL, NULL, &t);
|
||||
pfd[0].fd = STDIN_FILENO;
|
||||
pfd[0].events = POLLIN;
|
||||
retval = poll(pfd, 1, t.tv_sec * 1000 + t.tv_usec / 1000);
|
||||
if (retval > 0)
|
||||
process(getch());
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user