/[cmucl]/src/clx/excldep.c
ViewVC logotype

Contents of /src/clx/excldep.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Wed Jun 17 18:22:46 2009 UTC (4 years, 10 months ago) by rtoy
Branch: MAIN
CVS Tags: sparc-tramp-assem-base, post-merge-intl-branch, intl-branch-working-2010-02-19-1000, unicode-string-buffer-impl-base, release-20b-pre1, release-20b-pre2, unicode-string-buffer-base, sparc-tramp-assem-2010-07-19, amd64-dd-start, intl-2-branch-base, GIT-CONVERSION, cross-sol-x86-merged, intl-branch-working-2010-02-11-1000, RELEASE_20b, release-20a-base, cross-sol-x86-base, snapshot-2010-12, snapshot-2010-11, snapshot-2011-09, snapshot-2011-06, snapshot-2011-07, snapshot-2011-04, snapshot-2011-02, snapshot-2011-03, snapshot-2011-01, pre-merge-intl-branch, snapshot-2010-05, snapshot-2010-04, snapshot-2010-07, snapshot-2010-06, snapshot-2010-01, snapshot-2010-03, snapshot-2010-02, snapshot-2010-08, cross-sol-x86-2010-12-20, intl-branch-2010-03-18-1300, RELEASE_20a, release-20a-pre1, snapshot-2009-11, snapshot-2009-12, cross-sparc-branch-base, intl-branch-base, snapshot-2009-08, snapshot-2009-07, HEAD
Branch point for: cross-sparc-branch, RELEASE-20B-BRANCH, unicode-string-buffer-branch, sparc-tramp-assem-branch, RELEASE-20A-BRANCH, amd64-dd-branch, unicode-string-buffer-impl-branch, intl-branch, cross-sol-x86-branch, intl-2-branch
Changes since 1.3: +1 -1 lines
File MIME type: text/plain
Merge portable-clx (2009-06-16) to main branch.  Tested by running
src/contrib/games/feebs and hemlock which works (in non-unicode
builds).
1 /*
2 * Allegro CL dependent C helper routines for CLX
3 */
4
5 /*
6 * $Id: excldep.c,v 1.4 2009/06/17 18:22:46 rtoy Rel $
7 */
8
9 /*
10 * This code requires select and interval timers.
11 * This means you probably need BSD, or a version
12 * of Unix with select and interval timers added.
13 */
14
15 #include <sys/types.h>
16 #include <sys/errno.h>
17 #include <sys/time.h>
18 #include <stdio.h>
19
20 #define ERROR -1
21 #define INTERRUPT -2
22 #define TIMEOUT 0
23 #define SUCCESS 1
24
25 #ifdef FD_SETSIZE
26 #define NUMBER_OF_FDS FD_SETSIZE /* Highest possible file descriptor */
27 #else
28 #define NUMBER_OF_FDS 32
29 #endif
30
31 /* Length of array needed to hold all file descriptor bits */
32 #define CHECKLEN ((NUMBER_OF_FDS+8*sizeof(int)-1) / (8 * sizeof(int)))
33
34 extern int errno;
35
36 /*
37 * This function waits for input to become available on 'fd'. If timeout is
38 * 0, wait forever. Otherwise wait 'timeout' seconds. If input becomes
39 * available before the timer expires, return SUCCESS. If the timer expires
40 * return TIMEOUT. If an error occurs, return ERROR. If an interrupt occurs
41 * while waiting, return INTERRUPT.
42 */
43 int fd_wait_for_input(fd, timeout)
44 register int fd;
45 register int timeout;
46 {
47 struct timeval timer;
48 register int i;
49 int checkfds[CHECKLEN];
50
51 if (fd < 0 || fd >= NUMBER_OF_FDS) {
52 fprintf(stderr, "Bad file descriptor argument: %d to fd_wait_for_input\n", fd);
53 fflush(stderr);
54 }
55
56 for (i = 0; i < CHECKLEN; i++)
57 checkfds[i] = 0;
58 checkfds[fd / (8 * sizeof(int))] |= 1 << (fd % (8 * sizeof(int)));
59
60 if (timeout) {
61 timer.tv_sec = timeout;
62 timer.tv_usec = 0;
63 i = select(32, checkfds, (int *)0, (int *)0, &timer);
64 } else
65 i = select(32, checkfds, (int *)0, (int *)0, (struct timeval *)0);
66
67 if (i < 0)
68 /* error condition */
69 if (errno == EINTR)
70 return (INTERRUPT);
71 else
72 return (ERROR);
73 else if (i == 0)
74 return (TIMEOUT);
75 else
76 return (SUCCESS);
77 }

  ViewVC Help
Powered by ViewVC 1.1.5