/* Interfaces to system-dependent kernel and library entries.
- Copyright (C) 1985, 86, 87, 88, 93, 94 Free Software Foundation, Inc.
+ Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include <sys/stat.h>
#include <errno.h>
+/* Get _POSIX_VDISABLE, if it is available. */
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
#include <dos.h>
#include "dosfns.h"
#endif
#endif
+#ifndef VFORK_RETURN_TYPE
+#define VFORK_RETURN_TYPE int
+#endif
+
/* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
#ifndef LPASS8
#define LPASS8 0
s.main.c_lflag |= ICANON; /* Enable erase/kill and eof processing */
s.main.c_cc[VEOF] = 04; /* insure that EOF is Control-D */
- s.main.c_cc[VERASE] = 0377; /* disable erase processing */
- s.main.c_cc[VKILL] = 0377; /* disable kill processing */
+ s.main.c_cc[VERASE] = CDISABLE; /* disable erase processing */
+ s.main.c_cc[VKILL] = CDISABLE; /* disable kill processing */
#ifdef HPUX
s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
#ifdef WINDOWSNT
pid = -1;
#else /* not WINDOWSNT */
+#ifdef MSDOS
+ pid = 0;
+#else
pid = vfork ();
-
if (pid == -1)
error ("Can't spawn subshell");
+#endif
+
if (pid == 0)
#endif /* not WINDOWSNT */
{
- char *sh;
+ char *sh = 0;
#ifdef MSDOS /* MW, Aug 1993 */
getwd (oldwd);
+ if (sh == 0)
+ sh = (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
#endif
- sh = (char *) egetenv ("SHELL");
+ if (sh == 0)
+ sh = (char *) egetenv ("SHELL");
if (sh == 0)
sh = "sh";
#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
st = system (sh);
chdir (oldwd);
+#if 0 /* This is also reported if last command executed in subshell failed, KFS */
if (st)
report_file_error ("Can't execute subshell", Fcons (build_string (sh), Qnil));
+#endif
#else /* not MSDOS */
#ifdef WINDOWSNT
- restore_console ();
-
/* Waits for process completion */
pid = _spawnlp (_P_WAIT, sh, sh, NULL);
if (pid == -1)
save_signal_handlers (saved_handlers);
synch_process_alive = 1;
+#ifndef MSDOS
wait_for_termination (pid);
+#endif
restore_signal_handlers (saved_handlers);
#endif /* !VMS */
}
/* Set the parameters of the tty on FD according to the contents of
- *SETTINGS. If WAITP is non-zero, we wait for all queued output to
- be written before making the change; otherwise, we forget any
- queued input and make the change immediately.
+ *SETTINGS. If FLUSHP is non-zero, we discard input.
Return 0 if all went well, and -1 if anything failed. */
+
int
-emacs_set_tty (fd, settings, waitp)
+emacs_set_tty (fd, settings, flushp)
int fd;
struct emacs_tty *settings;
- int waitp;
+ int flushp;
{
/* Set the primary parameters - baud rate, character size, etcetera. */
#ifdef HAVE_TCATTR
AIX requires this to keep tty from hanging occasionally." */
/* This make sure that we don't loop indefinitely in here. */
for (i = 0 ; i < 10 ; i++)
- if (tcsetattr (fd, waitp ? TCSAFLUSH : TCSADRAIN, &settings->main) < 0)
+ if (tcsetattr (fd, flushp ? TCSAFLUSH : TCSADRAIN, &settings->main) < 0)
{
if (errno == EINTR)
continue;
#else
#ifdef HAVE_TERMIO
/* The SYSV-style interface? */
- if (ioctl (fd, waitp ? TCSETAW : TCSETAF, &settings->main) < 0)
+ if (ioctl (fd, flushp ? TCSETAF : TCSETAW, &settings->main) < 0)
return -1;
#else
#else
#ifndef DOS_NT
/* I give up - I hope you have the BSD ioctls. */
- if (ioctl (fd, (waitp) ? TIOCSETP : TIOCSETN, &settings->main) < 0)
+ if (ioctl (fd, (flushp) ? TIOCSETP : TIOCSETN, &settings->main) < 0)
return -1;
#endif /* not DOS_NT */
/* The initial tty mode bits */
struct emacs_tty old_tty;
-int term_initted; /* 1 if outer tty status has been recorded */
+/* 1 if we have been through init_sys_modes. */
+int term_initted;
+
+/* 1 if outer tty status has been recorded. */
+int old_tty_valid;
#ifdef BSD4_1
/* BSD 4.1 needs to keep track of the lmode bits in order to start
{
EMACS_GET_TTY (input_fd, &old_tty);
+ old_tty_valid = 1;
+
tty = old_tty;
#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
tty.main.c_cc[VSTOP] = CDISABLE;
#endif /* VSTOP */
#endif /* mips or HAVE_TCATTR */
+#ifdef SET_LINE_DISCIPLINE
+ /* Need to explicitely request TERMIODISC line discipline or
+ Ultrix's termios does not work correctly. */
+ tty.main.c_line = SET_LINE_DISCIPLINE;
+#endif
#ifdef AIX
#ifndef IBMR2AIX
- /* AIX enhanced edit loses NULs, so disable it */
+ /* AIX enhanced edit loses NULs, so disable it. */
tty.main.c_line = 0;
tty.main.c_iflag &= ~ASCEDIT;
#else
#endif
#if defined (HAVE_TERMIOS) || defined (HPUX9)
+#ifdef TCOON
if (!flow_control) tcflow (input_fd, TCOON);
#endif
+#endif
-#ifdef AIX
+#ifdef AIXHFT
hft_init ();
#ifdef IBMR2AIX
{
write (1, "\033[20l", 5);
}
#endif
-#endif
+#endif /* AIXHFT */
#ifdef VMS
/* Appears to do nothing when in PASTHRU mode.
#else
setbuf (stdout, _sobuf);
#endif
+#ifdef HAVE_X_WINDOWS
+ /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
+ needs the initialization code below. */
if (! read_socket_hook && EQ (Vwindow_system, Qnil))
+#endif
set_terminal_modes ();
if (term_initted && no_redraw_on_reenter)
return;
#endif
cursor_to (FRAME_HEIGHT (selected_frame) - 1, 0);
-#ifdef MSDOS
- if (!EQ (Vwindow_system, Qnil))
- {
- /* Change to grey on white. */
- putchar ('\e');
- putchar ('A');
- putchar (7);
- }
-#endif
clear_end_of_line (FRAME_WIDTH (selected_frame));
/* clear_end_of_line may move the cursor */
cursor_to (FRAME_HEIGHT (selected_frame) - 1, 0);
-#ifdef IBMR2AIX
+#if defined (IBMR2AIX) && defined (AIXHFT)
{
/* HFT devices normally use ^J as a LF/CR. We forced it to
do the LF only. Now, we need to reset it. */
reset_sigio ();
#endif /* BSD4_1 */
- while (EMACS_SET_TTY (input_fd, &old_tty, 0) < 0 && errno == EINTR)
- ;
+ if (old_tty_valid)
+ while (EMACS_SET_TTY (input_fd, &old_tty, 0) < 0 && errno == EINTR)
+ ;
#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
dos_ttcooked ();
#endif
-#ifdef AIX
+#ifdef SET_LINE_DISCIPLINE
+ /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
+ A different old line discipline is therefore not restored, yet.
+ Restore the old line discipline by hand. */
+ ioctl (0, TIOCSETD, &old_tty.main.c_line);
+#endif
+
+#ifdef AIXHFT
hft_reset ();
#endif
uname (&uts);
Vsystem_name = build_string (uts.nodename);
#else /* HAVE_GETHOSTNAME */
- int hostname_size = 256;
+ unsigned int hostname_size = 256;
char *hostname = (char *) alloca (hostname_size);
/* Try to get the host name; if the buffer is too short, try
}
if (hp)
{
- char *fqdn = hp->h_name;
+ char *fqdn = (char *) hp->h_name;
char *p;
if (!index (fqdn, '.'))
}
}
\f
+#ifndef MSDOS
#ifndef VMS
-#ifndef HAVE_SELECT
+#if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
-#ifdef HAVE_X_WINDOWS
+#include "sysselect.h"
+#undef select
+
+#if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
/* Cause explanatory error message at compile time,
since the select emulation is not good enough for X. */
int *x = &x_windows_lose_if_no_select_system_call;
#ifndef WINDOWSNT
/* Only rfds are checked. */
int
-select (nfds, rfds, wfds, efds, timeout)
+sys_select (nfds, rfds, wfds, efds, timeout)
int nfds;
- int *rfds, *wfds, *efds, *timeout;
+ SELECT_TYPE *rfds, *wfds, *efds;
+ EMACS_TIME *timeout;
{
- int ravail = 0, orfds = 0, old_alarm;
- int timeoutval = timeout ? *timeout : 100000;
- int *local_timeout = &timeoutval;
+ int ravail = 0, old_alarm;
+ SELECT_TYPE orfds;
+ int timeoutval;
+ int *local_timeout;
extern int proc_buffered_char[];
#ifndef subprocesses
int process_tick = 0, update_tick = 0;
SIGTYPE (*old_trap) ();
unsigned char buf;
+#if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
+ /* If we're using X, then the native select will work; we only need the
+ emulation for non-X usage. */
+ if (!NILP (Vwindow_system))
+ return select (nfds, rfds, wfds, efds, timeout);
+#endif
+ timeoutval = timeout ? EMACS_SECS (*timeout) : 100000;
+ local_timeout = &timeoutval;
+ FD_ZERO (&orfds);
if (rfds)
{
orfds = *rfds;
- *rfds = 0;
+ FD_ZERO (rfds);
}
if (wfds)
- *wfds = 0;
+ FD_ZERO (wfds);
if (efds)
- *efds = 0;
+ FD_ZERO (efds);
/* If we are looking only for the terminal, with no timeout,
just read it and wait -- that's more efficient. */
- if (orfds == 1 && *local_timeout == 100000 && process_tick == update_tick)
+ if (*local_timeout == 100000 && process_tick == update_tick
+ && FD_ISSET (0, &orfds))
{
+ int fd;
+ for (fd = 1; fd < nfds; ++fd)
+ if (FD_ISSET (fd, &orfds))
+ goto hardway;
if (! detect_input_pending ())
read_input_waiting ();
- *rfds = 1;
+ FD_SET (0, rfds);
return 1;
}
+ hardway:
/* Once a second, till the timer expires, check all the flagged read
* descriptors to see if any input is available. If there is some then
* set the corresponding bit in the return copy of rfds.
*/
while (1)
{
- register int to_check, bit, fd;
+ register int to_check, fd;
if (rfds)
{
- for (to_check = nfds, bit = 1, fd = 0; --to_check >= 0; bit <<= 1, fd++)
+ for (to_check = nfds, fd = 0; --to_check >= 0; fd++)
{
- if (orfds & bit)
+ if (FD_ISSET (fd, &orfds))
{
int avail = 0, status = 0;
- if (bit == 1)
+ if (fd == 0)
avail = detect_input_pending (); /* Special keyboard handler */
else
{
#ifdef FIONREAD
status = ioctl (fd, FIONREAD, &avail);
#else /* no FIONREAD */
-#ifdef MSDOS
- abort (); /* I don't think we need it. */
-#else /* not MSDOS */
/* Hoping it will return -1 if nothing available
or 0 if all 0 chars requested are read. */
if (proc_buffered_char[fd] >= 0)
if (avail > 0)
proc_buffered_char[fd] = buf;
}
-#endif /* not MSDOS */
#endif /* no FIONREAD */
}
if (status >= 0 && avail > 0)
{
- (*rfds) |= bit;
+ FD_SET (fd, rfds);
ravail++;
}
}
while (select_alarmed == 0 && *local_timeout != 0
&& process_tick == update_tick)
{
-#ifdef MSDOS
- sleep_or_kbd_hit (SELECT_PAUSE, (orfds & 1) != 0);
- select_alarm ();
-#else /* not MSDOS */
/* If we are interested in terminal input,
wait by reading the terminal.
That makes instant wakeup for terminal input at least. */
- if (orfds & 1)
+ if (FD_ISSET (0, &orfds))
{
read_input_waiting ();
if (detect_input_pending ())
}
else
pause ();
-#endif /* not MSDOS */
}
(*local_timeout) -= SELECT_PAUSE;
/* Reset the old alarm if there was one */
/* Don't look at input that follows a C-g too closely.
This reduces lossage due to autorepeat on C-g. */
if (buf[i].kind == ascii_keystroke
- && XINT(buf[i].code) == quit_char)
+ && buf[i].code == quit_char)
break;
}
}
#endif /* not HAVE_SELECT */
#endif /* not VMS */
+#endif /* not MSDOS */
\f
#ifdef BSD4_1
/*
#endif /* POSIX_SIGNALS */
\f
-#ifndef BSTRING
+#ifndef HAVE_RANDOM
+#ifdef random
+#define HAVE_RANDOM
+#endif
+#endif
-#ifndef bzero
+/* Figure out how many bits the system's random number generator uses.
+ `random' and `lrand48' are assumed to return 31 usable bits.
+ BSD `rand' returns a 31 bit value but the low order bits are unusable;
+ so we'll shift it and treat it like the 15-bit USG `rand'. */
+
+#ifndef RAND_BITS
+# ifdef HAVE_RANDOM
+# define RAND_BITS 31
+# else /* !HAVE_RANDOM */
+# ifdef HAVE_LRAND48
+# define RAND_BITS 31
+# define random lrand48
+# else /* !HAVE_LRAND48 */
+# define RAND_BITS 15
+# if RAND_MAX == 32767
+# define random rand
+# else /* RAND_MAX != 32767 */
+# if RAND_MAX == 2147483647
+# define random() (rand () >> 16)
+# else /* RAND_MAX != 2147483647 */
+# ifdef USG
+# define random rand
+# else
+# define random() (rand () >> 16)
+# endif /* !BSD */
+# endif /* RAND_MAX != 2147483647 */
+# endif /* RAND_MAX != 32767 */
+# endif /* !HAVE_LRAND48 */
+# endif /* !HAVE_RANDOM */
+#endif /* !RAND_BITS */
void
-bzero (b, length)
- register char *b;
- register int length;
-{
-#ifdef VMS
- short zero = 0;
- long max_str = 65535;
-
- while (length > max_str) {
- (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
- length -= max_str;
- b += max_str;
- }
- max_str = length;
- (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
-#else
- while (length-- > 0)
- *b++ = 0;
-#endif /* not VMS */
-}
-
-#endif /* no bzero */
-
-#ifndef bcopy
-/* Saying `void' requires a declaration, above, where bcopy is used
- and that declaration causes pain for systems where bcopy is a macro. */
-bcopy (b1, b2, length)
- register char *b1;
- register char *b2;
- register int length;
+seed_random (arg)
+ long arg;
{
-#ifdef VMS
- long max_str = 65535;
-
- while (length > max_str) {
- (void) LIB$MOVC3 (&max_str, b1, b2);
- length -= max_str;
- b1 += max_str;
- b2 += max_str;
- }
- max_str = length;
- (void) LIB$MOVC3 (&length, b1, b2);
-#else
- while (length-- > 0)
- *b2++ = *b1++;
-#endif /* not VMS */
-}
-#endif /* no bcopy */
-
-#ifndef bcmp
-int
-bcmp (b1, b2, length) /* This could be a macro! */
- register char *b1;
- register char *b2;
- register int length;
-{
-#ifdef VMS
- struct dsc$descriptor_s src1 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b1};
- struct dsc$descriptor_s src2 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b2};
-
- return STR$COMPARE (&src1, &src2);
+#ifdef HAVE_RANDOM
+ srandom ((unsigned int)arg);
#else
- while (length-- > 0)
- if (*b1++ != *b2++)
- return 1;
-
- return 0;
-#endif /* not VMS */
+# ifdef HAVE_LRAND48
+ srand48 (arg);
+# else
+ srand ((unsigned int)arg);
+# endif
+#endif
}
-#endif /* no bcmp */
-
-#endif /* not BSTRING */
-\f
-#ifndef HAVE_RANDOM
-#ifndef random
/*
- * The BSD random returns numbers in the range of
- * 0 to 2e31 - 1. The USG rand returns numbers in the
- * range of 0 to 2e15 - 1. This is probably not significant
- * in this usage.
+ * Build a full Emacs-sized word out of whatever we've got.
+ * This suffices even for a 64-bit architecture with a 15-bit rand.
*/
-
long
-random ()
-{
-#ifdef HAVE_LRAND48
- return lrand48 ();
-#else
-/* The BSD rand returns numbers in the range of 0 to 2e31 - 1,
- with unusable least significant bits. The USG rand returns
- numbers in the range of 0 to 2e15 - 1, all usable. Let us
- build a usable 30 bit number from either. */
-#ifdef USG
- return (rand () << 15) + rand ();
-#else
- return (rand () & 0x3fff8000) + (rand () >> 16);
-#endif
-#endif
+get_random ()
+{
+ long val = random ();
+#if VALBITS > RAND_BITS
+ val = (val << RAND_BITS) ^ random ();
+#if VALBITS > 2*RAND_BITS
+ val = (val << RAND_BITS) ^ random ();
+#if VALBITS > 3*RAND_BITS
+ val = (val << RAND_BITS) ^ random ();
+#if VALBITS > 4*RAND_BITS
+ val = (val << RAND_BITS) ^ random ();
+#endif /* need at least 5 */
+#endif /* need at least 4 */
+#endif /* need at least 3 */
+#endif /* need at least 2 */
+ return val & ((1L << VALBITS) - 1);
}
-
-srandom (arg)
- int arg;
-{
-#ifdef HAVE_LRAND48
- srand48 (arg);
-#else
- srand (arg);
-#endif
-}
-
-#endif /* no random */
-#endif /* not HAVE_RANDOM */
\f
#ifdef WRONG_NAME_INSQUE
sys_close (fd)
int fd;
{
+ int did_retry = 0;
register int rtnval;
while ((rtnval = close (fd)) == -1
- && (errno == EINTR));
+ && (errno == EINTR))
+ did_retry = 1;
+
+ /* If close is interrupted SunOS 4.1 may or may not have closed the
+ file descriptor. If it did the second close will fail with
+ errno = EBADF. That means we have succeeded. */
+ if (rtnval == -1 && did_retry && errno == EBADF)
+ return 0;
+
return rtnval;
}
* Substitute fork for vfork on USG flavors.
*/
+VFORK_RETURN_TYPE
vfork ()
{
return (fork ());
"LAN I/O interrupt", /* 25 SIGAIO */
"PTY I/O interrupt", /* 26 SIGPTY */
"I/O intervention required", /* 27 SIGIOINT */
+#ifdef AIXHFT
"HFT grant", /* 28 SIGGRANT */
"HFT retract", /* 29 SIGRETRACT */
"HFT sound done", /* 30 SIGSOUND */
"HFT input ready", /* 31 SIGMSG */
+#endif
#else /* not AIX */
"bogus signal", /* 0 */
"hangup", /* 1 SIGHUP */
dup2 (fd, 1);
dup2 (fd, 2);
}
- wait_for_termination (cpid);
- if (synch_process_death != 0 || synch_process_retcode != 0)
- return -1; /* /bin/rmdir failed */
+ execl ("/bin/rmdir", "rmdir", dpath, (char *) 0);
+ _exit (-1); /* Can't exec /bin/rmdir */
+
default: /* Parent process */
- while (cpid != wait (&status)); /* Wait for kid to finish */
+ wait_for_termination (cpid);
}
- if (WIFSIGNALED (status) || WEXITSTATUS (status) != 0)
+ if (synch_process_death != 0 || synch_process_retcode != 0)
{
errno = EIO; /* We don't know why, but */
- return -1; /* /bin/mkdir failed */
+ return -1; /* /bin/rmdir failed */
}
return 0;
}
#endif /* VMS */
\f
-#ifdef AIX
+#ifdef AIXHFT
/* Called from init_sys_modes. */
hft_init ()
hftctl (0, HFSKBD, &buf);
}
-#endif /* AIX */
+#endif /* AIXHFT */
#ifdef USE_DL_STUBS
}
#endif /* USE_DL_STUBS */
+\f
+#ifndef BSTRING
+
+#ifndef bzero
+
+void
+bzero (b, length)
+ register char *b;
+ register int length;
+{
+#ifdef VMS
+ short zero = 0;
+ long max_str = 65535;
+ while (length > max_str) {
+ (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
+ length -= max_str;
+ b += max_str;
+ }
+ max_str = length;
+ (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
+#else
+ while (length-- > 0)
+ *b++ = 0;
+#endif /* not VMS */
+}
+
+#endif /* no bzero */
+#endif /* BSTRING */
+
+#if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
+#undef bcopy
+
+/* Saying `void' requires a declaration, above, where bcopy is used
+ and that declaration causes pain for systems where bcopy is a macro. */
+bcopy (b1, b2, length)
+ register char *b1;
+ register char *b2;
+ register int length;
+{
+#ifdef VMS
+ long max_str = 65535;
+
+ while (length > max_str) {
+ (void) LIB$MOVC3 (&max_str, b1, b2);
+ length -= max_str;
+ b1 += max_str;
+ b2 += max_str;
+ }
+ max_str = length;
+ (void) LIB$MOVC3 (&length, b1, b2);
+#else
+ while (length-- > 0)
+ *b2++ = *b1++;
+#endif /* not VMS */
+}
+#endif /* (defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
+
+#ifndef BSTRING
+#ifndef bcmp
+int
+bcmp (b1, b2, length) /* This could be a macro! */
+ register char *b1;
+ register char *b2;
+ register int length;
+{
+#ifdef VMS
+ struct dsc$descriptor_s src1 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b1};
+ struct dsc$descriptor_s src2 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b2};
+
+ return STR$COMPARE (&src1, &src2);
+#else
+ while (length-- > 0)
+ if (*b1++ != *b2++)
+ return 1;
+
+ return 0;
+#endif /* not VMS */
+}
+#endif /* no bcmp */
+#endif /* not BSTRING */