/* Interfaces to system-dependent kernel and library entries.
- Copyright (C) 1985-1988, 1993-1995, 1999-2013 Free Software
+ Copyright (C) 1985-1988, 1993-1995, 1999-2014 Free Software
Foundation, Inc.
This file is part of GNU Emacs.
#include <config.h>
-#define SYSTIME_INLINE EXTERN_INLINE
-
#include <execinfo.h>
#include "sysstdio.h"
#ifdef HAVE_PWD_H
#include "syssignal.h"
#include "systime.h"
-static void emacs_get_tty (int, struct emacs_tty *);
-static int emacs_set_tty (int, struct emacs_tty *, bool);
+void emacs_get_tty (int, struct emacs_tty *) EXTERNALLY_VISIBLE;
+int emacs_set_tty (int, struct emacs_tty *, bool) EXTERNALLY_VISIBLE;
/* ULLONG_MAX is missing on Red Hat Linux 7.3; see Bug#11781. */
#ifndef ULLONG_MAX
/* Return the current working directory. Returns NULL on errors.
Any other returned value must be freed with free. This is used
only when get_current_dir_name is not defined on the system. */
-char*
+char *
get_current_dir_name (void)
{
char *buf;
void
stuff_char (char c)
{
- if (! FRAME_TERMCAP_P (SELECTED_FRAME ()))
+ if (! (FRAMEP (selected_frame)
+ && FRAME_LIVE_P (XFRAME (selected_frame))
+ && FRAME_TERMCAP_P (XFRAME (selected_frame))))
return;
/* Should perhaps error if in batch mode */
#endif /* not DOS_NT */
}
- baud_rate = (emacs_ospeed < sizeof baud_convert / sizeof baud_convert[0]
+ baud_rate = (emacs_ospeed < ARRAYELTS (baud_convert)
? baud_convert[emacs_ospeed] : 9600);
if (baud_rate == 0)
baud_rate = 1200;
{
#ifdef DOS_NT /* Demacs 1.1.2 91/10/20 Manabu Higashida */
int st;
+#ifdef MSDOS
char oldwd[MAXPATHLEN+1]; /* Fixed length is safe on MSDOS. */
+#else
+ char oldwd[MAX_UTF8_PATH];
+#endif
#endif
pid_t pid;
int status;
#endif
}
+#ifndef DOS_NT
static void
reset_sigio (int fd)
{
fcntl (fd, F_SETFL, old_fcntl_flags[fd]);
#endif
}
+#endif
void
request_sigio (void)
signal (SIGIO, SIG_IGN);
#endif
}
+\f
+#ifndef MSDOS
+/* Block SIGCHLD. */
+
+void
+block_child_signal (sigset_t *oldset)
+{
+ sigset_t blocked;
+ sigemptyset (&blocked);
+ sigaddset (&blocked, SIGCHLD);
+ sigaddset (&blocked, SIGINT);
+ pthread_sigmask (SIG_BLOCK, &blocked, oldset);
+}
+/* Unblock SIGCHLD. */
+
+void
+unblock_child_signal (sigset_t const *oldset)
+{
+ pthread_sigmask (SIG_SETMASK, oldset, 0);
+}
+
+#endif /* !MSDOS */
\f
/* Saving and restoring the process group of Emacs's terminal. */
/* Block and unblock SIGTTOU. */
void
-block_tty_out_signal (void)
+block_tty_out_signal (sigset_t *oldset)
{
#ifdef SIGTTOU
sigset_t blocked;
sigemptyset (&blocked);
sigaddset (&blocked, SIGTTOU);
- pthread_sigmask (SIG_BLOCK, &blocked, 0);
+ pthread_sigmask (SIG_BLOCK, &blocked, oldset);
#endif
}
void
-unblock_tty_out_signal (void)
+unblock_tty_out_signal (sigset_t const *oldset)
{
#ifdef SIGTTOU
- pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
+ pthread_sigmask (SIG_SETMASK, oldset, 0);
#endif
}
tcsetpgrp_without_stopping (int fd, pid_t pgid)
{
#ifdef SIGTTOU
+ sigset_t oldset;
block_input ();
- block_tty_out_signal ();
+ block_tty_out_signal (&oldset);
tcsetpgrp (fd, pgid);
- unblock_tty_out_signal ();
+ unblock_tty_out_signal (&oldset);
unblock_input ();
#endif
}
/* Set *TC to the parameters associated with the terminal FD,
or clear it if the parameters are not available. */
-static void
+void
emacs_get_tty (int fd, struct emacs_tty *settings)
{
/* Retrieve the primary parameters - baud rate, character size, etcetera. */
-#ifndef DOS_NT
- /* We have those nifty POSIX tcmumbleattr functions. */
memset (&settings->main, 0, sizeof (settings->main));
+#ifdef DOS_NT
+#ifdef WINDOWSNT
+ HANDLE h = (HANDLE)_get_osfhandle (fd);
+ DWORD console_mode;
+
+ if (h && h != INVALID_HANDLE_VALUE)
+ {
+ if (GetConsoleMode (h, &console_mode))
+ settings->main = console_mode;
+ }
+#endif /* WINDOWSNT */
+#else /* !DOS_NT */
+ /* We have those nifty POSIX tcmumbleattr functions. */
tcgetattr (fd, &settings->main);
#endif
}
*SETTINGS. If FLUSHP, discard input.
Return 0 if all went well, and -1 (setting errno) if anything failed. */
-static int
+int
emacs_set_tty (int fd, struct emacs_tty *settings, bool flushp)
{
/* Set the primary parameters - baud rate, character size, etcetera. */
-#ifndef DOS_NT
+#ifdef DOS_NT
+#ifdef WINDOWSNT
+ HANDLE h = (HANDLE)_get_osfhandle (fd);
+
+ if (h && h != INVALID_HANDLE_VALUE)
+ {
+ DWORD new_mode;
+
+ /* Assume the handle is open for input. */
+ if (flushp)
+ FlushConsoleInputBuffer (h);
+ new_mode = settings->main;
+ SetConsoleMode (h, new_mode);
+ }
+#endif /* WINDOWSNT */
+#else /* !DOS_NT */
int i;
/* We have those nifty POSIX tcmumbleattr functions.
William J. Smith <wjs@wiis.wang.com> writes:
return 0;
#endif /* DOS_NT */
}
+
+/* Discard echoing. */
+
+void
+suppress_echo_on_tty (int fd)
+{
+ struct emacs_tty etty;
+
+ emacs_get_tty (fd, &etty);
+#ifdef DOS_NT
+ /* Set raw input mode. */
+ etty.main = 0;
+#else
+ etty.main.c_lflag &= ~ICANON; /* Disable buffering */
+ etty.main.c_lflag &= ~ECHO; /* Disable echoing */
+#endif /* ! WINDOWSNT */
+ emacs_set_tty (fd, &etty, 0);
+}
\f
/* Get terminal size from system.
Store number of lines into *HEIGHTP and width into *WIDTHP.
int i;
tty_turn_off_insert (tty_out);
- for (i = curX (tty_out); i < FrameCols (tty_out) - 1; i++)
+ for (i = cursorX (tty_out); i < FrameCols (tty_out) - 1; i++)
{
fputc (' ', tty_out->output);
}
/* When handling a signal, block nonfatal system signals that are caught
by Emacs. This makes race conditions less likely. */
sigaddset (&action->sa_mask, SIGALRM);
+#ifdef SIGCHLD
sigaddset (&action->sa_mask, SIGCHLD);
+#endif
#ifdef SIGDANGER
sigaddset (&action->sa_mask, SIGDANGER);
#endif
#endif
}
- if (! IEEE_FLOATING_POINT)
- sigaddset (&action->sa_mask, SIGFPE);
-
action->sa_handler = handler;
action->sa_flags = emacs_sigaction_flags ();
}
# ifdef SIGBUS
sys_siglist[SIGBUS] = "Bus error";
# endif
+# ifdef SIGCHLD
sys_siglist[SIGCHLD] = "Child status changed";
+# endif
# ifdef SIGCONT
sys_siglist[SIGCONT] = "Continued";
# endif
int
emacs_pipe (int fd[2])
{
+#ifdef MSDOS
+ return pipe (fd);
+#else /* !MSDOS */
int result = pipe2 (fd, O_CLOEXEC);
if (! O_CLOEXEC && result == 0)
{
fcntl (fd[1], F_SETFD, FD_CLOEXEC);
}
return result;
+#endif /* !MSDOS */
}
/* Approximate posix_close and POSIX_CLOSE_RESTART well enough for Emacs.
Return the number of bytes read, which might be less than NBYTE.
On error, set errno and return -1. */
ptrdiff_t
-emacs_read (int fildes, char *buf, ptrdiff_t nbyte)
+emacs_read (int fildes, void *buf, ptrdiff_t nbyte)
{
- register ssize_t rtnval;
+ ssize_t rtnval;
/* There is no need to check against MAX_RW_COUNT, since no caller ever
passes a size that large to emacs_read. */
interrupted or if a partial write occurs. Return the number of
bytes written, setting errno if this is less than NBYTE. */
ptrdiff_t
-emacs_write (int fildes, char const *buf, ptrdiff_t nbyte)
+emacs_write (int fildes, void const *buf, ptrdiff_t nbyte)
{
return emacs_full_write (fildes, buf, nbyte, 0);
}
/* Like emacs_write, but also process pending signals if interrupted. */
ptrdiff_t
-emacs_write_sig (int fildes, char const *buf, ptrdiff_t nbyte)
+emacs_write_sig (int fildes, void const *buf, ptrdiff_t nbyte)
{
return emacs_full_write (fildes, buf, nbyte, 1);
}