/* Interfaces to system-dependent kernel and library entries.
- Copyright (C) 1985, 86,87,88,93,94,95, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1985, 86,87,88,93,94,95, 1999, 2000, 2001
+ Free Software Foundation, Inc.
This file is part of GNU Emacs.
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
-#include "config.h"
#include <signal.h>
#include <setjmp.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-
#include "lisp.h"
+/* Including stdlib.h isn't necessarily enough to get srandom
+ declared, e.g. without __USE_XOPEN_EXTENDED with glibc 2. */
+#ifdef HAVE_RANDOM
+#if 0 /* It turns out that defining _OSF_SOURCE in osf5-0.h gets
+ random prototyped as returning `int'. It looks to me as
+ though the best way to DTRT is to prefer the rand48 functions
+ (per libc.info). -- fx */
+extern long int random P_ ((void));
+#endif
+#if 0 /* Don't prototype srandom; it takes an unsigned argument on
+ some systems, and an unsigned long on others, like FreeBSD
+ 4.1. */
+extern void srandom P_ ((unsigned int));
+#endif
+#endif
+
#include "blockinput.h"
#undef NULL
-#ifdef macintosh
+#ifdef MAC_OS8
/* It is essential to include stdlib.h so that this file picks up
the correct definitions of rand, srand, and RAND_MAX.
Otherwise random numbers will not work correctly. */
/* Nonzero means delete a process right away if it exits (process.c). */
static int delete_exited_processes;
#endif
-#endif /* macintosh */
-
-#define min(x,y) ((x) > (y) ? (y) : (x))
+#endif /* MAC_OS8 */
#ifdef WINDOWSNT
#define read sys_read
#undef fwrite
#endif
-#ifdef TRY_AGAIN
-#ifndef HAVE_H_ERRNO
-extern int h_errno;
-#endif
-#endif /* TRY_AGAIN */
-
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_SPEED_T
#include <termios.h>
-extern speed_t ospeed;
#else
#if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
-extern short ospeed;
#else
-#if defined (HAVE_TERMIOS_H) && defined (LINUX)
+#if defined (HAVE_TERMIOS_H) && defined (GNU_LINUX)
#include <termios.h>
-/* HJL's version of libc is said to need this on the Alpha.
- On the other hand, DEC OSF1 on the Alpha needs ospeed to be a short. */
-extern speed_t ospeed;
-#else
-extern short ospeed;
#endif
#endif
#endif
+int emacs_ospeed;
+
/* The file descriptor for Emacs's input terminal.
Under Unix, this is normally zero except when using X;
under VMS, we place the input channel number here. */
init_baud_rate ()
{
if (noninteractive)
- ospeed = 0;
+ emacs_ospeed = 0;
else
{
#ifdef INIT_BAUD_RATE
INIT_BAUD_RATE ();
#else
#ifdef DOS_NT
- ospeed = 15;
+ emacs_ospeed = 15;
#else /* not DOS_NT */
#ifdef VMS
struct sensemode sg;
SYS$QIOW (0, input_fd, IO$_SENSEMODE, &sg, 0, 0,
&sg.class, 12, 0, 0, 0, 0 );
- ospeed = sg.xmit_baud;
+ emacs_ospeed = sg.xmit_baud;
#else /* not VMS */
#ifdef HAVE_TERMIOS
struct termios sg;
sg.c_cflag = B9600;
tcgetattr (input_fd, &sg);
- ospeed = cfgetospeed (&sg);
+ emacs_ospeed = cfgetospeed (&sg);
#if defined (USE_GETOBAUD) && defined (getobaud)
/* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
- if (ospeed == 0)
- ospeed = getobaud (sg.c_cflag);
+ if (emacs_ospeed == 0)
+ emacs_ospeed = getobaud (sg.c_cflag);
#endif
#else /* neither VMS nor TERMIOS */
#ifdef HAVE_TERMIO
#else
ioctl (input_fd, TCGETA, &sg);
#endif
- ospeed = sg.c_cflag & CBAUD;
+ emacs_ospeed = sg.c_cflag & CBAUD;
#else /* neither VMS nor TERMIOS nor TERMIO */
struct sgttyb sg;
sg.sg_ospeed = B9600;
if (ioctl (input_fd, TIOCGETP, &sg) < 0)
abort ();
- ospeed = sg.sg_ospeed;
+ emacs_ospeed = sg.sg_ospeed;
#endif /* not HAVE_TERMIO */
#endif /* not HAVE_TERMIOS */
#endif /* not VMS */
#endif /* not INIT_BAUD_RATE */
}
- baud_rate = (ospeed < sizeof baud_convert / sizeof baud_convert[0]
- ? baud_convert[ospeed] : 9600);
+ baud_rate = (emacs_ospeed < sizeof baud_convert / sizeof baud_convert[0]
+ ? baud_convert[emacs_ospeed] : 9600);
if (baud_rate == 0)
baud_rate = 1200;
}
break;
wait (0);
#else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
-#ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
+#ifdef POSIX_SIGNALS /* would this work for GNU/Linux as well? */
sigblock (sigmask (SIGCHLD));
- if (0 > kill (pid, 0))
+ errno = 0;
+ if (kill (pid, 0) == -1 && errno == ESRCH)
{
sigunblock (sigmask (SIGCHLD));
break;
}
- sigpause (SIGEMPTYMASK);
+
+ sigsuspend (&empty_mask);
#else /* not POSIX_SIGNALS */
#ifdef HAVE_SYSV_SIGPAUSE
sighold (SIGCHLD);
#endif
s.main.c_lflag &= ~ECHO; /* Disable echo */
s.main.c_lflag |= ISIG; /* Enable signals */
+#if 0 /* This causes bugs in (for instance) telnet to certain sites. */
+ s.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */
+#ifdef INLCR /* Just being cautious, since I can't check how
+ widespread INLCR is--rms. */
+ s.main.c_iflag &= ~INLCR; /* Disable map of NL to CR on input */
+#endif
+#endif
#ifdef IUCLC
s.main.c_iflag &= ~IUCLC; /* Disable downcasing on input. */
#endif
/* Fork a subshell. */
-#ifndef macintosh
+#ifndef MAC_OS8
void
sys_subshell ()
{
goto xyzzy;
dir = expand_and_dir_to_file (Funhandled_file_name_directory (dir), Qnil);
- str = (unsigned char *) alloca (XSTRING (dir)->size + 2);
- len = XSTRING (dir)->size;
- bcopy (XSTRING (dir)->data, str, len);
+ str = (unsigned char *) alloca (SCHARS (dir) + 2);
+ len = SCHARS (dir);
+ bcopy (SDATA (dir), str, len);
if (str[len - 1] != '/') str[len++] = '/';
str[len] = 0;
xyzzy:
#ifdef SET_EMACS_PRIORITY
{
- extern int emacs_priority;
+ extern EMACS_INT emacs_priority;
if (emacs_priority < 0)
nice (-emacs_priority);
#endif
#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
- st = system (sh);
- chdir (oldwd);
+ {
+ char *epwd = getenv ("PWD");
+ char old_pwd[MAXPATHLEN+1+4];
+
+ /* If PWD is set, pass it with corrected value. */
+ if (epwd)
+ {
+ strcpy (old_pwd, epwd);
+ if (str[len - 1] == '/')
+ str[len - 1] = '\0';
+ setenv ("PWD", str, 1);
+ }
+ st = system (sh);
+ chdir (oldwd);
+ if (epwd)
+ putenv (old_pwd); /* restore previous value */
+ }
#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));
synch_process_alive = 0;
#endif /* !VMS */
}
-#endif /* !macintosh */
+#endif /* !MAC_OS8 */
static void
save_signal_handlers (saved_handlers)
{
struct emacs_tty tty;
-#ifdef macintosh
+#ifdef MAC_OS8
/* cus-start.el complains if delete-exited-processes is not defined */
#ifndef subprocesses
DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes,
- "*Non-nil means delete processes immediately when they exit.\n\
-nil means don't delete them until `list-processes' is run.");
+ doc: /* *Non-nil means delete processes immediately when they exit.
+nil means don't delete them until `list-processes' is run. */);
delete_exited_processes = 0;
#endif
-#endif /* not macintosh */
+#endif /* MAC_OS8 */
#ifdef VMS
#if 0
if (c >= 0)
{
struct input_event e;
- e.kind = ascii_keystroke;
+ e.kind = ASCII_KEYSTROKE_EVENT;
XSETINT (e.code, c);
e.frame_or_window = selected_frame;
kbd_buffer_store_event (&e);
/* No timing error: wait for flag to be set. */
set_waiting_for_input (0);
SYS$WFLOR (input_ef, input_eflist);
- clear_waiting_for_input (0);
+ clear_waiting_for_input ();
if (!detect_input_pending ())
/* Check for subprocess input availability */
{
{
update_mode_lines++;
prepare_menu_bars ();
- redisplay_preserve_echo_area ();
+ redisplay_preserve_echo_area (18);
}
}
}
*
*/
+#ifndef start_of_data
char *
start_of_data ()
{
#endif /* ORDINARY_LINK */
#endif /* DATA_START */
}
+#endif /* start_of_data */
#endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
-
-#ifndef CANNOT_DUMP
-/* Some systems that cannot dump also cannot implement these. */
-
-/*
- * Return the address of the end of the text segment prior to
- * doing an unexec. After unexec the return value is undefined.
- */
-
-char *
-end_of_text ()
-{
-#ifdef TEXT_END
- return ((char *) TEXT_END);
-#else
- extern int etext;
- return ((char *) &etext);
-#endif
-}
-
-/*
- * Return the address of the end of the data segment prior to
- * doing an unexec. After unexec the return value is undefined.
- */
-
-char *
-end_of_data ()
-{
-#ifdef DATA_END
- return ((char *) DATA_END);
-#else
- extern int edata;
- return ((char *) &edata);
-#endif
-}
-
-#endif /* not CANNOT_DUMP */
\f
/* init_system_name sets up the string for the Lisp function
system-name to return. */
#endif /* not VMS */
#endif /* not BSD4_1 */
+#ifdef TRY_AGAIN
+#ifndef HAVE_H_ERRNO
+extern int h_errno;
+#endif
+#endif /* TRY_AGAIN */
+
void
init_system_name ()
{
if (hp)
{
char *fqdn = (char *) hp->h_name;
+#if 0
char *p;
+#endif
if (!index (fqdn, '.'))
{
#endif /* BSD4_1 */
{
unsigned char *p;
- for (p = XSTRING (Vsystem_name)->data; *p; p++)
+ for (p = SDATA (Vsystem_name); *p; p++)
if (*p == ' ' || *p == '\t')
*p = '-';
}
kbd_buffer_store_event (&buf[i]);
/* 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
+ if (buf[i].kind == ASCII_KEYSTROKE_EVENT
&& buf[i].code == quit_char)
break;
}
nread = read (fileno (stdin), buf, 1);
/* Scan the chars for C-g and store them in kbd_buffer. */
- e.kind = ascii_keystroke;
+ e.kind = ASCII_KEYSTROKE_EVENT;
e.frame_or_window = selected_frame;
e.modifiers = 0;
for (i = 0; i < nread; i++)
struct sigaction new_action, old_action;
sigemptyset (&new_action.sa_mask);
new_action.sa_handler = action;
-#ifdef SA_RESTART
+#if defined (SA_RESTART) && ! defined (BROKEN_SA_RESTART)
/* Emacs mostly works better with restartable system services. If this
- * flag exists, we probably want to turn it on here.
- */
+ flag exists, we probably want to turn it on here.
+ However, on some systems this resets the timeout of `select'
+ which means that `select' never finishes if it keeps getting signals.
+ BROKEN_SA_RESTART is defined on those systems. */
new_action.sa_flags = SA_RESTART;
#else
new_action.sa_flags = 0;
\f
int
emacs_open (path, oflag, mode)
- char *path;
+ const char *path;
int oflag, mode;
{
register int rtnval;
int
emacs_write (fildes, buf, nbyte)
int fildes;
- char *buf;
+ const char *buf;
unsigned int nbyte;
{
register int rtnval, bytes_written;
BLOCK_INPUT; /* getcwd uses malloc */
spath = npath = getcwd ((char *) 0, MAXPATHLEN);
if (spath == 0)
- return spath;
+ {
+ UNBLOCK_INPUT;
+ return spath;
+ }
/* On Altos 3068, getcwd can return @hostname/dir, so discard
up to first slash. Should be harmless on other systems. */
while (*npath && *npath != '/')
\f
int
set_file_times (filename, atime, mtime)
- char *filename;
+ const char *filename;
EMACS_TIME atime, mtime;
{
#ifdef HAVE_UTIMES