aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdep.c
diff options
context:
space:
mode:
authorStefan Monnier2010-10-15 17:55:33 -0400
committerStefan Monnier2010-10-15 17:55:33 -0400
commit0c747cb143fa227e78f350ac353d703f489209df (patch)
tree5b434055c797bd75eaa1e3d9d0773e586d44daee /src/sysdep.c
parenta01a7932080e8a6e7bc8472c58cefabcc2c37df3 (diff)
parentaa095b2db98ae149737f8de00ee733b1d257ed33 (diff)
downloademacs-0c747cb143fa227e78f350ac353d703f489209df.tar.gz
emacs-0c747cb143fa227e78f350ac353d703f489209df.zip
Merge from trunk
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c278
1 files changed, 4 insertions, 274 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index e7d35d46bf7..f68d475d22c 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -71,10 +71,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
71#endif 71#endif
72 72
73#include <sys/file.h> 73#include <sys/file.h>
74
75#ifdef HAVE_FCNTL_H
76#include <fcntl.h> 74#include <fcntl.h>
77#endif
78 75
79#include "systty.h" 76#include "systty.h"
80#include "syswait.h" 77#include "syswait.h"
@@ -126,19 +123,12 @@ struct utimbuf {
126#endif 123#endif
127#endif 124#endif
128 125
129/* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
130#ifndef LPASS8
131#define LPASS8 0
132#endif
133
134static const int baud_convert[] = 126static const int baud_convert[] =
135 { 127 {
136 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200, 128 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
137 1800, 2400, 4800, 9600, 19200, 38400 129 1800, 2400, 4800, 9600, 19200, 38400
138 }; 130 };
139 131
140int emacs_ospeed;
141
142void croak (char *) NO_RETURN; 132void croak (char *) NO_RETURN;
143 133
144/* Temporary used by `sigblock' when defined in terms of signprocmask. */ 134/* Temporary used by `sigblock' when defined in terms of signprocmask. */
@@ -278,6 +268,8 @@ stuff_char (char c)
278void 268void
279init_baud_rate (int fd) 269init_baud_rate (int fd)
280{ 270{
271 int emacs_ospeed;
272
281 if (noninteractive) 273 if (noninteractive)
282 emacs_ospeed = 0; 274 emacs_ospeed = 0;
283 else 275 else
@@ -300,16 +292,6 @@ init_baud_rate (int fd)
300} 292}
301 293
302 294
303/*ARGSUSED*/
304void
305set_exclusive_use (int fd)
306{
307#ifdef FIOCLEX
308 ioctl (fd, FIOCLEX, 0);
309#endif
310 /* Ok to do nothing if this feature does not exist */
311}
312
313 295
314int wait_debugging; /* Set nonzero to make following function work under dbx 296int wait_debugging; /* Set nonzero to make following function work under dbx
315 (at least for bsd). */ 297 (at least for bsd). */
@@ -373,22 +355,7 @@ wait_for_termination (int pid)
373void 355void
374flush_pending_output (int channel) 356flush_pending_output (int channel)
375{ 357{
376#ifndef DOS_NT 358 /* FIXME: maybe this function should be removed */
377 /* If we try this, we get hit with SIGTTIN, because
378 the child's tty belongs to the child's pgrp. */
379#else
380#ifdef TCFLSH
381 ioctl (channel, TCFLSH, 1);
382#else
383#ifdef TIOCFLUSH
384 int zero = 0;
385 /* 3rd arg should be ignored
386 but some 4.2 kernels actually want the address of an int
387 and nonzero means something different. */
388 ioctl (channel, TIOCFLUSH, &zero);
389#endif
390#endif
391#endif
392} 359}
393 360
394/* Set up the terminal at the other end of a pseudo-terminal that 361/* Set up the terminal at the other end of a pseudo-terminal that
@@ -483,7 +450,7 @@ child_setup_tty (int out)
483 EMACS_SET_TTY (out, &s, 0); 450 EMACS_SET_TTY (out, &s, 0);
484#endif /* not WINDOWSNT */ 451#endif /* not WINDOWSNT */
485} 452}
486#endif /* MSDOS */ 453#endif /* not MSDOS */
487 454
488 455
489/* Record a signal code and the handler for it. */ 456/* Record a signal code and the handler for it. */
@@ -1486,242 +1453,6 @@ init_system_name (void)
1486 } 1453 }
1487} 1454}
1488 1455
1489#ifndef MSDOS
1490#if !defined (HAVE_SELECT)
1491
1492#include "sysselect.h"
1493#undef select
1494
1495#if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
1496/* Cause explanatory error message at compile time,
1497 since the select emulation is not good enough for X. */
1498int *x = &x_windows_lose_if_no_select_system_call;
1499#endif
1500
1501/* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
1502 * Only checks read descriptors.
1503 */
1504/* How long to wait between checking fds in select */
1505#define SELECT_PAUSE 1
1506int select_alarmed;
1507
1508/* For longjmp'ing back to read_input_waiting. */
1509
1510jmp_buf read_alarm_throw;
1511
1512/* Nonzero if the alarm signal should throw back to read_input_waiting.
1513 The read_socket_hook function sets this to 1 while it is waiting. */
1514
1515int read_alarm_should_throw;
1516
1517void
1518select_alarm (int ignore)
1519{
1520 select_alarmed = 1;
1521 signal (SIGALRM, SIG_IGN);
1522 SIGNAL_THREAD_CHECK (SIGALRM);
1523 if (read_alarm_should_throw)
1524 longjmp (read_alarm_throw, 1);
1525}
1526
1527#ifndef WINDOWSNT
1528/* Only rfds are checked. */
1529int
1530sys_select (int nfds,
1531 SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
1532 EMACS_TIME *timeout)
1533{
1534 /* XXX This needs to be updated for multi-tty support. Is there
1535 anybody who needs to emulate select these days? */
1536 int ravail = 0;
1537 SELECT_TYPE orfds;
1538 int timeoutval;
1539 int *local_timeout;
1540 extern int proc_buffered_char[];
1541 extern int process_tick, update_tick;
1542 unsigned char buf;
1543
1544#if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
1545 /* If we're using X, then the native select will work; we only need the
1546 emulation for non-X usage. */
1547 if (!NILP (Vinitial_window_system))
1548 return select (nfds, rfds, wfds, efds, timeout);
1549#endif
1550 timeoutval = timeout ? EMACS_SECS (*timeout) : 100000;
1551 local_timeout = &timeoutval;
1552 FD_ZERO (&orfds);
1553 if (rfds)
1554 {
1555 orfds = *rfds;
1556 FD_ZERO (rfds);
1557 }
1558 if (wfds)
1559 FD_ZERO (wfds);
1560 if (efds)
1561 FD_ZERO (efds);
1562
1563 /* If we are looking only for the terminal, with no timeout,
1564 just read it and wait -- that's more efficient. */
1565 if (*local_timeout == 100000 && process_tick == update_tick
1566 && FD_ISSET (0, &orfds))
1567 {
1568 int fd;
1569 for (fd = 1; fd < nfds; ++fd)
1570 if (FD_ISSET (fd, &orfds))
1571 goto hardway;
1572 if (! detect_input_pending ())
1573 read_input_waiting ();
1574 FD_SET (0, rfds);
1575 return 1;
1576 }
1577
1578 hardway:
1579 /* Once a second, till the timer expires, check all the flagged read
1580 * descriptors to see if any input is available. If there is some then
1581 * set the corresponding bit in the return copy of rfds.
1582 */
1583 while (1)
1584 {
1585 register int to_check, fd;
1586
1587 if (rfds)
1588 {
1589 for (to_check = nfds, fd = 0; --to_check >= 0; fd++)
1590 {
1591 if (FD_ISSET (fd, &orfds))
1592 {
1593 int avail = 0, status = 0;
1594
1595 if (fd == 0)
1596 avail = detect_input_pending (); /* Special keyboard handler */
1597 else
1598 {
1599#ifdef FIONREAD
1600 status = ioctl (fd, FIONREAD, &avail);
1601#else /* no FIONREAD */
1602 /* Hoping it will return -1 if nothing available
1603 or 0 if all 0 chars requested are read. */
1604 if (proc_buffered_char[fd] >= 0)
1605 avail = 1;
1606 else
1607 {
1608 avail = read (fd, &buf, 1);
1609 if (avail > 0)
1610 proc_buffered_char[fd] = buf;
1611 }
1612#endif /* no FIONREAD */
1613 }
1614 if (status >= 0 && avail > 0)
1615 {
1616 FD_SET (fd, rfds);
1617 ravail++;
1618 }
1619 }
1620 }
1621 }
1622 if (*local_timeout == 0 || ravail != 0 || process_tick != update_tick)
1623 break;
1624
1625 turn_on_atimers (0);
1626 signal (SIGALRM, select_alarm);
1627 select_alarmed = 0;
1628 alarm (SELECT_PAUSE);
1629
1630 /* Wait for a SIGALRM (or maybe a SIGTINT) */
1631 while (select_alarmed == 0 && *local_timeout != 0
1632 && process_tick == update_tick)
1633 {
1634 /* If we are interested in terminal input,
1635 wait by reading the terminal.
1636 That makes instant wakeup for terminal input at least. */
1637 if (FD_ISSET (0, &orfds))
1638 {
1639 read_input_waiting ();
1640 if (detect_input_pending ())
1641 select_alarmed = 1;
1642 }
1643 else
1644 pause ();
1645 }
1646 (*local_timeout) -= SELECT_PAUSE;
1647
1648 /* Reset the old alarm if there was one. */
1649 turn_on_atimers (1);
1650
1651 if (*local_timeout == 0) /* Stop on timer being cleared */
1652 break;
1653 }
1654 return ravail;
1655}
1656#endif /* not WINDOWSNT */
1657
1658/* Read keyboard input into the standard buffer,
1659 waiting for at least one character. */
1660
1661void
1662read_input_waiting (void)
1663{
1664 /* XXX This needs to be updated for multi-tty support. Is there
1665 anybody who needs to emulate select these days? */
1666 int nread, i;
1667
1668 if (read_socket_hook)
1669 {
1670 struct input_event hold_quit;
1671
1672 EVENT_INIT (hold_quit);
1673 hold_quit.kind = NO_EVENT;
1674
1675 read_alarm_should_throw = 0;
1676 if (! setjmp (read_alarm_throw))
1677 nread = (*read_socket_hook) (0, 1, &hold_quit);
1678 else
1679 nread = -1;
1680
1681 if (hold_quit.kind != NO_EVENT)
1682 kbd_buffer_store_event (&hold_quit);
1683 }
1684 else
1685 {
1686 struct input_event e;
1687 char buf[3];
1688 nread = read (fileno (stdin), buf, 1);
1689 EVENT_INIT (e);
1690
1691 /* Scan the chars for C-g and store them in kbd_buffer. */
1692 e.kind = ASCII_KEYSTROKE_EVENT;
1693 e.frame_or_window = selected_frame;
1694 e.modifiers = 0;
1695 for (i = 0; i < nread; i++)
1696 {
1697 /* Convert chars > 0177 to meta events if desired.
1698 We do this under the same conditions that read_avail_input does. */
1699 if (read_socket_hook == 0)
1700 {
1701 /* If the user says she has a meta key, then believe her. */
1702 if (meta_key == 1 && (buf[i] & 0x80))
1703 e.modifiers = meta_modifier;
1704 if (meta_key != 2)
1705 buf[i] &= ~0x80;
1706 }
1707
1708 XSETINT (e.code, buf[i]);
1709 kbd_buffer_store_event (&e);
1710 /* Don't look at input that follows a C-g too closely.
1711 This reduces lossage due to autorepeat on C-g. */
1712 if (buf[i] == quit_char)
1713 break;
1714 }
1715 }
1716}
1717
1718#if !defined (HAVE_SELECT)
1719#define select sys_select
1720#endif
1721
1722#endif /* not HAVE_SELECT */
1723#endif /* not MSDOS */
1724
1725/* POSIX signals support - DJB */ 1456/* POSIX signals support - DJB */
1726/* Anyone with POSIX signals should have ANSI C declarations */ 1457/* Anyone with POSIX signals should have ANSI C declarations */
1727 1458
@@ -2271,7 +2002,6 @@ dup2 (int oldd, int newd)
2271#ifndef HAVE_GETTIMEOFDAY 2002#ifndef HAVE_GETTIMEOFDAY
2272#ifdef HAVE_TIMEVAL 2003#ifdef HAVE_TIMEVAL
2273 2004
2274/* ARGSUSED */
2275int 2005int
2276gettimeofday (struct timeval *tp, struct timezone *tzp) 2006gettimeofday (struct timeval *tp, struct timezone *tzp)
2277{ 2007{