sysselect.h 2.5 KB
Newer Older
Karl Heuer's avatar
Karl Heuer committed
1
/* sysselect.h - System-dependent definitions for the select function.
Paul Eggert's avatar
Paul Eggert committed
2
   Copyright (C) 1995, 2001-2019 Free Software Foundation, Inc.
Karl Heuer's avatar
Karl Heuer committed
3 4 5

This file is part of GNU Emacs.

6
GNU Emacs is free software: you can redistribute it and/or modify
Karl Heuer's avatar
Karl Heuer committed
7
it under the terms of the GNU General Public License as published by
8 9
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
Karl Heuer's avatar
Karl Heuer committed
10 11 12 13 14 15 16

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
17
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
Karl Heuer's avatar
Karl Heuer committed
18

19 20 21
#ifndef SYSSELECT_H
#define SYSSELECT_H 1

22
#ifndef DOS_NT
Karl Heuer's avatar
Karl Heuer committed
23
#include <sys/select.h>
24
#endif
Karl Heuer's avatar
Karl Heuer committed
25

26 27
#include "lisp.h"

28 29 30 31
/* The w32 build defines select stuff in w32.h, which is included
   where w32 needs it, but not where sysselect.h is included.  The w32
   definitions in w32.h are incompatible with the below.  */
#ifndef WINDOWSNT
Karl Heuer's avatar
Karl Heuer committed
32
#ifdef FD_SET
33 34
#ifndef FD_SETSIZE
#define FD_SETSIZE 64
Karl Heuer's avatar
Karl Heuer committed
35 36
#endif
#else /* no FD_SET */
37 38
#define FD_SETSIZE 32
typedef int fd_set;
Karl Heuer's avatar
Karl Heuer committed
39 40 41 42 43 44 45

/* Define the macros to access a single-int bitmap of descriptors.  */
#define FD_SET(n, p) (*(p) |= (1 << (n)))
#define FD_CLR(n, p) (*(p) &= ~(1 << (n)))
#define FD_ISSET(n, p) (*(p) & (1 << (n)))
#define FD_ZERO(p) (*(p) = 0)
#endif /* no FD_SET */
46
#endif /* not WINDOWSNT */
Karl Heuer's avatar
Karl Heuer committed
47

48
#if !defined (HAVE_SELECT)
Karl Heuer's avatar
Karl Heuer committed
49 50
#define select sys_select
#endif
51

52
#ifdef MSDOS
Eli Zaretskii's avatar
Eli Zaretskii committed
53 54 55 56 57
/* The above #define for 'select' gets in the way because sysselect.h
   is included in thread.h, which is included everywhere, and 'select'
   declared in DJGPP system headers has a signature incompatible with
   'pselect', which we emulate in msdos.c.  */
#undef select
58 59
#define pselect sys_select
#endif
60

61
#ifndef WINDOWSNT
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
INLINE_HEADER_BEGIN

/* Check for out-of-range errors if ENABLE_CHECKING is defined.  */

INLINE void
fd_CLR (int fd, fd_set *set)
{
  eassume (0 <= fd && fd < FD_SETSIZE);
  FD_CLR (fd, set);
}

INLINE bool
fd_ISSET (int fd, fd_set *set)
{
  eassume (0 <= fd && fd < FD_SETSIZE);
  return FD_ISSET (fd, set) != 0;
}

INLINE void
fd_SET (int fd, fd_set *set)
{
  eassume (0 <= fd && fd < FD_SETSIZE);
  FD_SET (fd, set);
}

#undef FD_CLR
#undef FD_ISSET
#undef FD_SET
#define FD_CLR(fd, set) fd_CLR (fd, set)
#define FD_ISSET(fd, set) fd_ISSET (fd, set)
#define FD_SET(fd, set) fd_SET (fd, set)

INLINE_HEADER_END

96 97
#endif	/* !WINDOWSNT */

98
#endif