428
+ − 1 /* Interfaces to system-dependent kernel and library entries.
+ − 2 Copyright (C) 1985-1988, 1992-1995 Free Software Foundation, Inc.
+ − 3 Copyright (C) 1995 Tinker Systems.
2367
+ − 4 Copyright (C) 2000, 2001, 2002, 2003, 2004 Ben Wing.
428
+ − 5
+ − 6 This file is part of XEmacs.
+ − 7
+ − 8 XEmacs is free software; you can redistribute it and/or modify it
+ − 9 under the terms of the GNU General Public License as published by the
+ − 10 Free Software Foundation; either version 2, or (at your option) any
+ − 11 later version.
+ − 12
+ − 13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
+ − 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ − 15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ − 16 for more details.
+ − 17
+ − 18 You should have received a copy of the GNU General Public License
+ − 19 along with XEmacs; see the file COPYING. If not, write to
+ − 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ − 21 Boston, MA 02111-1307, USA. */
+ − 22
771
+ − 23
428
+ − 24 /* Synched up with: FSF 19.30 except for some Windows-NT crap. */
+ − 25
771
+ − 26 /* Authorship:
+ − 27
+ − 28 Current primary author: Various
+ − 29
+ − 30 Originally from FSF. Major changes at various times.
+ − 31 Substantially cleaned up by Ben Wing, Dec. 1994 / Jan. 1995.
+ − 32 SIGIO stuff ripped apart and redone by Ben Wing. (during 19.14 devel?)
+ − 33 Signal stuff totally redone by Ben Wing. (during 19.14 devel? that would
+ − 34 be Dec 1995 - Apr 1996.)
+ − 35 Controlling terminal stuff redone by Ben Wing for 19.13.
+ − 36 System call encapsulation stuff written by Ben Wing for 19.12. (1995)
+ − 37 Ripped up and redone avoiding preprocessor tricks Aug - Sep 2001 during
+ − 38 Mule-on-Windows development.
+ − 39 */
428
+ − 40
+ − 41 #include <config.h>
+ − 42 #include "lisp.h"
+ − 43
+ − 44 /* ------------------------------- */
+ − 45 /* basic includes */
+ − 46 /* ------------------------------- */
+ − 47
800
+ − 48
+ − 49 #include "buffer.h"
872
+ − 50 #include "device-impl.h"
800
+ − 51 #include "events.h"
+ − 52 #include "frame.h"
+ − 53 #include "process.h"
+ − 54 #include "redisplay.h"
+ − 55 #include "sysdep.h"
+ − 56 #include "window.h"
+ − 57
428
+ − 58 #ifdef HAVE_TTY
872
+ − 59 #include "console-tty-impl.h"
428
+ − 60 #else
+ − 61 #endif /* HAVE_TTY */
+ − 62
872
+ − 63 #include "console-stream-impl.h"
442
+ − 64 #ifdef WIN32_NATIVE
771
+ − 65 #include "syswindows.h"
428
+ − 66 #endif
+ − 67
800
+ − 68 #include "sysdir.h"
+ − 69 #include "sysfile.h"
+ − 70 #include "sysproc.h"
+ − 71 #include "syspwd.h"
859
+ − 72 #include "syssignal.h"
800
+ − 73 #include "systime.h"
+ − 74 #include "systty.h"
+ − 75 #include "syswait.h"
+ − 76
+ − 77 #include <setjmp.h>
+ − 78
+ − 79
428
+ − 80 /* ------------------------------- */
+ − 81 /* TTY definitions */
+ − 82 /* ------------------------------- */
+ − 83
+ − 84 #ifdef USG
+ − 85 #include <sys/utsname.h>
+ − 86 #if defined (TIOCGWINSZ) || defined (ISC4_0)
+ − 87 #ifdef NEED_SIOCTL
+ − 88 #include <sys/sioctl.h>
+ − 89 #endif
+ − 90 #ifdef NEED_PTEM_H
+ − 91 #include <sys/stream.h>
+ − 92 #include <sys/ptem.h>
+ − 93 #endif
+ − 94 #endif /* TIOCGWINSZ or ISC4_0 */
+ − 95 #endif /* USG */
+ − 96
+ − 97 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
+ − 98 #ifndef LPASS8
+ − 99 #define LPASS8 0
+ − 100 #endif
+ − 101
+ − 102 #ifndef HAVE_H_ERRNO
+ − 103 int h_errno;
+ − 104 #endif
+ − 105
+ − 106 #ifdef HAVE_TTY
+ − 107
+ − 108 static int baud_convert[] =
+ − 109 #ifdef BAUD_CONVERT
+ − 110 BAUD_CONVERT;
+ − 111 #else
+ − 112 {
+ − 113 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
+ − 114 1800, 2400, 4800, 9600, 19200, 38400
+ − 115 };
+ − 116 #endif
+ − 117
+ − 118 #endif
+ − 119
+ − 120 #ifdef AIXHFT
+ − 121 static void hft_init (struct console *c);
+ − 122 static void hft_reset (struct console *c);
+ − 123 #include <sys/termio.h>
+ − 124 #endif
+ − 125
2340
+ − 126 #ifdef HAVE_TTY
+ − 127 #define USED_IF_TTY(decl) decl
+ − 128 #else
+ − 129 #define USED_IF_TTY(decl) UNUSED (decl)
+ − 130 #endif
+ − 131
428
+ − 132
+ − 133 /************************************************************************/
+ − 134 /* subprocess control */
+ − 135 /************************************************************************/
+ − 136
853
+ − 137 #ifdef NEED_SYNC_PROCESS_CODE
+ − 138
+ − 139 /* True iff we are about to fork off a synchronous process or if we
+ − 140 are waiting for it. */
+ − 141 volatile int synch_process_alive;
+ − 142
+ − 143 /* Nonzero => this is a string explaining death of synchronous subprocess. */
+ − 144 const char *synch_process_death;
+ − 145
+ − 146 /* If synch_process_death is zero,
+ − 147 this is exit code of synchronous subprocess. */
+ − 148 int synch_process_retcode;
+ − 149
+ − 150 #endif /* NEED_SYNC_PROCESS_CODE */
+ − 151
428
+ − 152 #ifdef HAVE_TTY
+ − 153
+ − 154 #ifdef SIGTSTP
+ − 155
+ − 156 /* Arrange for character C to be read as the next input from
+ − 157 the terminal. */
+ − 158 void
2311
+ − 159 stuff_char (struct console *con,
+ − 160 #ifdef TIOCSTI
+ − 161 int c
+ − 162 #else
+ − 163 int UNUSED (c)
+ − 164 #endif
+ − 165 )
428
+ − 166 {
+ − 167 int input_fd;
+ − 168
+ − 169 assert (CONSOLE_TTY_P (con));
+ − 170 input_fd = CONSOLE_TTY_DATA (con)->infd;
+ − 171 /* Should perhaps error if in batch mode */
+ − 172 #ifdef TIOCSTI
+ − 173 ioctl (input_fd, TIOCSTI, &c);
+ − 174 #else /* no TIOCSTI */
563
+ − 175 invalid_operation ("Cannot stuff terminal input characters in this version of Unix.", Qunbound);
428
+ − 176 #endif /* no TIOCSTI */
+ − 177 }
+ − 178
+ − 179 #endif /* SIGTSTP */
+ − 180
+ − 181 #endif /* HAVE_TTY */
+ − 182
+ − 183 void
2311
+ − 184 set_exclusive_use (
+ − 185 #ifdef FIOCLEX
+ − 186 int fd
+ − 187 #else
+ − 188 int UNUSED (fd)
+ − 189 #endif
+ − 190 )
428
+ − 191 {
+ − 192 #ifdef FIOCLEX
+ − 193 ioctl (fd, FIOCLEX, 0);
+ − 194 #endif
+ − 195 /* Ok to do nothing if this feature does not exist */
+ − 196 }
+ − 197
+ − 198 void
2340
+ − 199 set_descriptor_non_blocking (
+ − 200 #if defined (STRIDE) || (defined (pfa) && defined (HAVE_PTYS)) || defined (AIX) || defined (F_SETFL)
+ − 201 int fd
+ − 202 #else
+ − 203 int UNUSED (fd)
+ − 204 #endif
+ − 205 )
428
+ − 206 {
+ − 207 /* Stride people say it's a mystery why this is needed
+ − 208 as well as the O_NDELAY, but that it fails without this. */
+ − 209 /* For AIX: Apparently need this for non-blocking reads on sockets.
+ − 210 It seems that O_NONBLOCK applies only to FIFOs? From
+ − 211 lowry@watson.ibm.com (Andy Lowry). */
+ − 212 /* #### Should this be conditionalized on FIONBIO? */
872
+ − 213 #if defined (STRIDE) || (defined (pfa) && defined (HAVE_PTYS)) || defined (AIX)
428
+ − 214 {
+ − 215 int one = 1;
+ − 216 ioctl (fd, FIONBIO, &one);
+ − 217 }
+ − 218 #endif
+ − 219
+ − 220 #ifdef F_SETFL
+ − 221 fcntl (fd, F_SETFL, O_NONBLOCK);
+ − 222 #endif
+ − 223 }
+ − 224
853
+ − 225 #ifdef NEED_SYNC_PROCESS_CODE /* #### Used only on super-ancient systems */
+ − 226
+ − 227 static void
814
+ − 228 wait_for_termination (int pid)
428
+ − 229 {
+ − 230 /* #### With the new improved SIGCHLD handling stuff, there is much
+ − 231 less danger of race conditions and some of the comments below
+ − 232 don't apply. This should be updated. */
+ − 233
+ − 234 #if defined (NO_SUBPROCESSES)
+ − 235 while (1)
+ − 236 {
+ − 237 /* No need to be tricky like below; we can just call wait(). */
+ − 238 /* #### should figure out how to write a wait_allowing_quit().
+ − 239 Since hardly any systems don't have subprocess support,
+ − 240 however, there doesn't seem to be much point. */
+ − 241 if (wait (0) == pid)
+ − 242 return;
+ − 243 }
+ − 244 #elif defined (HAVE_WAITPID)
+ − 245 /* Note that, whenever any subprocess terminates (asynch. or synch.),
+ − 246 the SIGCHLD handler will be called and it will call wait(). Thus
+ − 247 we cannot just call wait() ourselves, and we can't block SIGCHLD
+ − 248 and then call wait(), because then if an asynch. process dies
+ − 249 while we're waiting for our synch. process, Emacs will never
+ − 250 notice that the asynch. process died.
+ − 251
+ − 252 So, the general approach we take is to repeatedly block until a
+ − 253 signal arrives, and then check if our process died using kill
+ − 254 (pid, 0). (We could also check the value of `synch_process_alive',
+ − 255 since the SIGCHLD handler will reset that and we know that we're
+ − 256 only being called on synchronous processes, but this approach is
+ − 257 safer. I don't trust the proper delivery of SIGCHLD.
+ − 258
+ − 259 Note also that we cannot use any form of waitpid(). A loop with
+ − 260 WNOHANG will chew up CPU time; better to use sleep(). A loop
+ − 261 without WNOWAIT will screw up the SIGCHLD handler (actually this
+ − 262 is not true, if you duplicate the exit-status-reaping code; see
+ − 263 below). A loop with WNOWAIT will result in a race condition if
+ − 264 the process terminates between the process-status check and the
+ − 265 call to waitpid(). */
+ − 266
+ − 267 /* Formerly, immediate_quit was set around this function call, but
+ − 268 that could lead to problems if the QUIT happened when SIGCHLD was
+ − 269 blocked -- it would remain blocked. Yet another reason why
+ − 270 immediate_quit is a bad idea. In any case, there is no reason to
+ − 271 resort to this because either the SIGIO or the SIGALRM will stop
+ − 272 the block in EMACS_WAIT_FOR_SIGNAL(). */
+ − 273
+ − 274 /* Apparently there are bugs on some systems with the second method
+ − 275 used below (the EMACS_BLOCK_SIGNAL method), whereby zombie
+ − 276 processes get left around. It appears in those cases that the
+ − 277 SIGCHLD handler is never getting invoked. It's not clear whether
+ − 278 this is an Emacs bug or a kernel bug or both: on HPUX this
+ − 279 problem is observed only with XEmacs, but under Solaris 2.4 all
+ − 280 sorts of different programs have problems with zombies. The
+ − 281 method we use here does not require a working SIGCHLD (but will
+ − 282 not break if it is working), and should be safe. */
+ − 283 /*
+ − 284 We use waitpid(), contrary to the remarks above. There is no
+ − 285 race condition, because the three situations when sigchld_handler
+ − 286 is invoked should be handled OK:
+ − 287
+ − 288 - handler invoked before waitpid(): In this case, subprocess
+ − 289 status will be set by sigchld_handler. waitpid() here will
+ − 290 return -1 with errno set to ECHILD, which is a valid exit
+ − 291 condition.
+ − 292
+ − 293 - handler invoked during waitpid(): as above, except that errno
+ − 294 here will be set to EINTR. This will cause waitpid() to be
+ − 295 called again, and this time it will exit with ECHILD.
+ − 296
+ − 297 - handler invoked after waitpid(): The following code will reap
+ − 298 the subprocess. In the handler, wait() will return -1 because
+ − 299 there is no child to reap, and the handler will exit without
+ − 300 modifying child subprocess status. */
+ − 301 int ret, status;
+ − 302
+ − 303 /* Because the SIGCHLD handler can potentially reap the synchronous
+ − 304 subprocess, we should take care of that. */
+ − 305
+ − 306 /* Will stay in the do loop as long as:
+ − 307 1. Process is alive
+ − 308 2. Ctrl-G is not pressed */
+ − 309 do
+ − 310 {
+ − 311 QUIT;
+ − 312 ret = waitpid (pid, &status, 0);
+ − 313 /* waitpid returns 0 if the process is still alive. */
+ − 314 }
+ − 315 while (ret == 0 || (ret == -1 && errno == EINTR));
+ − 316
+ − 317 if (ret == pid) /* Success */
+ − 318 /* Set synch process globals. This is can also happen
+ − 319 in sigchld_handler, and that code is duplicated. */
+ − 320 {
+ − 321 synch_process_alive = 0;
+ − 322 if (WIFEXITED (status))
+ − 323 synch_process_retcode = WEXITSTATUS (status);
+ − 324 else if (WIFSIGNALED (status))
+ − 325 synch_process_death = signal_name (WTERMSIG (status));
+ − 326 }
+ − 327 /* On exiting the loop, ret will be -1, with errno set to ECHILD if
+ − 328 the child has already been reaped, e.g. in the signal handler. */
+ − 329
+ − 330 /* Otherwise, we've had some error condition here.
+ − 331 Per POSIX, the only other possibilities are:
+ − 332 - EFAULT (bus error accessing arg 2) or
+ − 333 - EINVAL (incorrect arguments),
+ − 334 which are both program bugs.
+ − 335
+ − 336 Since implementations may add their own error indicators on top,
+ − 337 we ignore it by default. */
+ − 338 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD)
+ − 339 while (1)
+ − 340 {
+ − 341 static int wait_debugging = 0; /* Set nonzero to make following
+ − 342 function work under dbx (at least for bsd). */
+ − 343 QUIT;
+ − 344 if (wait_debugging)
+ − 345 return;
+ − 346
+ − 347 EMACS_BLOCK_SIGNAL (SIGCHLD);
+ − 348 /* Block SIGCHLD from happening during this check,
+ − 349 to avoid race conditions. */
+ − 350 if (kill (pid, 0) < 0)
+ − 351 {
+ − 352 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
+ − 353 return;
+ − 354 }
+ − 355 else
+ − 356 /* WARNING: Whatever this macro does *must* not allow SIGCHLD
+ − 357 to happen between the time that it's reenabled and when we
+ − 358 begin to block. Otherwise we may end up blocking for a
+ − 359 signal that has already arrived and isn't coming again.
+ − 360 Can you say "race condition"?
+ − 361
+ − 362 I assume that the system calls sigpause() or sigsuspend()
+ − 363 to provide this atomicness. If you're getting hangs in
+ − 364 sigpause()/sigsuspend(), then your OS doesn't implement
+ − 365 this properly (this applies under hpux9, for example).
+ − 366 Try defining BROKEN_WAIT_FOR_SIGNAL. */
+ − 367 EMACS_WAIT_FOR_SIGNAL (SIGCHLD);
+ − 368 }
853
+ − 369 #else /* not HAVE_WAITPID and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */
428
+ − 370 /* This approach is kind of cheesy but is guaranteed(?!) to work
+ − 371 for all systems. */
+ − 372 while (1)
+ − 373 {
+ − 374 QUIT;
+ − 375 if (kill (pid, 0) < 0)
+ − 376 return;
771
+ − 377 stop_interrupts ();
+ − 378 sleep (1);
+ − 379 start_interrupts ();
428
+ − 380 }
+ − 381 #endif /* OS features */
+ − 382 }
+ − 383
853
+ − 384 #endif /* NEED_SYNC_PROCESS_CODE */
428
+ − 385
+ − 386 #if !defined (NO_SUBPROCESSES)
+ − 387
+ − 388 /*
+ − 389 * flush any pending output
+ − 390 * (may flush input as well; it does not matter the way we use it)
+ − 391 */
+ − 392
+ − 393 void
2286
+ − 394 flush_pending_output (
+ − 395 #if !defined (HAVE_TERMIOS) && (defined (TCFLSH) || defined (TIOCFLUSH))
+ − 396 int channel
+ − 397 #else
+ − 398 int UNUSED (channel)
+ − 399 #endif
+ − 400 )
428
+ − 401 {
+ − 402 #ifdef HAVE_TERMIOS
+ − 403 /* If we try this, we get hit with SIGTTIN, because
+ − 404 the child's tty belongs to the child's pgrp. */
+ − 405 #elif defined (TCFLSH)
+ − 406 ioctl (channel, TCFLSH, 1);
+ − 407 #elif defined (TIOCFLUSH)
+ − 408 int zero = 0;
+ − 409 /* 3rd arg should be ignored
+ − 410 but some 4.2 kernels actually want the address of an int
+ − 411 and nonzero means something different. */
+ − 412 ioctl (channel, TIOCFLUSH, &zero);
+ − 413 #endif
+ − 414 }
+ − 415
442
+ − 416 #ifndef WIN32_NATIVE
428
+ − 417 /* Set up the terminal at the other end of a pseudo-terminal that
+ − 418 we will be controlling an inferior through.
+ − 419 It should not echo or do line-editing, since that is done
+ − 420 in Emacs. No padding needed for insertion into an Emacs buffer. */
+ − 421
+ − 422 void
+ − 423 child_setup_tty (int out)
+ − 424 {
+ − 425 struct emacs_tty s;
430
+ − 426 emacs_get_tty (out, &s);
428
+ − 427
+ − 428 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
+ − 429 assert (isatty(out));
+ − 430 s.main.c_oflag |= OPOST; /* Enable output postprocessing */
+ − 431 s.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL on output */
513
+ − 432
+ − 433 {
+ − 434 /* Disable all output delays. */
+ − 435 tcflag_t delay_mask = 0;
428
+ − 436 #ifdef NLDLY
513
+ − 437 delay_mask |= NLDLY;
+ − 438 #endif
+ − 439 #ifdef CRDLY
+ − 440 delay_mask |= CRDLY;
+ − 441 #endif
+ − 442 #ifdef TABDLY
+ − 443 delay_mask |= TABDLY; /* Also disables tab expansion (Posix). */
+ − 444 #endif
+ − 445 #ifdef BSDLY
+ − 446 delay_mask |= BSDLY;
+ − 447 #endif
+ − 448 #ifdef VTDLY
+ − 449 delay_mask |= VTDLY;
428
+ − 450 #endif
513
+ − 451 #ifdef FFDLY
+ − 452 delay_mask |= FFDLY;
+ − 453 #endif
+ − 454 s.main.c_oflag &= ~delay_mask;
+ − 455 }
+ − 456
+ − 457 #ifdef OXTABS
+ − 458 /* Posix defines the TAB3 value for TABDLY to mean: expand tabs to spaces.
+ − 459 On those systems tab expansion would be disabled by the above code.
+ − 460 BSD systems use an independent flag, OXTABS. */
+ − 461 s.main.c_oflag &= ~OXTABS; /* Disable tab expansion */
+ − 462 #endif
+ − 463
428
+ − 464 s.main.c_lflag &= ~ECHO; /* Disable echo */
+ − 465 s.main.c_lflag |= ISIG; /* Enable signals */
+ − 466 #ifdef IUCLC
+ − 467 s.main.c_iflag &= ~IUCLC; /* Disable downcasing on input. */
+ − 468 #endif
+ − 469 #ifdef OLCUC
+ − 470 s.main.c_oflag &= ~OLCUC; /* Disable upcasing on output. */
+ − 471 #endif
513
+ − 472
428
+ − 473 #if defined (CSIZE) && defined (CS8)
+ − 474 s.main.c_cflag = (s.main.c_cflag & ~CSIZE) | CS8; /* Don't strip 8th bit */
+ − 475 #endif
+ − 476 #ifdef ISTRIP
+ − 477 s.main.c_iflag &= ~ISTRIP; /* Don't strip 8th bit on input */
+ − 478 #endif
+ − 479 #if 0
+ − 480 /* Unnecessary as long as ICANON is set */
+ − 481 s.main.c_cc[VMIN] = 1; /* minimum number of characters to accept */
+ − 482 s.main.c_cc[VTIME] = 0; /* wait forever for at least 1 character */
+ − 483 #endif /* 0 */
+ − 484
+ − 485 s.main.c_lflag |= ICANON; /* Enable erase/kill and eof processing */
+ − 486 s.main.c_cc[VEOF] = 04; /* ensure that EOF is Control-D */
+ − 487 s.main.c_cc[VERASE] = _POSIX_VDISABLE; /* disable erase processing */
+ − 488 s.main.c_cc[VKILL] = _POSIX_VDISABLE; /* disable kill processing */
+ − 489
+ − 490 #ifdef HPUX
+ − 491 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
+ − 492 #endif /* HPUX */
+ − 493
+ − 494 #ifdef AIX
+ − 495 #ifndef IBMR2AIX
+ − 496 /* AIX enhanced edit loses NULs, so disable it. */
+ − 497 s.main.c_line = 0;
+ − 498 s.main.c_iflag &= ~ASCEDIT;
+ − 499 #endif /* IBMR2AIX */
+ − 500 /* Also, PTY overloads NUL and BREAK.
+ − 501 don't ignore break, but don't signal either, so it looks like NUL.
+ − 502 This really serves a purpose only if running in an XTERM window
+ − 503 or via TELNET or the like, but does no harm elsewhere. */
+ − 504 s.main.c_iflag &= ~IGNBRK;
+ − 505 s.main.c_iflag &= ~BRKINT;
+ − 506 #endif /* AIX */
+ − 507 #ifdef SIGNALS_VIA_CHARACTERS
+ − 508 /* TTY `special characters' are used in process_send_signal
+ − 509 so set them here to something useful. */
+ − 510 s.main.c_cc[VQUIT] = '\\'&037; /* Control-\ */
+ − 511 s.main.c_cc[VINTR] = 'C' &037; /* Control-C */
+ − 512 s.main.c_cc[VSUSP] = 'Z' &037; /* Control-Z */
+ − 513 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
+ − 514 /* TTY `special characters' work better as signals, so disable
+ − 515 character forms */
+ − 516 s.main.c_cc[VQUIT] = _POSIX_VDISABLE;
+ − 517 s.main.c_cc[VINTR] = _POSIX_VDISABLE;
+ − 518 s.main.c_cc[VSUSP] = _POSIX_VDISABLE;
+ − 519 s.main.c_lflag &= ~ISIG;
+ − 520 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
+ − 521 s.main.c_cc[VEOL] = _POSIX_VDISABLE;
+ − 522 #if defined (CBAUD)
440
+ − 523 /* <mdiers> #### This is not portable. ###
428
+ − 524 POSIX does not specify CBAUD, and 4.4BSD does not have it.
+ − 525 Instead, POSIX suggests to use cfset{i,o}speed().
+ − 526 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal
+ − 527 I/O, O'Reilly 1991] */
+ − 528 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
+ − 529 #else
+ − 530 /* <mdiers> What to do upon failure? Just ignoring rc is probably
+ − 531 not acceptable, is it? */
+ − 532 if (cfsetispeed (&s.main, B9600) == -1) /* ignore */;
+ − 533 if (cfsetospeed (&s.main, B9600) == -1) /* ignore */;
+ − 534 #endif /* defined (CBAUD) */
+ − 535
+ − 536 #else /* not HAVE_TERMIO */
+ − 537
+ − 538 s.main.sg_flags &= ~(ECHO | CRMOD | ANYP | ALLDELAY | RAW | LCASE
+ − 539 | CBREAK | TANDEM);
+ − 540 s.main.sg_flags |= LPASS8;
+ − 541 s.main.sg_erase = 0377;
+ − 542 s.main.sg_kill = 0377;
+ − 543 s.lmode = LLITOUT | s.lmode; /* Don't strip 8th bit */
+ − 544
+ − 545 #endif /* not HAVE_TERMIO */
430
+ − 546 emacs_set_tty (out, &s, 0);
428
+ − 547
+ − 548 #ifdef RTU
+ − 549 {
+ − 550 int zero = 0;
+ − 551 ioctl (out, FIOASYNC, &zero);
+ − 552 }
+ − 553 #endif /* RTU */
+ − 554 }
442
+ − 555 #endif /* WIN32_NATIVE */
428
+ − 556
+ − 557 #endif /* not NO_SUBPROCESSES */
+ − 558
+ − 559
+ − 560 #if !defined (SIGTSTP) && !defined (USG_JOBCTRL)
+ − 561
+ − 562 #define SIG_PARAM_TYPE int
+ − 563
+ − 564 /* Record a signal code and the handler for it. */
+ − 565 struct save_signal
+ − 566 {
+ − 567 int code;
872
+ − 568 RETSIGTYPE (XCDECL * handler) (SIG_PARAM_TYPE);
428
+ − 569 };
+ − 570
+ − 571 static void
+ − 572 save_signal_handlers (struct save_signal *saved_handlers)
+ − 573 {
+ − 574 while (saved_handlers->code)
+ − 575 {
+ − 576 saved_handlers->handler
872
+ − 577 = (RETSIGTYPE (XCDECL *) (SIG_PARAM_TYPE)) EMACS_SIGNAL (saved_handlers->code, SIG_IGN);
428
+ − 578 saved_handlers++;
+ − 579 }
+ − 580 }
+ − 581
+ − 582 static void
+ − 583 restore_signal_handlers (struct save_signal *saved_handlers)
+ − 584 {
+ − 585 while (saved_handlers->code)
+ − 586 {
613
+ − 587 EMACS_SIGNAL (saved_handlers->code, saved_handlers->handler);
428
+ − 588 saved_handlers++;
+ − 589 }
+ − 590 }
+ − 591
+ − 592
+ − 593 /* Fork a subshell. */
+ − 594 static void
+ − 595 sys_subshell (void)
+ − 596 {
+ − 597 Lisp_Object dir;
867
+ − 598 Ibyte *str = 0;
771
+ − 599 Bytecount len;
428
+ − 600 struct gcpro gcpro1;
867
+ − 601 Ibyte *sh = 0;
771
+ − 602 Extbyte *shext;
+ − 603
+ − 604 /* Use our buffer's default directory for the subshell. */
+ − 605
+ − 606 /* Note: These calls are spread out to insure that the return values
+ − 607 of the calls (which may be newly-created strings) are properly
+ − 608 GC-protected. */
854
+ − 609
428
+ − 610 GCPRO1 (dir);
771
+ − 611
+ − 612 dir = current_buffer->directory;
+ − 613 /* If the current dir has no terminating slash, we'll get undesirable
+ − 614 results, so put the slash back. */
+ − 615 dir = Ffile_name_as_directory (dir);
428
+ − 616 dir = Funhandled_file_name_directory (dir);
+ − 617 dir = expand_and_dir_to_file (dir, Qnil);
771
+ − 618
2367
+ − 619 str = alloca_ibytes (XSTRING_LENGTH (dir) + 2);
428
+ − 620 len = XSTRING_LENGTH (dir);
+ − 621 memcpy (str, XSTRING_DATA (dir), len);
442
+ − 622 if (!IS_ANY_SEP (str[len - 1]))
+ − 623 str[len++] = DIRECTORY_SEP;
428
+ − 624 str[len] = 0;
771
+ − 625
+ − 626 if (sh == 0)
+ − 627 sh = egetenv ("SHELL");
+ − 628 if (sh == 0)
1204
+ − 629 sh = (Ibyte *) "sh";
771
+ − 630
+ − 631 C_STRING_TO_EXTERNAL (sh, shext, Qfile_name);
+ − 632
+ − 633 UNGCPRO;
428
+ − 634
442
+ − 635 #ifdef WIN32_NATIVE
+ − 636
771
+ − 637 if (str)
+ − 638 qxe_chdir (str);
+ − 639
+ − 640 /* Waits for process completion */
+ − 641 if (_spawnlp (_P_WAIT, shext, shext, NULL) != 0)
+ − 642 report_process_error ("Can't spawn subshell", Qunbound);
+ − 643 else
+ − 644 return; /* we're done, no need to wait for termination */
+ − 645
+ − 646 #else /* not WIN32_NATIVE */
+ − 647
+ − 648 {
+ − 649 int pid;
+ − 650 struct save_signal saved_handlers[5];
+ − 651
+ − 652 saved_handlers[0].code = SIGINT;
+ − 653 saved_handlers[1].code = SIGQUIT;
+ − 654 saved_handlers[2].code = SIGTERM;
+ − 655 #ifdef SIGIO
+ − 656 saved_handlers[3].code = SIGIO;
+ − 657 saved_handlers[4].code = 0;
+ − 658 #else
+ − 659 saved_handlers[3].code = 0;
+ − 660 #endif
+ − 661
+ − 662 pid = fork ();
+ − 663
+ − 664 if (pid == -1)
563
+ − 665 report_process_error ("Can't spawn subshell", Qunbound);
771
+ − 666 if (pid == 0)
+ − 667 {
+ − 668 if (str)
+ − 669 qxe_chdir (str);
442
+ − 670
+ − 671 #if !defined (NO_SUBPROCESSES)
771
+ − 672 close_process_descs (); /* Close Emacs's pipes/ptys */
428
+ − 673 #endif
+ − 674
+ − 675 #ifdef SET_EMACS_PRIORITY
771
+ − 676 if (emacs_priority != 0)
+ − 677 nice (-emacs_priority); /* Give the new shell the default priority */
428
+ − 678 #endif
+ − 679
771
+ − 680 execlp (shext, shext, 0);
+ − 681 retry_write (1, "Can't execute subshell", 22);
+ − 682 _exit (1);
+ − 683 }
+ − 684
+ − 685 save_signal_handlers (saved_handlers);
+ − 686 synch_process_alive = 1;
+ − 687 wait_for_termination (pid);
+ − 688 restore_signal_handlers (saved_handlers);
428
+ − 689 }
+ − 690
442
+ − 691 #endif /* not WIN32_NATIVE */
428
+ − 692 }
+ − 693
+ − 694 #endif /* !defined (SIGTSTP) && !defined (USG_JOBCTRL) */
+ − 695
+ − 696
+ − 697
+ − 698 /* Suspend the Emacs process; give terminal to its superior. */
+ − 699 void
+ − 700 sys_suspend (void)
+ − 701 {
+ − 702 #if defined (SIGTSTP)
+ − 703 {
+ − 704 int pgrp = EMACS_GET_PROCESS_GROUP ();
+ − 705 EMACS_KILLPG (pgrp, SIGTSTP);
+ − 706 }
+ − 707
+ − 708 #elif defined (USG_JOBCTRL)
+ − 709 /* If you don't know what this is don't mess with it */
+ − 710 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
+ − 711 kill (getpid (), SIGQUIT);
+ − 712
+ − 713 #else /* No SIGTSTP or USG_JOBCTRL */
+ − 714
+ − 715 /* On a system where suspending is not implemented,
+ − 716 instead fork a subshell and let it talk directly to the terminal
+ − 717 while we wait. */
+ − 718 sys_subshell ();
+ − 719
+ − 720 #endif
+ − 721 }
+ − 722
+ − 723 /* Suspend a process if possible; give terminal to its superior. */
+ − 724 void
2340
+ − 725 sys_suspend_process (
+ − 726 #ifdef SIGTSTP
+ − 727 int process
+ − 728 #else
+ − 729 int UNUSED (process)
+ − 730 #endif
+ − 731 )
428
+ − 732 {
+ − 733 /* I don't doubt that it is possible to suspend processes on
+ − 734 * VMS machines or thost that use USG_JOBCTRL,
+ − 735 * but I don't know how to do it, so...
+ − 736 */
+ − 737 #if defined (SIGTSTP)
+ − 738 kill(process, SIGTSTP);
+ − 739 #endif
+ − 740 }
+ − 741
+ − 742
+ − 743 /* Given FD, obtain pty buffer size. When no luck, a good guess is made,
442
+ − 744 so that the function works even when fd is not a pty. */
428
+ − 745
+ − 746 int
2340
+ − 747 get_pty_max_bytes (
+ − 748 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
+ − 749 int fd
+ − 750 #else
+ − 751 int UNUSED (fd)
+ − 752 #endif
+ − 753 )
428
+ − 754 {
442
+ − 755 /* DEC OSF 4.0 fpathconf returns 255, but xemacs hangs on long shell
+ − 756 input lines if we return 253. 252 is OK!. So let's leave a bit
+ − 757 of slack for the newline that xemacs will insert, and for those
+ − 758 inevitable vendor off-by-one-or-two-or-three bugs. */
+ − 759 #define MAX_CANON_SLACK 10
+ − 760 #define SAFE_MAX_CANON (127 - MAX_CANON_SLACK)
428
+ − 761 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
442
+ − 762 {
+ − 763 int max_canon = fpathconf (fd, _PC_MAX_CANON);
+ − 764 #ifdef __hpux__
+ − 765 /* HP-UX 10.20 fpathconf returns 768, but this results in
+ − 766 truncated input lines, while 255 works. */
+ − 767 if (max_canon > 255) max_canon = 255;
428
+ − 768 #endif
442
+ − 769 return (max_canon < 0 ? SAFE_MAX_CANON :
+ − 770 max_canon > SAFE_MAX_CANON ? max_canon - MAX_CANON_SLACK :
+ − 771 max_canon);
+ − 772 }
+ − 773 #elif defined (_POSIX_MAX_CANON)
+ − 774 return (_POSIX_MAX_CANON > SAFE_MAX_CANON ?
+ − 775 _POSIX_MAX_CANON - MAX_CANON_SLACK :
+ − 776 _POSIX_MAX_CANON);
+ − 777 #else
+ − 778 return SAFE_MAX_CANON;
+ − 779 #endif
428
+ − 780 }
+ − 781
+ − 782 /* Figure out the eof character for the FD. */
+ − 783
867
+ − 784 Ibyte
428
+ − 785 get_eof_char (int fd)
+ − 786 {
867
+ − 787 const Ibyte ctrl_d = (Ibyte) '\004';
428
+ − 788
+ − 789 if (!isatty (fd))
+ − 790 return ctrl_d;
+ − 791 #ifdef HAVE_TERMIOS
+ − 792 {
+ − 793 struct termios t;
+ − 794 tcgetattr (fd, &t);
+ − 795 #if 0
+ − 796 /* What is the following line designed to do??? -mrb */
647
+ − 797 if ((int) strlen ((const char *) t.c_cc) < (VEOF + 1))
428
+ − 798 return ctrl_d;
+ − 799 else
867
+ − 800 return (Ibyte) t.c_cc[VEOF];
428
+ − 801 #endif
867
+ − 802 return t.c_cc[VEOF] == _POSIX_VDISABLE ? ctrl_d : (Ibyte) t.c_cc[VEOF];
428
+ − 803 }
+ − 804 #else /* ! HAVE_TERMIOS */
+ − 805 /* On Berkeley descendants, the following IOCTL's retrieve the
+ − 806 current control characters. */
+ − 807 #if defined (TIOCGETC)
+ − 808 {
+ − 809 struct tchars c;
+ − 810 ioctl (fd, TIOCGETC, &c);
867
+ − 811 return (Ibyte) c.t_eofc;
428
+ − 812 }
+ − 813 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
+ − 814 /* On SYSV descendants, the TCGETA ioctl retrieves the current control
+ − 815 characters. */
+ − 816 #ifdef TCGETA
+ − 817 {
+ − 818 struct termio t;
+ − 819 ioctl (fd, TCGETA, &t);
647
+ − 820 if ((int) strlen ((const char *) t.c_cc) < (VINTR + 1))
428
+ − 821 return ctrl_d;
+ − 822 else
867
+ − 823 return (Ibyte) t.c_cc[VINTR];
428
+ − 824 }
+ − 825 #else /* ! defined (TCGETA) */
+ − 826 /* Rather than complain, we'll just guess ^D, which is what
+ − 827 * earlier emacsen always used. */
+ − 828 return ctrl_d;
+ − 829 #endif /* ! defined (TCGETA) */
+ − 830 #endif /* ! defined (TIOCGETC) */
+ − 831 #endif /* ! defined (HAVE_TERMIOS) */
+ − 832 }
+ − 833
+ − 834 /* Set the logical window size associated with descriptor FD
+ − 835 to HEIGHT and WIDTH. This is used mainly with ptys. */
+ − 836
+ − 837 int
2340
+ − 838 set_window_size (
+ − 839 #if defined (TIOCSWINSZ) || defined (TIOCSSIZE)
+ − 840 int fd, int height, int width
+ − 841 #else
+ − 842 int UNUSED (fd), int UNUSED (height), int UNUSED (width)
+ − 843 #endif
+ − 844 )
428
+ − 845 {
+ − 846 #ifdef TIOCSWINSZ
+ − 847
+ − 848 /* BSD-style. */
+ − 849 struct winsize size;
+ − 850 size.ws_row = height;
+ − 851 size.ws_col = width;
+ − 852
+ − 853 if (ioctl (fd, TIOCSWINSZ, &size) == -1)
+ − 854 return 0; /* error */
+ − 855 else
+ − 856 return 1;
+ − 857
+ − 858 #elif defined (TIOCSSIZE)
+ − 859
+ − 860 /* SunOS - style. */
+ − 861 struct ttysize size;
+ − 862 size.ts_lines = height;
+ − 863 size.ts_cols = width;
+ − 864
+ − 865 if (ioctl (fd, TIOCGSIZE, &size) == -1)
+ − 866 return 0;
+ − 867 else
+ − 868 return 1;
+ − 869 #else
+ − 870 return -1;
+ − 871 #endif
+ − 872 }
+ − 873
+ − 874 /* Set up the proper status flags for use of a pty. */
+ − 875
+ − 876 void
2340
+ − 877 setup_pty (
+ − 878 #ifdef TIOCPKT
+ − 879 int fd
+ − 880 #else
+ − 881 int UNUSED (fd)
+ − 882 #endif
+ − 883 )
428
+ − 884 {
+ − 885 #ifdef IBMRTAIX
+ − 886 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
+ − 887 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
+ − 888 /* cause EMACS not to die when it should, i.e., when its own controlling */
+ − 889 /* tty goes away. I've complained to the AIX developers, and they may */
+ − 890 /* change this behavior, but I'm not going to hold my breath. */
613
+ − 891 EMACS_SIGNAL (SIGHUP, SIG_IGN);
535
+ − 892 #endif /* IBMRTAIX */
+ − 893
428
+ − 894 #ifdef TIOCPKT
+ − 895 /* In some systems (Linux through 2.0.0, at least), packet mode doesn't
+ − 896 get cleared when a pty is closed, so we need to clear it here.
+ − 897 Linux pre2.0.13 contained an attempted fix for this (from Ted Ts'o,
+ − 898 tytso@mit.edu), but apparently it messed up rlogind and telnetd, so he
+ − 899 removed the fix in pre2.0.14. - dkindred@cs.cmu.edu
+ − 900 */
+ − 901 {
+ − 902 int off = 0;
+ − 903 ioctl (fd, TIOCPKT, (char *)&off);
+ − 904 }
535
+ − 905 #endif /* TIOCPKT */
428
+ − 906 }
+ − 907
+ − 908
+ − 909 /************************************************************************/
+ − 910 /* TTY control */
+ − 911 /************************************************************************/
+ − 912
+ − 913 /* ------------------------------------------------------ */
+ − 914 /* get baud rate */
+ − 915 /* ------------------------------------------------------ */
+ − 916
+ − 917 /* It really makes more sense for the baud-rate to be console-specific
+ − 918 and not device-specific, but it's (at least potentially) used for output
+ − 919 decisions. */
+ − 920
+ − 921 void
+ − 922 init_baud_rate (struct device *d)
+ − 923 {
+ − 924 if (DEVICE_WIN_P (d) || DEVICE_STREAM_P (d))
+ − 925 {
+ − 926 DEVICE_BAUD_RATE (d) = 38400;
+ − 927 return;
+ − 928 }
+ − 929
+ − 930 #ifdef HAVE_TTY
+ − 931 assert (DEVICE_TTY_P (d));
+ − 932 {
647
+ − 933 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
428
+ − 934 int input_fd = CONSOLE_TTY_DATA (con)->infd;
814
+ − 935 #ifdef HAVE_TERMIOS
428
+ − 936 struct termios sg;
+ − 937
+ − 938 sg.c_cflag = B9600;
+ − 939 tcgetattr (input_fd, &sg);
+ − 940 DEVICE_TTY_DATA (d)->ospeed = cfgetospeed (&sg);
+ − 941 # if defined (USE_GETOBAUD) && defined (getobaud)
+ − 942 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
+ − 943 if (DEVICE_TTY_DATA (d)->ospeed == 0)
+ − 944 DEVICE_TTY_DATA (d)->ospeed = getobaud (sg.c_cflag);
+ − 945 # endif
+ − 946 #elif defined (HAVE_TERMIO)
+ − 947 struct termio sg;
+ − 948
+ − 949 sg.c_cflag = B9600;
+ − 950 # ifdef HAVE_TCATTR
+ − 951 tcgetattr (input_fd, &sg);
+ − 952 # else
+ − 953 ioctl (input_fd, TCGETA, &sg);
+ − 954 # endif
+ − 955 DEVICE_TTY_DATA (d)->ospeed = sg.c_cflag & CBAUD;
+ − 956 #else /* neither TERMIOS nor TERMIO */
+ − 957 struct sgttyb sg;
+ − 958
+ − 959 sg.sg_ospeed = B9600;
+ − 960 if (ioctl (input_fd, TIOCGETP, &sg) < 0)
+ − 961 abort ();
+ − 962 DEVICE_TTY_DATA (d)->ospeed = sg.sg_ospeed;
+ − 963 #endif
+ − 964 }
+ − 965
+ − 966 DEVICE_BAUD_RATE (d) =
+ − 967 (DEVICE_TTY_DATA (d)->ospeed < countof (baud_convert)
+ − 968 ? baud_convert[DEVICE_TTY_DATA (d)->ospeed]
+ − 969 : 9600);
+ − 970
+ − 971 if (DEVICE_BAUD_RATE (d) == 0)
+ − 972 DEVICE_BAUD_RATE (d) = 1200;
+ − 973 #endif /* HAVE_TTY */
+ − 974 }
+ − 975
+ − 976
+ − 977 /* ------------------------------------------------------ */
+ − 978 /* SIGIO control */
+ − 979 /* ------------------------------------------------------ */
+ − 980
853
+ − 981 #if defined (SIGIO) && !defined (BROKEN_SIGIO)
428
+ − 982
+ − 983 static void
+ − 984 init_sigio_on_device (struct device *d)
+ − 985 {
+ − 986 int filedesc = DEVICE_INFD (d);
+ − 987
+ − 988 #if defined (FIOSSAIOOWN)
+ − 989 { /* HPUX stuff */
+ − 990 int owner = getpid ();
+ − 991 int ioctl_status;
+ − 992 if (DEVICE_TTY_P (d))
+ − 993 {
+ − 994 ioctl_status = ioctl (filedesc, FIOGSAIOOWN,
+ − 995 &DEVICE_OLD_FCNTL_OWNER (d));
+ − 996 ioctl_status = ioctl (filedesc, FIOSSAIOOWN, &owner);
+ − 997 }
+ − 998 #ifdef HAVE_WINDOW_SYSTEM
+ − 999 else if (!DEVICE_STREAM_P (d))
+ − 1000 {
+ − 1001 ioctl_status = ioctl (filedesc, SIOCGPGRP,
+ − 1002 &DEVICE_OLD_FCNTL_OWNER (d));
+ − 1003 ioctl_status = ioctl (filedesc, SIOCSPGRP, &owner);
+ − 1004 }
+ − 1005 #endif
+ − 1006 }
+ − 1007 #elif defined (F_SETOWN) && !defined (F_SETOWN_BUG)
+ − 1008 DEVICE_OLD_FCNTL_OWNER (d) = fcntl (filedesc, F_GETOWN, 0);
+ − 1009 # ifdef F_SETOWN_SOCK_NEG
+ − 1010 /* stdin is a socket here */
+ − 1011 fcntl (filedesc, F_SETOWN, -getpid ());
+ − 1012 # else
+ − 1013 fcntl (filedesc, F_SETOWN, getpid ());
+ − 1014 # endif
+ − 1015 #endif
+ − 1016 }
+ − 1017
+ − 1018 static void
+ − 1019 reset_sigio_on_device (struct device *d)
+ − 1020 {
+ − 1021 int filedesc = DEVICE_INFD (d);
+ − 1022
+ − 1023 #if defined (FIOSSAIOOWN)
+ − 1024 { /* HPUX stuff */
+ − 1025 int ioctl_status;
+ − 1026 if (DEVICE_TTY_P (d))
+ − 1027 {
+ − 1028 ioctl_status = ioctl (filedesc, FIOSSAIOOWN,
+ − 1029 &DEVICE_OLD_FCNTL_OWNER (d));
+ − 1030 }
+ − 1031 #ifdef HAVE_WINDOW_SYSTEM
+ − 1032 else if (!DEVICE_STREAM_P (d))
+ − 1033 {
+ − 1034 ioctl_status = ioctl (filedesc, SIOCSPGRP,
+ − 1035 &DEVICE_OLD_FCNTL_OWNER (d));
+ − 1036 }
+ − 1037 #endif
+ − 1038 }
+ − 1039 #elif defined (F_SETOWN) && !defined (F_SETOWN_BUG)
+ − 1040 fcntl (filedesc, F_SETOWN, DEVICE_OLD_FCNTL_OWNER (d));
+ − 1041 #endif
+ − 1042 }
+ − 1043
+ − 1044 static void
+ − 1045 request_sigio_on_device (struct device *d)
+ − 1046 {
+ − 1047 int filedesc = DEVICE_INFD (d);
+ − 1048
502
+ − 1049 /* NOTE: It appears that Linux has its own mechanism for requesting
+ − 1050 SIGIO, using the F_GETSIG and F_SETSIG commands to fcntl().
+ − 1051 These let you pick which signal you want sent (not just SIGIO),
+ − 1052 and if you do this, you get additional info which tells you which
+ − 1053 file descriptor has input ready on it. The man page says:
+ − 1054
+ − 1055 Using these mechanisms, a program can implement fully
+ − 1056 asynchronous I/O without using select(2) or poll(2) most
+ − 1057 of the time.
+ − 1058
+ − 1059 The use of O_ASYNC, F_GETOWN, F_SETOWN is specific to BSD
+ − 1060 and Linux. F_GETSIG and F_SETSIG are Linux-specific.
+ − 1061 POSIX has asynchronous I/O and the aio_sigevent structure
+ − 1062 to achieve similar things; these are also available in
+ − 1063 Linux as part of the GNU C Library (Glibc).
+ − 1064
+ − 1065 But it appears that Linux also supports O_ASYNC, so I see no
+ − 1066 particular need to switch. --ben
+ − 1067 */
+ − 1068
+ − 1069 #if defined (I_SETSIG) && !defined (HPUX10) && !defined (LINUX)
428
+ − 1070 {
502
+ − 1071 int events = 0;
428
+ − 1072 ioctl (filedesc, I_GETSIG, &events);
+ − 1073 ioctl (filedesc, I_SETSIG, events | S_INPUT);
+ − 1074 }
502
+ − 1075 #elif defined (O_ASYNC)
+ − 1076 /* Generally FASYNC and O_ASYNC are both defined, and both equal;
+ − 1077 but let's not depend on that. O_ASYNC appears to be more
+ − 1078 standard (at least the Linux include files think so), so
+ − 1079 check it first. */
+ − 1080 fcntl (filedesc, F_SETFL, fcntl (filedesc, F_GETFL, 0) | O_ASYNC);
428
+ − 1081 #elif defined (FASYNC)
+ − 1082 fcntl (filedesc, F_SETFL, fcntl (filedesc, F_GETFL, 0) | FASYNC);
+ − 1083 #elif defined (FIOSSAIOSTAT)
+ − 1084 {
+ − 1085 /* DG: Changed for HP-UX. HP-UX uses different IOCTLs for
+ − 1086 sockets and other devices for some bizarre reason. We guess
+ − 1087 that an X device is a socket, and tty devices aren't. We then
+ − 1088 use the following crud to do the appropriate thing. */
+ − 1089 int on = 1;
+ − 1090 int ioctl_status; /* ####DG: check if IOCTL succeeds here. */
+ − 1091
+ − 1092 if (DEVICE_TTY_P (d))
+ − 1093 {
+ − 1094 ioctl_status = ioctl (filedesc, FIOSSAIOSTAT, &on);
+ − 1095 }
+ − 1096 #ifdef HAVE_WINDOW_SYSTEM
+ − 1097 else if (!DEVICE_STREAM_P (d))
+ − 1098 {
+ − 1099 ioctl_status = ioctl (filedesc, FIOASYNC, &on);
+ − 1100 }
+ − 1101 #endif
+ − 1102 }
+ − 1103 #elif defined (FIOASYNC)
+ − 1104 {
+ − 1105 int on = 1;
+ − 1106 ioctl (filedesc, FIOASYNC, &on);
+ − 1107 }
+ − 1108 #endif
+ − 1109
+ − 1110 #if defined (_CX_UX) /* #### Is this crap necessary? */
+ − 1111 EMACS_UNBLOCK_SIGNAL (SIGIO);
+ − 1112 #endif
+ − 1113 }
+ − 1114
+ − 1115 static void
+ − 1116 unrequest_sigio_on_device (struct device *d)
+ − 1117 {
+ − 1118 int filedesc = DEVICE_INFD (d);
+ − 1119
502
+ − 1120 #if defined (I_SETSIG) && !defined (HPUX10) && !defined (LINUX)
428
+ − 1121 {
502
+ − 1122 int events = 0;
428
+ − 1123 ioctl (filedesc, I_GETSIG, &events);
+ − 1124 ioctl (filedesc, I_SETSIG, events & ~S_INPUT);
+ − 1125 }
502
+ − 1126 #elif defined (O_ASYNC)
+ − 1127 fcntl (filedesc, F_SETFL, fcntl (filedesc, F_GETFL, 0) & ~O_ASYNC);
428
+ − 1128 #elif defined (FASYNC)
+ − 1129 fcntl (filedesc, F_SETFL, fcntl (filedesc, F_GETFL, 0) & ~FASYNC);
+ − 1130 #elif defined (FIOSSAIOSTAT)
+ − 1131 {
+ − 1132 /* DG: Changed for HP-UX. HP-UX uses different IOCTLs for
+ − 1133 sockets and other devices for some bizarre reason. We guess
+ − 1134 that an X device is a socket, and tty devices aren't. We then
+ − 1135 use the following crud to do the appropriate thing. */
+ − 1136
+ − 1137 int off = 0;
+ − 1138 int ioctl_status;
+ − 1139
+ − 1140 /* See comment for request_sigio_on_device */
+ − 1141
+ − 1142 if (DEVICE_TTY_P (d))
+ − 1143 {
+ − 1144 ioctl_status = ioctl (filedesc, FIOSSAIOSTAT, &off);
+ − 1145 }
+ − 1146 else
+ − 1147 {
+ − 1148 ioctl_status = ioctl (filedesc, FIOASYNC, &off);
+ − 1149 }
+ − 1150 }
+ − 1151 #elif defined (FIOASYNC)
+ − 1152 {
+ − 1153 int off = 0;
+ − 1154 ioctl (filedesc, FIOASYNC, &off);
+ − 1155 }
+ − 1156 #endif
+ − 1157 }
+ − 1158
+ − 1159 void
+ − 1160 request_sigio (void)
+ − 1161 {
+ − 1162 Lisp_Object devcons, concons;
+ − 1163
+ − 1164 DEVICE_LOOP_NO_BREAK (devcons, concons)
+ − 1165 {
+ − 1166 struct device *d;
+ − 1167
+ − 1168 d = XDEVICE (XCAR (devcons));
+ − 1169
+ − 1170 if (!DEVICE_STREAM_P (d))
+ − 1171 request_sigio_on_device (d);
+ − 1172 }
+ − 1173 }
+ − 1174
+ − 1175 void
+ − 1176 unrequest_sigio (void)
+ − 1177 {
+ − 1178 Lisp_Object devcons, concons;
+ − 1179
+ − 1180 DEVICE_LOOP_NO_BREAK (devcons, concons)
+ − 1181 {
+ − 1182 struct device *d;
+ − 1183
+ − 1184 d = XDEVICE (XCAR (devcons));
+ − 1185
+ − 1186 if (!DEVICE_STREAM_P (d))
+ − 1187 unrequest_sigio_on_device (d);
+ − 1188 }
+ − 1189 }
+ − 1190
+ − 1191 #endif /* SIGIO */
+ − 1192
+ − 1193 /* ------------------------------------------------------ */
+ − 1194 /* Changing Emacs's process group */
+ − 1195 /* ------------------------------------------------------ */
+ − 1196
+ − 1197 /* Saving and restoring the process group of Emacs's terminal. */
+ − 1198
+ − 1199 /* On some systems, apparently (?!) Emacs must be in its own process
+ − 1200 group in order to receive SIGIO correctly. On other systems
+ − 1201 (e.g. Solaris), it's not required and doing it makes things
+ − 1202 get fucked up. So, we only do it when
+ − 1203 SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP is defined. Basically,
+ − 1204 this is only required for BSD 4.2 systems. (Actually, I bet
+ − 1205 we don't have to do this at all -- those systems also
+ − 1206 required interrupt input, which we don't support.)
+ − 1207
+ − 1208 If Emacs was in its own process group (i.e. inherited_pgroup ==
+ − 1209 getpid ()), then we know we're running under a shell with job
+ − 1210 control (Emacs would never be run as part of a pipeline).
+ − 1211 Everything is fine.
+ − 1212
+ − 1213 If Emacs was not in its own process group, then we know we're
+ − 1214 running under a shell (or a caller) that doesn't know how to
+ − 1215 separate itself from Emacs (like sh). Emacs must be in its own
+ − 1216 process group in order to receive SIGIO correctly. In this
+ − 1217 situation, we put ourselves in our own pgroup, forcibly set the
+ − 1218 tty's pgroup to our pgroup, and make sure to restore and reinstate
+ − 1219 the tty's pgroup just like any other terminal setting. If
+ − 1220 inherited_group was not the tty's pgroup, then we'll get a
+ − 1221 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
+ − 1222 it goes foreground in the future, which is what should happen. */
+ − 1223
+ − 1224 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
+ − 1225
442
+ − 1226 static pid_t inherited_pgroup;
+ − 1227 static pid_t inherited_tty_pgroup;
428
+ − 1228
+ − 1229 #endif
+ − 1230
+ − 1231 void
+ − 1232 munge_tty_process_group (void)
+ − 1233 {
+ − 1234 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
+ − 1235 if (noninteractive)
+ − 1236 return;
+ − 1237
+ − 1238 /* Only do this munging if we have a device on the controlling
+ − 1239 terminal. See the large comment below. */
+ − 1240
+ − 1241 if (CONSOLEP (Vcontrolling_terminal) &&
+ − 1242 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
+ − 1243 {
+ − 1244 int fd = open ("/dev/tty", O_RDWR, 0);
442
+ − 1245 pid_t me = getpid ();
428
+ − 1246 EMACS_BLOCK_SIGNAL (SIGTTOU);
+ − 1247 EMACS_SET_TTY_PROCESS_GROUP (fd, &me);
+ − 1248 EMACS_UNBLOCK_SIGNAL (SIGTTOU);
771
+ − 1249 retry_close (fd);
428
+ − 1250 }
+ − 1251 #endif
+ − 1252 }
+ − 1253
+ − 1254 /* Split off the foreground process group to Emacs alone.
+ − 1255 When we are in the foreground, but not started in our own process
+ − 1256 group, redirect the TTY to point to our own process group. We need
+ − 1257 to be in our own process group to receive SIGIO properly. */
+ − 1258 static void
+ − 1259 munge_process_groups (void)
+ − 1260 {
+ − 1261 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
+ − 1262 if (noninteractive)
+ − 1263 return;
+ − 1264
+ − 1265 EMACS_SEPARATE_PROCESS_GROUP ();
+ − 1266
+ − 1267 munge_tty_process_group ();
+ − 1268 #endif
+ − 1269 }
+ − 1270
+ − 1271 void
+ − 1272 unmunge_tty_process_group (void)
+ − 1273 {
+ − 1274 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
+ − 1275 {
+ − 1276 int fd = open ("/dev/tty", O_RDWR, 0);
+ − 1277 EMACS_BLOCK_SIGNAL (SIGTTOU);
+ − 1278 EMACS_SET_TTY_PROCESS_GROUP (fd, &inherited_tty_pgroup);
+ − 1279 EMACS_UNBLOCK_SIGNAL (SIGTTOU);
771
+ − 1280 retry_close (fd);
428
+ − 1281 }
+ − 1282 #endif
+ − 1283 }
+ − 1284
+ − 1285 /* Set the tty to our original foreground group.
+ − 1286 Also restore the original process group (put us back into sh's
+ − 1287 process group), so that ^Z will suspend both us and sh. */
+ − 1288 static void
+ − 1289 unmunge_process_groups (void)
+ − 1290 {
+ − 1291 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
+ − 1292 if (noninteractive)
+ − 1293 return;
+ − 1294
+ − 1295 unmunge_tty_process_group ();
+ − 1296
+ − 1297 EMACS_SET_PROCESS_GROUP (inherited_pgroup);
+ − 1298 #endif
+ − 1299 }
+ − 1300
+ − 1301 /* According to some old wisdom, we need to be in a separate process
+ − 1302 group for SIGIO to work correctly (at least on some systems ...).
+ − 1303 So go ahead and put ourselves into our own process group. This
+ − 1304 will fail if we're already in our own process group, but who cares.
+ − 1305 Also record whether we were in our own process group. (In general,
+ − 1306 we will already be in our own process group if we were started from
+ − 1307 a job-control shell like csh, but not if we were started from sh).
+ − 1308
+ − 1309 If we succeeded in changing our process group, then we will no
+ − 1310 longer be in the foreground process group of our controlling
+ − 1311 terminal. Therefore, if we have a console open onto this terminal,
+ − 1312 we have to change the controlling terminal's foreground process
+ − 1313 group (otherwise we will get stopped with a SIGTTIN signal when
+ − 1314 attempting to read from the terminal). It's important,
+ − 1315 however, that we do this *only* when we have a console open onto
+ − 1316 the terminal. It's a decidedly bad idea to do so otherwise,
+ − 1317 especially if XEmacs was started from the background. */
+ − 1318
+ − 1319 void
+ − 1320 init_process_group (void)
+ − 1321 {
+ − 1322 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
+ − 1323 if (! noninteractive)
+ − 1324 {
+ − 1325 int fd = open ("/dev/tty", O_RDWR, 0);
+ − 1326 inherited_pgroup = EMACS_GET_PROCESS_GROUP ();
+ − 1327 EMACS_GET_TTY_PROCESS_GROUP (fd, &inherited_tty_pgroup);
771
+ − 1328 retry_close (fd);
428
+ − 1329 EMACS_SEPARATE_PROCESS_GROUP ();
+ − 1330 }
+ − 1331 #endif
+ − 1332 }
+ − 1333
+ − 1334 void
+ − 1335 disconnect_controlling_terminal (void)
+ − 1336 {
+ − 1337 # ifdef HAVE_SETSID
+ − 1338 /* Controlling terminals are attached to a session.
+ − 1339 Create a new session for us; it will have no controlling
+ − 1340 terminal. This also, of course, puts us in our own
+ − 1341 process group. */
+ − 1342 setsid ();
+ − 1343 # else
+ − 1344 /* Put us in our own process group. */
+ − 1345 EMACS_SEPARATE_PROCESS_GROUP ();
+ − 1346 # if defined (TIOCNOTTY)
+ − 1347 /* This is the older way of disconnecting the controlling
+ − 1348 terminal, on 4.3 BSD. We must open /dev/tty; using
+ − 1349 filedesc 0 is not sufficient because it could be
+ − 1350 something else (e.g. our stdin was redirected to
+ − 1351 another terminal).
+ − 1352 */
+ − 1353 {
+ − 1354 int j = open ("/dev/tty", O_RDWR, 0);
+ − 1355 ioctl (j, TIOCNOTTY, 0);
771
+ − 1356 retry_close (j);
428
+ − 1357 }
+ − 1358 # endif /* TIOCNOTTY */
+ − 1359 /*
+ − 1360 On systems without TIOCNOTTY and without
+ − 1361 setsid(), we don't need to do anything more to
+ − 1362 disconnect our controlling terminal. Here is
+ − 1363 what the man page for termio(7) from a SYSV 3.2
+ − 1364 system says:
+ − 1365
+ − 1366 "The first terminal file opened by the process group leader
+ − 1367 of a terminal file not already associated with a process
+ − 1368 group becomes the control terminal for that process group.
+ − 1369 The control terminal plays a special role in handling quit
+ − 1370 and interrupt signals, as discussed below. The control
+ − 1371 terminal is inherited by a child process during a fork(2).
+ − 1372 A process can break this association by changing its process
+ − 1373 group using setpgrp(2)."
+ − 1374
+ − 1375 */
+ − 1376 # endif /* not HAVE_SETSID */
+ − 1377 }
+ − 1378
+ − 1379
+ − 1380 /* ------------------------------------------------------ */
+ − 1381 /* Getting and setting emacs_tty structures */
+ − 1382 /* ------------------------------------------------------ */
+ − 1383
+ − 1384 /* It's wrong to encase these into #ifdef HAVE_TTY because we need
+ − 1385 them for child TTY processes. */
+ − 1386 /* However, this does break NT support while we don't do child TTY processes */
442
+ − 1387 #ifndef WIN32_NATIVE
428
+ − 1388
+ − 1389 /* Set *TC to the parameters associated with the terminal FD.
+ − 1390 Return zero if all's well, or -1 if we ran into an error we
+ − 1391 couldn't deal with. */
+ − 1392 int
+ − 1393 emacs_get_tty (int fd, struct emacs_tty *settings)
+ − 1394 {
+ − 1395 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
+ − 1396 #ifdef HAVE_TCATTR
+ − 1397 /* We have those nifty POSIX tcmumbleattr functions. */
+ − 1398 if (tcgetattr (fd, &settings->main) < 0)
+ − 1399 return -1;
+ − 1400
+ − 1401 #elif defined HAVE_TERMIO
+ − 1402 /* The SYSV-style interface? */
+ − 1403 if (ioctl (fd, TCGETA, &settings->main) < 0)
+ − 1404 return -1;
+ − 1405
814
+ − 1406 #else
428
+ − 1407 /* I give up - I hope you have the BSD ioctls. */
+ − 1408 if (ioctl (fd, TIOCGETP, &settings->main) < 0)
+ − 1409 return -1;
+ − 1410 #endif /* HAVE_TCATTR */
+ − 1411
+ − 1412 /* Suivant - Do we have to get struct ltchars data? */
+ − 1413 #ifdef HAVE_LTCHARS
+ − 1414 if (ioctl (fd, TIOCGLTC, &settings->ltchars) < 0)
+ − 1415 return -1;
+ − 1416 #endif
+ − 1417
+ − 1418 /* How about a struct tchars and a wordful of lmode bits? */
+ − 1419 #ifdef HAVE_TCHARS
+ − 1420 if (ioctl (fd, TIOCGETC, &settings->tchars) < 0
+ − 1421 || ioctl (fd, TIOCLGET, &settings->lmode) < 0)
+ − 1422 return -1;
+ − 1423 #endif
+ − 1424
+ − 1425 /* We have survived the tempest. */
+ − 1426 return 0;
+ − 1427 }
+ − 1428
+ − 1429 /* Set the parameters of the tty on FD according to the contents of
+ − 1430 *SETTINGS. If FLUSHP is non-zero, we discard input.
430
+ − 1431 Return 0 if all went well, and -1 if anything failed.
+ − 1432 #### All current callers use FLUSHP == 0. */
428
+ − 1433
+ − 1434 int
+ − 1435 emacs_set_tty (int fd, struct emacs_tty *settings, int flushp)
+ − 1436 {
+ − 1437 /* Set the primary parameters - baud rate, character size, etcetera. */
+ − 1438 #ifdef HAVE_TCATTR
+ − 1439 int i;
+ − 1440 /* We have those nifty POSIX tcmumbleattr functions.
+ − 1441 William J. Smith <wjs@wiis.wang.com> writes:
+ − 1442 "POSIX 1003.1 defines tcsetattr() to return success if it was
+ − 1443 able to perform any of the requested actions, even if some
+ − 1444 of the requested actions could not be performed.
+ − 1445 We must read settings back to ensure tty setup properly.
+ − 1446 AIX requires this to keep tty from hanging occasionally." */
+ − 1447 /* This makes sure that we don't loop indefinitely in here. */
+ − 1448 for (i = 0 ; i < 10 ; i++)
+ − 1449 if (tcsetattr (fd, flushp ? TCSAFLUSH : TCSADRAIN, &settings->main) < 0)
+ − 1450 {
+ − 1451 if (errno == EINTR)
+ − 1452 continue;
+ − 1453 else
+ − 1454 return -1;
+ − 1455 }
+ − 1456 else
+ − 1457 {
+ − 1458 struct termios new;
+ − 1459
+ − 1460 /* Get the current settings, and see if they're what we asked for. */
+ − 1461 tcgetattr (fd, &new);
+ − 1462 /* We cannot use memcmp on the whole structure here because under
+ − 1463 * aix386 the termios structure has some reserved field that may
+ − 1464 * not be filled in.
+ − 1465 */
+ − 1466 if ( new.c_iflag == settings->main.c_iflag
+ − 1467 && new.c_oflag == settings->main.c_oflag
+ − 1468 && new.c_cflag == settings->main.c_cflag
+ − 1469 && new.c_lflag == settings->main.c_lflag
+ − 1470 && memcmp(new.c_cc, settings->main.c_cc, NCCS) == 0)
+ − 1471 break;
+ − 1472 else
+ − 1473 continue;
+ − 1474 }
+ − 1475 #elif defined HAVE_TERMIO
+ − 1476 /* The SYSV-style interface? */
+ − 1477 if (ioctl (fd, flushp ? TCSETAF : TCSETAW, &settings->main) < 0)
+ − 1478 return -1;
+ − 1479
814
+ − 1480 #else
428
+ − 1481 /* I give up - I hope you have the BSD ioctls. */
+ − 1482 if (ioctl (fd, (flushp) ? TIOCSETP : TIOCSETN, &settings->main) < 0)
+ − 1483 return -1;
+ − 1484 #endif /* HAVE_TCATTR */
+ − 1485
+ − 1486 /* Suivant - Do we have to get struct ltchars data? */
+ − 1487 #ifdef HAVE_LTCHARS
+ − 1488 if (ioctl (fd, TIOCSLTC, &settings->ltchars) < 0)
+ − 1489 return -1;
+ − 1490 #endif
+ − 1491
+ − 1492 /* How about a struct tchars and a wordful of lmode bits? */
+ − 1493 #ifdef HAVE_TCHARS
+ − 1494 if (ioctl (fd, TIOCSETC, &settings->tchars) < 0
+ − 1495 || ioctl (fd, TIOCLSET, &settings->lmode) < 0)
+ − 1496 return -1;
+ − 1497 #endif
+ − 1498
+ − 1499 /* We have survived the tempest. */
+ − 1500 return 0;
+ − 1501 }
+ − 1502
442
+ − 1503 #endif /* WIN32_NATIVE */
428
+ − 1504
+ − 1505 /* ------------------------------------------------------ */
+ − 1506 /* Initializing a device */
+ − 1507 /* ------------------------------------------------------ */
+ − 1508
+ − 1509 #ifdef HAVE_TTY
+ − 1510
+ − 1511 /* This may also be defined in stdio,
+ − 1512 but if so, this does no harm,
+ − 1513 and using the same name avoids wasting the other one's space. */
+ − 1514
+ − 1515 #if ((defined(USG) || defined(DGUX)) && !defined(__STDC__))
+ − 1516 char _sobuf[BUFSIZ+8];
+ − 1517 #elif (defined(USG) && !defined(LINUX) && !defined(_SCO_DS)) || defined(IRIX5)
+ − 1518 extern unsigned char _sobuf[BUFSIZ+8];
+ − 1519 #else
+ − 1520 char _sobuf[BUFSIZ];
+ − 1521 #endif
+ − 1522
+ − 1523 #if defined (TIOCGLTC) && defined (HAVE_LTCHARS) /* HAVE_LTCHARS */
+ − 1524 static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1};
+ − 1525 #endif
+ − 1526 #ifdef TIOCGETC /* HAVE_TCHARS */
+ − 1527 #ifdef HAVE_TCHARS
+ − 1528 static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
+ − 1529 #endif
+ − 1530 #endif
+ − 1531
+ − 1532 static void
+ − 1533 tty_init_sys_modes_on_device (struct device *d)
+ − 1534 {
+ − 1535 struct emacs_tty tty;
2286
+ − 1536 int input_fd;
+ − 1537 #if defined (IBMR2AIX) && defined (AIXHFT)
+ − 1538 int output_fd;
+ − 1539 #endif
428
+ − 1540 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
+ − 1541
+ − 1542 input_fd = CONSOLE_TTY_DATA (con)->infd;
2286
+ − 1543 #if defined (IBMR2AIX) && defined (AIXHFT)
428
+ − 1544 output_fd = CONSOLE_TTY_DATA (con)->outfd;
2286
+ − 1545 #endif
428
+ − 1546
430
+ − 1547 emacs_get_tty (input_fd, &CONSOLE_TTY_DATA (con)->old_tty);
428
+ − 1548 tty = CONSOLE_TTY_DATA (con)->old_tty;
+ − 1549
+ − 1550 con->tty_erase_char = Qnil;
+ − 1551
+ − 1552 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
+ − 1553 /* after all those years... */
+ − 1554 con->tty_erase_char = make_char (tty.main.c_cc[VERASE]);
+ − 1555 #ifdef DGUX
+ − 1556 /* This allows meta to be sent on 8th bit. */
+ − 1557 tty.main.c_iflag &= ~INPCK; /* don't check input for parity */
+ − 1558 #endif
+ − 1559 tty.main.c_iflag |= (IGNBRK); /* Ignore break condition */
+ − 1560 tty.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */
+ − 1561 #ifdef ISTRIP
+ − 1562 tty.main.c_iflag &= ~ISTRIP; /* don't strip 8th bit on input */
+ − 1563 #endif
+ − 1564 tty.main.c_lflag &= ~ECHO; /* Disable echo */
+ − 1565 tty.main.c_lflag &= ~ICANON; /* Disable erase/kill processing */
+ − 1566 #ifdef IEXTEN
+ − 1567 tty.main.c_lflag &= ~IEXTEN; /* Disable other editing characters. */
+ − 1568 #endif
+ − 1569 tty.main.c_lflag |= ISIG; /* Enable signals */
+ − 1570 if (TTY_FLAGS (con).flow_control)
+ − 1571 {
+ − 1572 tty.main.c_iflag |= IXON; /* Enable start/stop output control */
+ − 1573 #ifdef IXANY
+ − 1574 tty.main.c_iflag &= ~IXANY;
+ − 1575 #endif /* IXANY */
+ − 1576 }
+ − 1577 else
+ − 1578 tty.main.c_iflag &= ~IXON; /* Disable start/stop output control */
+ − 1579 tty.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL
+ − 1580 on output */
513
+ − 1581
+ − 1582 #if 0
+ − 1583 /* We used to disable tab expansion here, but this is the user's decision. */
+ − 1584 #if defined (TABDLY) && defined (TAB3)
+ − 1585 if ((tty.main.c_oflag & TABDLY) == TAB3)
+ − 1586 tty.main.c_oflag &= ~TABDLY; /* Disable tab expansion (Posix). */
+ − 1587 #elif defined (OXTABS)
+ − 1588 tty.main.c_oflag &= ~OXTABS; /* Disable tab expansion (BSD). */
+ − 1589 #endif
+ − 1590 #endif /* 0 */
+ − 1591
428
+ − 1592 #ifdef CS8
+ − 1593 if (TTY_FLAGS (con).meta_key)
+ − 1594 {
+ − 1595 tty.main.c_cflag |= CS8; /* allow 8th bit on input */
+ − 1596 tty.main.c_cflag &= ~PARENB;/* Don't check parity */
+ − 1597 }
+ − 1598 #endif
+ − 1599 if (CONSOLE_TTY_DATA (con)->controlling_terminal)
+ − 1600 {
1204
+ − 1601 tty.main.c_cc[VINTR] = /* C-g (usually) gives SIGINT */
+ − 1602 event_to_character (CONSOLE_QUIT_EVENT (con), 0, 1, 0);
428
+ − 1603 /* Set up C-g for both SIGQUIT and SIGINT.
+ − 1604 We don't know which we will get, but we handle both alike
+ − 1605 so which one it really gives us does not matter. */
1204
+ − 1606 tty.main.c_cc[VQUIT] = tty.main.c_cc[VINTR];
428
+ − 1607 }
+ − 1608 else
+ − 1609 {
+ − 1610 tty.main.c_cc[VINTR] = _POSIX_VDISABLE;
+ − 1611 tty.main.c_cc[VQUIT] = _POSIX_VDISABLE;
+ − 1612 }
+ − 1613 tty.main.c_cc[VMIN] = 1; /* Input should wait for at
+ − 1614 least 1 char */
+ − 1615 tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */
+ − 1616 #ifdef VSWTCH
+ − 1617 tty.main.c_cc[VSWTCH] = _POSIX_VDISABLE; /* Turn off shell layering use
+ − 1618 of C-z */
+ − 1619 #endif /* VSWTCH */
+ − 1620 /* There was some conditionalizing here on (mips or TCATTR), but
+ − 1621 I think that's wrong. There was one report of C-y (DSUSP) not being
+ − 1622 disabled on HP9000s700 systems, and this might fix it. */
+ − 1623 #ifdef VSUSP
+ − 1624 tty.main.c_cc[VSUSP] = _POSIX_VDISABLE; /* Turn off mips handling of C-z. */
+ − 1625 #endif /* VSUSP */
+ − 1626 #ifdef V_DSUSP
+ − 1627 tty.main.c_cc[V_DSUSP] = _POSIX_VDISABLE; /* Turn off mips handling of C-y. */
+ − 1628 #endif /* V_DSUSP */
+ − 1629 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
+ − 1630 tty.main.c_cc[VDSUSP] = _POSIX_VDISABLE;
+ − 1631 #endif /* VDSUSP */
+ − 1632 #ifdef VLNEXT
+ − 1633 tty.main.c_cc[VLNEXT] = _POSIX_VDISABLE;
+ − 1634 #endif /* VLNEXT */
+ − 1635 #ifdef VREPRINT
+ − 1636 tty.main.c_cc[VREPRINT] = _POSIX_VDISABLE;
+ − 1637 #endif /* VREPRINT */
+ − 1638 #ifdef VWERASE
+ − 1639 tty.main.c_cc[VWERASE] = _POSIX_VDISABLE;
+ − 1640 #endif /* VWERASE */
+ − 1641 #ifdef VDISCARD
+ − 1642 tty.main.c_cc[VDISCARD] = _POSIX_VDISABLE;
+ − 1643 #endif /* VDISCARD */
+ − 1644 #ifdef VSTART
+ − 1645 tty.main.c_cc[VSTART] = _POSIX_VDISABLE;
+ − 1646 #endif /* VSTART */
+ − 1647 #ifdef VSTRT
+ − 1648 tty.main.c_cc[VSTRT] = _POSIX_VDISABLE; /* called VSTRT on some systems */
+ − 1649 #endif /* VSTART */
+ − 1650 #ifdef VSTOP
+ − 1651 tty.main.c_cc[VSTOP] = _POSIX_VDISABLE;
+ − 1652 #endif /* VSTOP */
+ − 1653 #ifdef SET_LINE_DISCIPLINE
+ − 1654 /* Need to explicitly request TERMIODISC line discipline or
+ − 1655 Ultrix's termios does not work correctly. */
+ − 1656 tty.main.c_line = SET_LINE_DISCIPLINE;
+ − 1657 #endif
+ − 1658
+ − 1659 #ifdef AIX
+ − 1660 #ifndef IBMR2AIX
+ − 1661 /* AIX enhanced edit loses NULs, so disable it. */
+ − 1662 tty.main.c_line = 0;
+ − 1663 tty.main.c_iflag &= ~ASCEDIT;
+ − 1664 #else
+ − 1665 tty.main.c_cc[VSTRT] = 255;
+ − 1666 tty.main.c_cc[VSTOP] = 255;
+ − 1667 tty.main.c_cc[VSUSP] = 255;
+ − 1668 tty.main.c_cc[VDSUSP] = 255;
+ − 1669 #endif /* IBMR2AIX */
+ − 1670 /* Also, PTY overloads NUL and BREAK.
+ − 1671 don't ignore break, but don't signal either, so it looks like NUL.
+ − 1672 This really serves a purpose only if running in an XTERM window
+ − 1673 or via TELNET or the like, but does no harm elsewhere. */
+ − 1674 tty.main.c_iflag &= ~IGNBRK;
+ − 1675 tty.main.c_iflag &= ~BRKINT;
+ − 1676 #endif /* AIX */
+ − 1677 #else /* if not HAVE_TERMIO */
+ − 1678 con->tty_erase_char = make_char (tty.main.sg_erase);
+ − 1679 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS);
+ − 1680 if (TTY_FLAGS (con).meta_key)
+ − 1681 tty.main.sg_flags |= ANYP;
+ − 1682 /* #### should we be using RAW mode here? */
+ − 1683 tty.main.sg_flags |= /* interrupt_input ? RAW : */ CBREAK;
+ − 1684 #endif /* not HAVE_TERMIO */
+ − 1685
+ − 1686 /* If going to use CBREAK mode, we must request C-g to interrupt
+ − 1687 and turn off start and stop chars, etc. If not going to use
+ − 1688 CBREAK mode, do this anyway so as to turn off local flow
+ − 1689 control for user coming over network on 4.2; in this case,
+ − 1690 only t_stopc and t_startc really matter. */
+ − 1691 #ifndef HAVE_TERMIO
+ − 1692 #ifdef HAVE_TCHARS
+ − 1693 /* Note: if not using CBREAK mode, it makes no difference how we
+ − 1694 set this */
+ − 1695 tty.tchars = new_tchars;
1204
+ − 1696 tty.tchars.t_intrc = event_to_character (CONSOLE_QUIT_EVENT (con), 0, 1, 0);
428
+ − 1697 if (TTY_FLAGS (con).flow_control)
+ − 1698 {
+ − 1699 tty.tchars.t_startc = '\021';
+ − 1700 tty.tchars.t_stopc = '\023';
+ − 1701 }
+ − 1702
+ − 1703 tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH |
+ − 1704 CONSOLE_TTY_DATA (con)->old_tty.lmode;
+ − 1705
+ − 1706 #if defined (ultrix) || defined (__bsdi__)
+ − 1707 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
+ − 1708 anything, and leaving it in breaks the meta key. Go figure. */
+ − 1709 /* Turning off ONLCR is enough under BSD/386. Leave the general
+ − 1710 output post-processing flag alone since for some reason it
+ − 1711 doesn't get reset after XEmacs goes away. */
+ − 1712 tty.lmode &= ~LLITOUT;
+ − 1713 #endif
+ − 1714
+ − 1715 #endif /* HAVE_TCHARS */
+ − 1716 #endif /* not HAVE_TERMIO */
+ − 1717
+ − 1718 #ifdef HAVE_LTCHARS
+ − 1719 tty.ltchars = new_ltchars;
+ − 1720 #endif /* HAVE_LTCHARS */
+ − 1721
430
+ − 1722 emacs_set_tty (input_fd, &tty, 0);
428
+ − 1723
+ − 1724 /* This code added to insure that, if flow-control is not to be used,
+ − 1725 we have an unlocked terminal at the start. */
+ − 1726
+ − 1727 #ifdef TCXONC
+ − 1728 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TCXONC, 1);
+ − 1729 #endif
+ − 1730 #ifdef TIOCSTART
+ − 1731 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TIOCSTART, 0);
+ − 1732 #endif
+ − 1733
+ − 1734 #if defined (HAVE_TERMIOS) || defined (HPUX9)
+ − 1735 #ifdef TCOON
+ − 1736 if (!TTY_FLAGS (con).flow_control) tcflow (input_fd, TCOON);
+ − 1737 #endif
+ − 1738 #endif
+ − 1739 #ifdef AIXHFT
+ − 1740 hft_init (con);
+ − 1741 #ifdef IBMR2AIX
+ − 1742 {
+ − 1743 /* IBM's HFT device usually thinks a ^J should be LF/CR.
+ − 1744 We need it to be only LF. This is the way that is
+ − 1745 done. */
+ − 1746 struct termio tty;
+ − 1747
+ − 1748 if (ioctl (output_fd, HFTGETID, &tty) != -1)
771
+ − 1749 retry_write (output_fd, "\033[20l", 5);
428
+ − 1750 }
+ − 1751 #endif
+ − 1752 #endif
+ − 1753
+ − 1754 #if 0 /* We do our own buffering with lstreams. */
+ − 1755 #ifdef _IOFBF
+ − 1756 /* This symbol is defined on recent USG systems.
+ − 1757 Someone says without this call USG won't really buffer the file
+ − 1758 even with a call to setbuf. */
647
+ − 1759 setvbuf (CONSOLE_TTY_DATA (con)->outfd, (char *) _sobuf, _IOFBF,
+ − 1760 sizeof (_sobuf));
428
+ − 1761 #else
+ − 1762 setbuf (CONSOLE_TTY_DATA (con)->outfd, (char *) _sobuf);
+ − 1763 #endif
+ − 1764 #endif
+ − 1765 set_tty_modes (con);
+ − 1766 }
+ − 1767
+ − 1768 #endif /* HAVE_TTY */
+ − 1769
+ − 1770 void
2340
+ − 1771 init_one_device (
+ − 1772 #if defined(HAVE_TTY) || (defined(SIGIO) && !defined(BROKEN_SIGIO))
+ − 1773 struct device *d
+ − 1774 #else
+ − 1775 struct device *UNUSED (d)
+ − 1776 #endif
+ − 1777 )
428
+ − 1778 {
+ − 1779 #ifdef HAVE_TTY
+ − 1780 if (DEVICE_TTY_P (d))
+ − 1781 tty_init_sys_modes_on_device (d);
+ − 1782 #endif
+ − 1783 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
+ − 1784 if (!DEVICE_STREAM_P (d))
+ − 1785 {
+ − 1786 init_sigio_on_device (d);
+ − 1787 request_sigio_on_device (d);
+ − 1788 }
+ − 1789 #endif
+ − 1790 }
+ − 1791
+ − 1792 void
+ − 1793 init_one_console (struct console *con)
+ − 1794 {
+ − 1795 Lisp_Object devcons;
+ − 1796
+ − 1797 CONSOLE_DEVICE_LOOP (devcons, con)
+ − 1798 {
+ − 1799 struct device *d = XDEVICE (XCAR (devcons));
+ − 1800
+ − 1801 init_one_device (d);
+ − 1802 }
+ − 1803 }
+ − 1804
+ − 1805 void
+ − 1806 reinit_initial_console (void)
+ − 1807 {
+ − 1808 munge_process_groups ();
+ − 1809 if (CONSOLEP (Vcontrolling_terminal) &&
+ − 1810 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
+ − 1811 init_one_console (XCONSOLE (Vcontrolling_terminal));
+ − 1812 }
+ − 1813
+ − 1814
+ − 1815 /* ------------------------------------------------------ */
+ − 1816 /* Other TTY functions */
+ − 1817 /* ------------------------------------------------------ */
+ − 1818
+ − 1819 #ifdef HAVE_TTY
+ − 1820
+ − 1821 #if 0 /* not currently used */
+ − 1822
+ − 1823 /* Return nonzero if safe to use tabs in output.
+ − 1824 At the time this is called, init_sys_modes has not been done yet. */
+ − 1825
+ − 1826 int
2340
+ − 1827 tabs_safe_p (struct device *USED_IF_TTY (d))
428
+ − 1828 {
+ − 1829 #ifdef HAVE_TTY
+ − 1830 if (DEVICE_TTY_P (d))
+ − 1831 {
+ − 1832 struct emacs_tty tty;
+ − 1833
430
+ − 1834 emacs_get_tty (DEVICE_INFD (d), &tty);
428
+ − 1835 return EMACS_TTY_TABS_OK (&tty);
+ − 1836 }
+ − 1837 #endif
+ − 1838 return 1;
+ − 1839 }
+ − 1840
+ − 1841 #endif /* 0 */
+ − 1842
+ − 1843 /* Get terminal size from system.
+ − 1844 Store number of lines into *heightp and width into *widthp.
+ − 1845 If zero or a negative number is stored, the value is not valid. */
+ − 1846
+ − 1847 void
+ − 1848 get_tty_device_size (struct device *d, int *widthp, int *heightp)
+ − 1849 {
+ − 1850 int input_fd = DEVICE_INFD (d);
+ − 1851
+ − 1852 assert (DEVICE_TTY_P (d));
+ − 1853
+ − 1854 #ifdef TIOCGWINSZ
+ − 1855 {
+ − 1856 /* BSD-style. */
+ − 1857 struct winsize size;
+ − 1858
+ − 1859 if (ioctl (input_fd, TIOCGWINSZ, &size) == -1)
+ − 1860 *widthp = *heightp = 0;
+ − 1861 else
+ − 1862 {
+ − 1863 *widthp = size.ws_col;
+ − 1864 *heightp = size.ws_row;
+ − 1865 }
+ − 1866 }
+ − 1867 #elif defined TIOCGSIZE
+ − 1868 {
+ − 1869 /* SunOS - style. */
+ − 1870 struct ttysize size;
+ − 1871
+ − 1872 if (ioctl (input_fd, TIOCGSIZE, &size) == -1)
+ − 1873 *widthp = *heightp = 0;
+ − 1874 else
+ − 1875 {
+ − 1876 *widthp = size.ts_cols;
+ − 1877 *heightp = size.ts_lines;
+ − 1878 }
+ − 1879 }
+ − 1880 #else /* system doesn't know size */
+ − 1881
+ − 1882 *widthp = 0;
+ − 1883 *heightp = 0;
+ − 1884
+ − 1885 #endif /* not !TIOCGWINSZ */
+ − 1886 }
+ − 1887
+ − 1888 #endif /* HAVE_TTY */
+ − 1889
+ − 1890
+ − 1891 /* ------------------------------------------------------ */
+ − 1892 /* Is device 8 bit ? */
+ − 1893 /* ------------------------------------------------------ */
+ − 1894
+ − 1895 #ifdef HAVE_TTY
+ − 1896
+ − 1897 int
+ − 1898 eight_bit_tty (struct device *d)
+ − 1899 {
+ − 1900 struct emacs_tty s;
+ − 1901 int input_fd;
+ − 1902 int eight_bit = 0;
+ − 1903
+ − 1904 assert (DEVICE_TTY_P (d));
+ − 1905 input_fd = DEVICE_INFD (d);
+ − 1906
430
+ − 1907 emacs_get_tty (input_fd, &s);
428
+ − 1908
+ − 1909 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
+ − 1910 eight_bit = (s.main.c_cflag & CSIZE) == CS8;
+ − 1911 #else
+ − 1912 eight_bit = 0; /* I don't know how to do it */
+ − 1913 #endif
+ − 1914 return eight_bit;
+ − 1915 }
+ − 1916
+ − 1917 #endif /* HAVE_TTY */
+ − 1918
+ − 1919
+ − 1920 /* ------------------------------------------------------ */
+ − 1921 /* Resetting a device */
+ − 1922 /* ------------------------------------------------------ */
+ − 1923
+ − 1924 #ifdef HAVE_TTY
+ − 1925
+ − 1926 /* Prepare the terminal for exiting Emacs; move the cursor to the
+ − 1927 bottom of the frame, turn off interrupt-driven I/O, etc. */
+ − 1928 static void
+ − 1929 tty_reset_sys_modes_on_device (struct device *d)
+ − 1930 {
2286
+ − 1931 #if defined (BSD) || (defined (IBMR2AIX) && defined (AIXHFT))
+ − 1932 int output_fd;
+ − 1933 #endif
+ − 1934 int input_fd;
428
+ − 1935 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
+ − 1936
+ − 1937 input_fd = CONSOLE_TTY_DATA (con)->infd;
2286
+ − 1938 #if defined (BSD) || (defined (IBMR2AIX) && defined (AIXHFT))
428
+ − 1939 output_fd = CONSOLE_TTY_DATA (con)->outfd;
2286
+ − 1940 #endif
428
+ − 1941
+ − 1942 #if defined (IBMR2AIX) && defined (AIXHFT)
+ − 1943 {
+ − 1944 /* HFT consoles normally use ^J as a LF/CR. We forced it to
+ − 1945 do the LF only. Now, we need to reset it. */
+ − 1946 struct termio tty;
+ − 1947
+ − 1948 if (ioctl (output_fd, HFTGETID, &tty) != -1)
771
+ − 1949 retry_write (output_fd, "\033[20h", 5);
428
+ − 1950 }
+ − 1951 #endif
+ − 1952
+ − 1953 tty_redisplay_shutdown (con);
+ − 1954 /* reset_tty_modes() flushes the connection at its end. */
+ − 1955 reset_tty_modes (con);
+ − 1956
+ − 1957 #if defined (BSD)
+ − 1958 /* Avoid possible loss of output when changing terminal modes. */
+ − 1959 fsync (output_fd);
+ − 1960 #endif
+ − 1961
430
+ − 1962 while (emacs_set_tty (input_fd, &CONSOLE_TTY_DATA (con)->old_tty, 0)
428
+ − 1963 < 0 && errno == EINTR)
+ − 1964 ;
+ − 1965
+ − 1966 #ifdef SET_LINE_DISCIPLINE
+ − 1967 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
+ − 1968 A different old line discipline is therefore not restored, yet.
+ − 1969 Restore the old line discipline by hand. */
+ − 1970 ioctl (input_fd, TIOCSETD, &old_tty.main.c_line);
+ − 1971 #endif
+ − 1972
+ − 1973 #ifdef AIXHFT
+ − 1974 hft_reset (con);
+ − 1975 #endif
+ − 1976
+ − 1977 }
+ − 1978
+ − 1979 #endif /* HAVE_TTY */
+ − 1980
+ − 1981 void
+ − 1982 reset_one_device (struct device *d)
+ − 1983 {
+ − 1984 #ifdef HAVE_TTY
+ − 1985 if (DEVICE_TTY_P (d))
+ − 1986 tty_reset_sys_modes_on_device (d);
+ − 1987 else
+ − 1988 #endif
+ − 1989 if (DEVICE_STREAM_P (d))
+ − 1990 fflush (CONSOLE_STREAM_DATA (XCONSOLE (DEVICE_CONSOLE (d)))->out);
+ − 1991 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
+ − 1992 if (!DEVICE_STREAM_P (d))
+ − 1993 {
+ − 1994 unrequest_sigio_on_device (d);
+ − 1995 reset_sigio_on_device (d);
+ − 1996 }
+ − 1997 #endif
+ − 1998 }
+ − 1999
+ − 2000 void
+ − 2001 reset_one_console (struct console *con)
+ − 2002 {
+ − 2003 /* Note: this can be called during GC. */
+ − 2004 Lisp_Object devcons;
+ − 2005
+ − 2006 CONSOLE_DEVICE_LOOP (devcons, con)
+ − 2007 {
+ − 2008 struct device *d = XDEVICE (XCAR (devcons));
+ − 2009
+ − 2010 reset_one_device (d);
+ − 2011 }
+ − 2012 }
+ − 2013
+ − 2014 void
+ − 2015 reset_all_consoles (void)
+ − 2016 {
+ − 2017 /* Note: this can be called during GC. */
+ − 2018 Lisp_Object concons;
+ − 2019
+ − 2020 CONSOLE_LOOP (concons)
+ − 2021 {
+ − 2022 struct console *con = XCONSOLE (XCAR (concons));
+ − 2023
+ − 2024 reset_one_console (con);
+ − 2025 }
+ − 2026
+ − 2027 unmunge_process_groups ();
+ − 2028 }
+ − 2029
+ − 2030 void
+ − 2031 reset_initial_console (void)
+ − 2032 {
+ − 2033 if (CONSOLEP (Vcontrolling_terminal) &&
+ − 2034 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
+ − 2035 reset_one_console (XCONSOLE (Vcontrolling_terminal));
+ − 2036 unmunge_process_groups ();
+ − 2037 }
+ − 2038
+ − 2039
+ − 2040 /* ------------------------------------------------------ */
+ − 2041 /* extra TTY stuff under AIX */
+ − 2042 /* ------------------------------------------------------ */
+ − 2043
+ − 2044 #ifdef AIXHFT
+ − 2045
+ − 2046 /* Called from init_sys_modes. */
+ − 2047 static void
+ − 2048 hft_init (struct console *con)
+ − 2049 {
+ − 2050 int junk;
+ − 2051 int input_fd;
+ − 2052
+ − 2053 assert (CONSOLE_TTY_P (con));
+ − 2054 input_fd = CONSOLE_TTY_DATA (con)->infd;
+ − 2055
+ − 2056 /* If we're not on an HFT we shouldn't do any of this. We determine
+ − 2057 if we are on an HFT by trying to get an HFT error code. If this
+ − 2058 call fails, we're not on an HFT. */
+ − 2059 #ifdef IBMR2AIX
+ − 2060 if (ioctl (input_fd, HFQERROR, &junk) < 0)
+ − 2061 return;
+ − 2062 #else /* not IBMR2AIX */
+ − 2063 if (ioctl (input_fd, HFQEIO, 0) < 0)
+ − 2064 return;
+ − 2065 #endif /* not IBMR2AIX */
+ − 2066
+ − 2067 /* On AIX the default hft keyboard mapping uses backspace rather than delete
+ − 2068 as the rubout key's ASCII code. Here this is changed. The bug is that
+ − 2069 there's no way to determine the old mapping, so in reset_one_console
+ − 2070 we need to assume that the normal map had been present. Of course, this
+ − 2071 code also doesn't help if on a terminal emulator which doesn't understand
+ − 2072 HFT VTD's. */
+ − 2073 {
+ − 2074 struct hfbuf buf;
+ − 2075 struct hfkeymap keymap;
+ − 2076
+ − 2077 buf.hf_bufp = (char *)&keymap;
+ − 2078 buf.hf_buflen = sizeof (keymap);
+ − 2079 keymap.hf_nkeys = 2;
+ − 2080 keymap.hfkey[0].hf_kpos = 15;
+ − 2081 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE;
+ − 2082 #ifdef IBMR2AIX
+ − 2083 keymap.hfkey[0].hf_keyidh = '<';
+ − 2084 #else /* not IBMR2AIX */
+ − 2085 keymap.hfkey[0].hf_page = '<';
+ − 2086 #endif /* not IBMR2AIX */
+ − 2087 keymap.hfkey[0].hf_char = 127;
+ − 2088 keymap.hfkey[1].hf_kpos = 15;
+ − 2089 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT;
+ − 2090 #ifdef IBMR2AIX
+ − 2091 keymap.hfkey[1].hf_keyidh = '<';
+ − 2092 #else /* not IBMR2AIX */
+ − 2093 keymap.hfkey[1].hf_page = '<';
+ − 2094 #endif /* not IBMR2AIX */
+ − 2095 keymap.hfkey[1].hf_char = 127;
+ − 2096 hftctl (input_fd, HFSKBD, &buf);
+ − 2097 }
+ − 2098 /* #### Should probably set a console TTY flag here. */
+ − 2099 #if 0
+ − 2100 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
+ − 2101 at times. */
+ − 2102 line_ins_del_ok = char_ins_del_ok = 0;
+ − 2103 #endif /* 0 */
+ − 2104 }
+ − 2105
+ − 2106 /* Reset the rubout key to backspace. */
+ − 2107
+ − 2108 static void
+ − 2109 hft_reset (struct console *con)
+ − 2110 {
+ − 2111 struct hfbuf buf;
+ − 2112 struct hfkeymap keymap;
+ − 2113 int junk;
+ − 2114 int input_fd;
+ − 2115
+ − 2116 assert (CONSOLE_TTY_P (con));
+ − 2117 input_fd = CONSOLE_TTY_DATA (con)->infd;
+ − 2118
+ − 2119 #ifdef IBMR2AIX
+ − 2120 if (ioctl (input_fd, HFQERROR, &junk) < 0)
+ − 2121 return;
+ − 2122 #else /* not IBMR2AIX */
+ − 2123 if (ioctl (input_fd, HFQEIO, 0) < 0)
+ − 2124 return;
+ − 2125 #endif /* not IBMR2AIX */
+ − 2126
+ − 2127 buf.hf_bufp = (char *)&keymap;
+ − 2128 buf.hf_buflen = sizeof (keymap);
+ − 2129 keymap.hf_nkeys = 2;
+ − 2130 keymap.hfkey[0].hf_kpos = 15;
+ − 2131 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE;
+ − 2132 #ifdef IBMR2AIX
+ − 2133 keymap.hfkey[0].hf_keyidh = '<';
+ − 2134 #else /* not IBMR2AIX */
+ − 2135 keymap.hfkey[0].hf_page = '<';
+ − 2136 #endif /* not IBMR2AIX */
+ − 2137 keymap.hfkey[0].hf_char = 8;
+ − 2138 keymap.hfkey[1].hf_kpos = 15;
+ − 2139 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT;
+ − 2140 #ifdef IBMR2AIX
+ − 2141 keymap.hfkey[1].hf_keyidh = '<';
+ − 2142 #else /* not IBMR2AIX */
+ − 2143 keymap.hfkey[1].hf_page = '<';
+ − 2144 #endif /* not IBMR2AIX */
+ − 2145 keymap.hfkey[1].hf_char = 8;
+ − 2146 hftctl (input_fd, HFSKBD, &buf);
+ − 2147 }
+ − 2148
+ − 2149 #endif /* AIXHFT */
+ − 2150
+ − 2151
+ − 2152 /************************************************************************/
+ − 2153 /* limits of text/data segments */
+ − 2154 /************************************************************************/
+ − 2155
801
+ − 2156 /* Need start_of_data() as much as possible now, for total_data_usage();
+ − 2157 but with PDUMP and WIN32_NATIVE, can't currently do it. */
1330
+ − 2158 #if ! (defined (PDUMP) && defined (WIN32_NATIVE) && defined (SYSTEM_MALLOC))
428
+ − 2159 #define NEED_STARTS
+ − 2160 #endif
+ − 2161
+ − 2162 #ifdef NEED_STARTS
+ − 2163 /* Some systems that cannot dump also cannot implement these. */
+ − 2164
+ − 2165 /*
+ − 2166 * Return the address of the start of the text segment prior to
+ − 2167 * doing an unexec. After unexec the return value is undefined.
+ − 2168 * See crt0.c for further explanation and _start.
+ − 2169 *
+ − 2170 */
+ − 2171
801
+ − 2172 #if !defined (HAVE_TEXT_START) && !defined (PDUMP)
440
+ − 2173
442
+ − 2174 EXTERN_C int _start (void);
428
+ − 2175
+ − 2176 char *
+ − 2177 start_of_text (void)
+ − 2178 {
+ − 2179 #ifdef TEXT_START
442
+ − 2180 return (char *) TEXT_START;
428
+ − 2181 #else
442
+ − 2182 return (char *) _start;
428
+ − 2183 #endif /* TEXT_START */
+ − 2184 }
440
+ − 2185 #endif /* !defined(HAVE_TEXT_START) && !defined(PDUMP) */
428
+ − 2186
+ − 2187 /*
+ − 2188 * Return the address of the start of the data segment prior to
+ − 2189 * doing an unexec. After unexec the return value is undefined.
442
+ − 2190 * See ecrt0.c for further information and definition of data_start.
428
+ − 2191 *
+ − 2192 * Apparently, on BSD systems this is etext at startup. On
+ − 2193 * USG systems (swapping) this is highly mmu dependent and
+ − 2194 * is also dependent on whether or not the program is running
+ − 2195 * with shared text. Generally there is a (possibly large)
+ − 2196 * gap between end of text and start of data with shared text.
+ − 2197 *
+ − 2198 * On Uniplus+ systems with shared text, data starts at a
+ − 2199 * fixed address. Each port (from a given oem) is generally
+ − 2200 * different, and the specific value of the start of data can
+ − 2201 * be obtained via the UniPlus+ specific "uvar" system call,
+ − 2202 * however the method outlined in crt0.c seems to be more portable.
+ − 2203 *
+ − 2204 * Probably what will have to happen when a USG unexec is available,
+ − 2205 * at least on UniPlus, is temacs will have to be made unshared so
+ − 2206 * that text and data are contiguous. Then once loadup is complete,
+ − 2207 * unexec will produce a shared executable where the data can be
+ − 2208 * at the normal shared text boundary and the startofdata variable
+ − 2209 * will be patched by unexec to the correct value.
+ − 2210 *
+ − 2211 */
+ − 2212
801
+ − 2213 #if defined (ORDINARY_LINK) && !defined (MINGW)
428
+ − 2214 extern char **environ;
+ − 2215 #endif
+ − 2216
+ − 2217 void *
+ − 2218 start_of_data (void)
+ − 2219 {
+ − 2220 #ifdef DATA_START
+ − 2221 return ((char *) DATA_START);
+ − 2222 #else
452
+ − 2223 #if defined (ORDINARY_LINK) || defined(PDUMP)
428
+ − 2224 /*
+ − 2225 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
+ − 2226 * data_start isn't defined. We take the address of environ, which
+ − 2227 * is known to live at or near the start of the system crt0.c, and
+ − 2228 * we don't sweat the handful of bytes that might lose.
+ − 2229 */
442
+ − 2230 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
428
+ − 2231 extern char* static_heap_base;
+ − 2232 if (!initialized)
+ − 2233 return static_heap_base;
+ − 2234 #endif
801
+ − 2235 return ((char *) &environ);
428
+ − 2236 #else
+ − 2237 extern int data_start;
+ − 2238 return ((char *) &data_start);
+ − 2239 #endif /* ORDINARY_LINK */
+ − 2240 #endif /* DATA_START */
+ − 2241 }
1330
+ − 2242 #endif /* NEED_STARTS aka !(PDUMP && WIN32_NATIVE && SYSTEM_MALLOC) */
428
+ − 2243
801
+ − 2244 extern void *minimum_address_seen; /* from xmalloc() */
+ − 2245 extern void *maximum_address_seen; /* from xmalloc() */
+ − 2246
+ − 2247 Bytecount
+ − 2248 total_data_usage (void)
+ − 2249 {
+ − 2250 #ifdef NEED_STARTS
+ − 2251 void *data_start = start_of_data ();
+ − 2252 #else
+ − 2253 void *data_start = minimum_address_seen;
+ − 2254 #endif
854
+ − 2255
1315
+ − 2256 #ifndef WIN32_ANY
814
+ − 2257 void *data_end = sbrk (0);
801
+ − 2258 #else
+ − 2259 void *data_end = maximum_address_seen;
+ − 2260 #endif
+ − 2261
+ − 2262 /* Sanity checking -- the min determined by malloc() should always be
+ − 2263 greater than data start determined by other means. We could do the
+ − 2264 same check on the max, except that things like rel-alloc might
+ − 2265 invalidate it. */
+ − 2266 if (minimum_address_seen &&
+ − 2267 (char *) minimum_address_seen < (char *) data_start)
+ − 2268 data_start = minimum_address_seen;
+ − 2269
+ − 2270 if (data_end < data_start) /* Huh?????????? */
+ − 2271 data_end = maximum_address_seen;
+ − 2272
+ − 2273 /* #### Doesn't seem to give good results on Windows; values are much
+ − 2274 higher than actual memory usage. How to fix??? */
+ − 2275 return (char *) data_end - (char *) data_start;
+ − 2276 }
+ − 2277
428
+ − 2278
+ − 2279 /************************************************************************/
+ − 2280 /* get the system name */
+ − 2281 /************************************************************************/
+ − 2282
+ − 2283 /* init_system_name sets up the string for the Lisp function
+ − 2284 system-name to return. */
+ − 2285
+ − 2286 extern Lisp_Object Vsystem_name;
+ − 2287
+ − 2288 void
+ − 2289 init_system_name (void)
+ − 2290 {
442
+ − 2291 #if defined (WIN32_NATIVE)
771
+ − 2292 Extbyte hostname[MAX_XETCHAR_SIZE * (MAX_COMPUTERNAME_LENGTH + 1)];
+ − 2293 DWORD size = sizeof (hostname) / XETCHAR_SIZE;
+ − 2294 qxeGetComputerName (hostname, &size);
+ − 2295 Vsystem_name = build_tstr_string (hostname);
428
+ − 2296 #elif !defined (HAVE_GETHOSTNAME)
+ − 2297 struct utsname uts;
+ − 2298 uname (&uts);
+ − 2299 Vsystem_name = build_string (uts.nodename);
+ − 2300 #else /* HAVE_GETHOSTNAME */
647
+ − 2301 int hostname_size = 256;
2367
+ − 2302 /* !!#### Needs review */
851
+ − 2303 char *hostname = (char *) ALLOCA (hostname_size);
428
+ − 2304
+ − 2305 /* Try to get the host name; if the buffer is too short, try
+ − 2306 again. Apparently, the only indication gethostname gives of
+ − 2307 whether the buffer was large enough is the presence or absence
+ − 2308 of a '\0' in the string. Eech. */
+ − 2309 for (;;)
+ − 2310 {
+ − 2311 gethostname (hostname, hostname_size - 1);
+ − 2312 hostname[hostname_size - 1] = '\0';
+ − 2313
+ − 2314 /* Was the buffer large enough for the '\0'? */
647
+ − 2315 if ((int) strlen (hostname) < (hostname_size - 1))
428
+ − 2316 break;
+ − 2317
+ − 2318 hostname_size <<= 1;
2367
+ − 2319 /* !!#### Needs review */
851
+ − 2320 hostname = (char *) ALLOCA (hostname_size);
428
+ − 2321 }
558
+ − 2322 # if defined( HAVE_SOCKETS)
428
+ − 2323 /* Turn the hostname into the official, fully-qualified hostname.
+ − 2324 Don't do this if we're going to dump; this can confuse system
+ − 2325 libraries on some machines and make the dumped emacs core dump. */
+ − 2326 if (initialized)
+ − 2327 if (!strchr (hostname, '.'))
+ − 2328 {
440
+ − 2329 # if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETNAMEINFO))
428
+ − 2330 struct hostent *hp = NULL;
+ − 2331 int count;
440
+ − 2332 # ifdef TRY_AGAIN
428
+ − 2333 for (count = 0; count < 10; count++)
+ − 2334 {
+ − 2335 h_errno = 0;
440
+ − 2336 # endif
428
+ − 2337 /* Some systems can't handle SIGALARM/SIGIO in gethostbyname(). */
+ − 2338 stop_interrupts ();
+ − 2339 hp = gethostbyname (hostname);
+ − 2340 start_interrupts ();
440
+ − 2341 # ifdef TRY_AGAIN
428
+ − 2342 if (! (hp == 0 && h_errno == TRY_AGAIN))
+ − 2343 break;
+ − 2344 Fsleep_for (make_int (1));
+ − 2345 }
440
+ − 2346 # endif
428
+ − 2347 if (hp)
+ − 2348 {
442
+ − 2349 const char *fqdn = (const char *) hp->h_name;
428
+ − 2350
+ − 2351 if (!strchr (fqdn, '.'))
+ − 2352 {
+ − 2353 /* We still don't have a fully qualified domain name.
+ − 2354 Try to find one in the list of alternate names */
+ − 2355 char **alias = hp->h_aliases;
+ − 2356 while (*alias && !strchr (*alias, '.'))
+ − 2357 alias++;
+ − 2358 if (*alias)
+ − 2359 fqdn = *alias;
+ − 2360 }
2367
+ − 2361 /* !!#### Needs review */
851
+ − 2362 hostname = (char *) ALLOCA (strlen (fqdn) + 1);
428
+ − 2363 strcpy (hostname, fqdn);
+ − 2364 }
440
+ − 2365 # else /* !(HAVE_GETADDRINFO && HAVE_GETNAMEINFO) */
+ − 2366 struct addrinfo hints, *res;
+ − 2367
+ − 2368 xzero (hints);
+ − 2369 hints.ai_flags = AI_CANONNAME;
724
+ − 2370 #ifdef IPV6_CANONICALIZE
440
+ − 2371 hints.ai_family = AF_UNSPEC;
724
+ − 2372 #else
+ − 2373 hints.ai_family = PF_INET;
+ − 2374 #endif
440
+ − 2375 hints.ai_socktype = SOCK_STREAM;
+ − 2376 hints.ai_protocol = 0;
+ − 2377 if (!getaddrinfo (hostname, NULL, &hints, &res))
+ − 2378 {
2367
+ − 2379 /* !!#### Needs review */
851
+ − 2380 hostname = (char *) ALLOCA (strlen (res->ai_canonname) + 1);
440
+ − 2381 strcpy (hostname, res->ai_canonname);
+ − 2382
+ − 2383 freeaddrinfo (res);
+ − 2384 }
+ − 2385 # endif /* !(HAVE_GETADDRINFO && HAVE_GETNAMEINFO) */
428
+ − 2386 }
+ − 2387 # endif /* HAVE_SOCKETS */
+ − 2388 Vsystem_name = build_string (hostname);
+ − 2389 #endif /* HAVE_GETHOSTNAME */
+ − 2390 {
867
+ − 2391 Ibyte *p;
428
+ − 2392 Bytecount i;
+ − 2393
+ − 2394 for (i = 0, p = XSTRING_DATA (Vsystem_name);
+ − 2395 i < XSTRING_LENGTH (Vsystem_name);
+ − 2396 i++, p++)
+ − 2397 {
+ − 2398 if (*p == ' ' || *p == '\t')
+ − 2399 *p = '-';
+ − 2400 }
+ − 2401 }
+ − 2402 }
+ − 2403
+ − 2404
+ − 2405 /************************************************************************/
+ − 2406 /* Emulation of select() */
+ − 2407 /************************************************************************/
+ − 2408
+ − 2409 #ifndef HAVE_SELECT
+ − 2410
+ − 2411 ERROR: XEmacs requires a working select().
+ − 2412
+ − 2413 #endif /* not HAVE_SELECT */
+ − 2414
+ − 2415
+ − 2416 /************************************************************************/
+ − 2417 /* Emulation of signal stuff */
+ − 2418 /************************************************************************/
+ − 2419
+ − 2420 /* BSD 4.1 crap deleted. 4.2 was released in 1983, for God's sake! I
+ − 2421 can't imagine that anyone is actually running that OS any more.
+ − 2422 You can't use X under it (I think) because there's no select().
+ − 2423 Anyway, the signal stuff has all been changed. If someone wants to
+ − 2424 get this stuff working again, look in the FSF Emacs sources. */
+ − 2425
+ − 2426 /* POSIX signals support - DJB */
+ − 2427
+ − 2428 #ifdef HAVE_SIGPROCMASK
+ − 2429
+ − 2430 /* #### Is there any reason this is static global rather than local? */
+ − 2431 static struct sigaction new_action, old_action;
+ − 2432
+ − 2433 signal_handler_t
613
+ − 2434 qxe_reliable_signal (int signal_number, signal_handler_t action)
428
+ − 2435 {
+ − 2436 #if 0
+ − 2437
+ − 2438 /* XEmacs works better if system calls are *not* restarted.
+ − 2439 This allows C-g to interrupt reads and writes, on most systems.
+ − 2440
+ − 2441 #### Another possibility is to just longjmp() out of the signal
+ − 2442 handler. According to W.R. Stevens, this should be OK on all
+ − 2443 systems. However, I don't want to deal with the potential
+ − 2444 evil ramifications of this at this point. */
+ − 2445
+ − 2446 #ifdef DGUX
+ − 2447 /* This gets us restartable system calls for efficiency.
+ − 2448 The "else" code will work as well. */
+ − 2449 return (berk_signal (signal_number, action));
+ − 2450 #else
+ − 2451 sigemptyset (&new_action.sa_mask);
+ − 2452 new_action.sa_handler = action;
+ − 2453 #if defined (SA_RESTART)
+ − 2454 /* Emacs mostly works better with restartable system services. If this
+ − 2455 * flag exists, we probably want to turn it on here.
+ − 2456 */
+ − 2457 new_action.sa_flags = SA_RESTART;
+ − 2458 #else
+ − 2459 new_action.sa_flags = 0;
+ − 2460 #endif
+ − 2461 sigaction (signal_number, &new_action, &old_action);
+ − 2462 return (old_action.sa_handler);
+ − 2463 #endif /* DGUX */
+ − 2464
+ − 2465 #else /* not 0 */
+ − 2466
+ − 2467 sigemptyset (&new_action.sa_mask);
+ − 2468 new_action.sa_handler = action;
+ − 2469 #if defined (SA_INTERRUPT) /* don't restart system calls, under SunOS */
+ − 2470 new_action.sa_flags = SA_INTERRUPT;
+ − 2471 #else
+ − 2472 new_action.sa_flags = 0;
+ − 2473 #endif
+ − 2474 sigaction (signal_number, &new_action, &old_action);
+ − 2475 return (signal_handler_t) (old_action.sa_handler);
+ − 2476
+ − 2477 #endif /* not 0 */
+ − 2478 }
+ − 2479
+ − 2480 #elif defined (HAVE_SIGBLOCK)
+ − 2481
+ − 2482 /* We use sigvec() rather than signal() if we have it, because
+ − 2483 it lets us specify interruptible system calls. */
+ − 2484 signal_handler_t
613
+ − 2485 qxe_reliable_signal (int signal_number, signal_handler_t action)
428
+ − 2486 {
+ − 2487 struct sigvec vec, ovec;
+ − 2488
+ − 2489 vec.sv_handler = action;
+ − 2490 vec.sv_mask = 0;
+ − 2491 #ifdef SV_INTERRUPT /* don't restart system calls */
+ − 2492 vec.sv_flags = SV_INTERRUPT;
+ − 2493 #else
+ − 2494 vec.sv_flags = 0;
+ − 2495 #endif
+ − 2496
+ − 2497 sigvec (signal_number, &vec, &ovec);
+ − 2498
+ − 2499 return (ovec.sv_handler);
+ − 2500 }
+ − 2501
+ − 2502 #endif /* HAVE_SIGBLOCK (HAVE_SIGPROCMASK) */
+ − 2503
+ − 2504
+ − 2505 /************************************************************************/
+ − 2506 /* Emulation of strerror() and errno support */
+ − 2507 /************************************************************************/
+ − 2508
+ − 2509 #ifndef HAVE_STRERROR
+ − 2510
+ − 2511 #if !defined(NeXT) && !defined(__alpha) && !defined(MACH) && !defined(LINUX) && !defined(IRIX) && !defined(__NetBSD__)
+ − 2512 /* Linux added here by Raymond L. Toy <toy@alydar.crd.ge.com> for XEmacs. */
+ − 2513 /* Irix added here by gparker@sni-usa.com for XEmacs. */
+ − 2514 /* NetBSD added here by James R Grinter <jrg@doc.ic.ac.uk> for XEmacs */
442
+ − 2515 extern const char *sys_errlist[];
428
+ − 2516 extern int sys_nerr;
+ − 2517 #endif
+ − 2518
+ − 2519 #ifdef __NetBSD__
+ − 2520 extern char *sys_errlist[];
+ − 2521 extern int sys_nerr;
+ − 2522 #endif
+ − 2523
+ − 2524
442
+ − 2525 const char *
428
+ − 2526 strerror (int errnum)
+ − 2527 {
+ − 2528 if (errnum >= 0 && errnum < sys_nerr)
+ − 2529 return sys_errlist[errnum];
442
+ − 2530 return ((const char *) GETTEXT ("Unknown error"));
428
+ − 2531 }
+ − 2532
+ − 2533 #endif /* ! HAVE_STRERROR */
+ − 2534
+ − 2535
+ − 2536 /************************************************************************/
+ − 2537 /* Encapsulations of system calls */
+ − 2538 /************************************************************************/
+ − 2539
1318
+ − 2540 /* The documentation in VC++ claims that the pathname library functions
+ − 2541 accept strings in the current locale-specific encoding, but that's
+ − 2542 false, because they just call the native Win32 routines directly, which
+ − 2543 always use the system-default encoding (which is what Qmswindows_tstr
+ − 2544 will give us when not XEUNICODE_P). */
771
+ − 2545 #ifdef WIN32_NATIVE
+ − 2546 #define PATHNAME_CONVERT_OUT(path, pathout) C_STRING_TO_TSTR (path, pathout)
+ − 2547 #else
+ − 2548 #define PATHNAME_CONVERT_OUT(path, pathout) \
+ − 2549 C_STRING_TO_EXTERNAL (path, pathout, Qfile_name)
+ − 2550 #endif
428
+ − 2551
+ − 2552 /***************** low-level calls ****************/
+ − 2553
+ − 2554 /*
+ − 2555 * On USG systems the system calls are INTERRUPTIBLE by signals
+ − 2556 * that the user program has elected to catch. Thus the system call
+ − 2557 * must be retried in these cases. To handle this without massive
+ − 2558 * changes in the source code, we remap the standard system call names
+ − 2559 * to names for our own functions in sysdep.c that do the system call
+ − 2560 * with retries. Actually, for portability reasons, it is good
+ − 2561 * programming practice, as this example shows, to limit all actual
+ − 2562 * system calls to a single occurrence in the source. Sure, this
+ − 2563 * adds an extra level of function call overhead but it is almost
+ − 2564 * always negligible. Fred Fish, Unisoft Systems Inc.
+ − 2565 */
+ − 2566
+ − 2567 /* Ben sez: read Dick Gabriel's essay about the Worse Is Better
+ − 2568 approach to programming and its connection to the silly
+ − 2569 interruptible-system-call business. To find it, look on
2340
+ − 2570 Jamie's home page (http://www.jwz.org/doc/worse-is-better.html). */
428
+ − 2571
771
+ − 2572 #ifdef WIN32_NATIVE
+ − 2573
+ − 2574 static int
+ − 2575 underlying_open_1 (const Extbyte *path, int oflag, int mode)
+ − 2576 {
+ − 2577 if (XEUNICODE_P)
+ − 2578 return _wopen ((const wchar_t *) path, oflag, mode);
+ − 2579 else
+ − 2580 return _open (path, oflag, mode);
+ − 2581 }
+ − 2582
+ − 2583 #endif /* WIN32_NATIVE */
+ − 2584
2367
+ − 2585 /* Just call open() with normal open() semantics, with some fixups for
+ − 2586 problems under Windows. */
771
+ − 2587
+ − 2588 static int
+ − 2589 underlying_open (const Extbyte *path, int oflag, int mode)
+ − 2590 {
+ − 2591 #ifdef WIN32_NATIVE
+ − 2592 {
+ − 2593 /* Try to open file without _O_CREAT, to be able to write to hidden
+ − 2594 and system files. Force all file handles to be
+ − 2595 non-inheritable. */
+ − 2596 int res = underlying_open_1 (path, (oflag & ~_O_CREAT) | _O_NOINHERIT,
+ − 2597 mode);
+ − 2598 if (res >= 0)
+ − 2599 return res;
+ − 2600 return underlying_open_1 (path, oflag | _O_NOINHERIT, mode);
+ − 2601 }
+ − 2602 #else
+ − 2603 return open (path, oflag, mode);
+ − 2604 #endif /* WIN32_NATIVE */
+ − 2605 }
+ − 2606
2367
+ − 2607 static int
+ − 2608 retry_open_1 (const Extbyte *path, int oflag, int mode)
428
+ − 2609 {
440
+ − 2610 #ifdef INTERRUPTIBLE_OPEN
428
+ − 2611 {
+ − 2612 int rtnval;
771
+ − 2613 while ((rtnval = underlying_open (path, oflag, mode)) == -1
428
+ − 2614 && (errno == EINTR))
+ − 2615 DO_NOTHING;
+ − 2616 return rtnval;
+ − 2617 }
+ − 2618 #else
771
+ − 2619 return underlying_open (path, oflag, mode);
428
+ − 2620 #endif
+ − 2621 }
771
+ − 2622
2367
+ − 2623 /* A version of open() that retries when interrupted. Operates on
+ − 2624 externally-encoded filenames. */
+ − 2625
+ − 2626 int XCDECL
+ − 2627 retry_open (const Extbyte *path, int oflag, ...)
+ − 2628 {
+ − 2629 int mode;
+ − 2630 va_list ap;
+ − 2631
+ − 2632 va_start (ap, oflag);
+ − 2633 mode = va_arg (ap, int);
+ − 2634 va_end (ap);
+ − 2635
+ − 2636 return retry_open_1 (path, oflag, mode);
+ − 2637 }
+ − 2638
+ − 2639 #if defined (WIN32_NATIVE) && defined (WEXTTEXT_IS_WIDE)
+ − 2640
+ − 2641 /* Like retry_open() but operate on Wexttext filenames. */
+ − 2642
+ − 2643 int XCDECL
+ − 2644 wext_retry_open (const Wexttext *path, int oflag, ...)
+ − 2645 {
+ − 2646 int mode;
+ − 2647 va_list ap;
+ − 2648
+ − 2649 va_start (ap, oflag);
+ − 2650 mode = va_arg (ap, int);
+ − 2651 va_end (ap);
+ − 2652
+ − 2653 if (!XEUNICODE_P)
+ − 2654 return retry_open_1 (WEXTTEXT_TO_MULTIBYTE (path), oflag, mode);
+ − 2655 else
+ − 2656 return retry_open_1 ((Extbyte *) path, oflag, mode);
+ − 2657 }
+ − 2658
+ − 2659 #endif
+ − 2660
771
+ − 2661 /* The basic external entry point to open(). Handles conversion to
+ − 2662 external encoding, interruptions, etc. */
+ − 2663
872
+ − 2664 int XCDECL
867
+ − 2665 qxe_open (const Ibyte *path, int oflag, ...)
771
+ − 2666 {
+ − 2667 Extbyte *pathout;
+ − 2668 int mode;
+ − 2669 va_list ap;
+ − 2670
+ − 2671 va_start (ap, oflag);
+ − 2672 mode = va_arg (ap, int);
+ − 2673 va_end (ap);
+ − 2674
+ − 2675 PATHNAME_CONVERT_OUT (path, pathout);
+ − 2676 return retry_open (pathout, oflag, mode);
+ − 2677 }
+ − 2678
+ − 2679 /* Like qxe_open, only when open() is interrupted by EINTR, check for
428
+ − 2680 QUIT. This allows the callers of this function to be interrupted
+ − 2681 with C-g when, say, reading from named pipes. However, this should
1123
+ − 2682 be used with caution, as it can run random Lisp code (although it
+ − 2683 cannot GC).
428
+ − 2684
+ − 2685 This function will not function as expected on systems where open()
+ − 2686 is not interrupted by C-g. However, the worst that can happen is
+ − 2687 the fallback to simple open(). */
+ − 2688 int
867
+ − 2689 qxe_interruptible_open (const Ibyte *path, int oflag, int mode)
428
+ − 2690 {
+ − 2691 /* This function can GC */
771
+ − 2692 Extbyte *pathout;
+ − 2693
+ − 2694 PATHNAME_CONVERT_OUT (path, pathout);
428
+ − 2695
442
+ − 2696 #ifdef WIN32_NATIVE
440
+ − 2697 /* Make all handles non-inheritable */
+ − 2698 oflag |= _O_NOINHERIT;
+ − 2699 #endif
+ − 2700
428
+ − 2701 for (;;)
+ − 2702 {
771
+ − 2703 int rtnval = underlying_open (pathout, oflag, mode);
428
+ − 2704 if (!(rtnval == -1 && errno == EINTR))
+ − 2705 return rtnval;
+ − 2706 /* open() was interrupted. Was QUIT responsible? */
+ − 2707 QUIT;
+ − 2708 }
+ − 2709 }
+ − 2710
+ − 2711 int
771
+ − 2712 retry_close (int filedes)
428
+ − 2713 {
+ − 2714 #ifdef INTERRUPTIBLE_CLOSE
+ − 2715 int did_retry = 0;
+ − 2716 REGISTER int rtnval;
+ − 2717
+ − 2718 while ((rtnval = close (filedes)) == -1
+ − 2719 && (errno == EINTR))
+ − 2720 did_retry = 1;
+ − 2721
+ − 2722 /* If close is interrupted SunOS 4.1 may or may not have closed the
+ − 2723 file descriptor. If it did the second close will fail with
+ − 2724 errno = EBADF. That means we have succeeded. */
+ − 2725 if (rtnval == -1 && did_retry && errno == EBADF)
+ − 2726 return 0;
+ − 2727
+ − 2728 return rtnval;
+ − 2729 #else
+ − 2730 return close (filedes);
+ − 2731 #endif
+ − 2732 }
771
+ − 2733
+ − 2734 static ssize_t
+ − 2735 retry_read_1 (int fildes, void *buf, size_t nbyte, int allow_quit)
428
+ − 2736 {
+ − 2737 ssize_t rtnval;
+ − 2738
+ − 2739 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */
+ − 2740 while ((rtnval = read (fildes, buf, nbyte)) == -1
+ − 2741 && (errno == EINTR))
+ − 2742 {
+ − 2743 if (allow_quit)
853
+ − 2744 QUIT;
428
+ − 2745 }
+ − 2746 return rtnval;
+ − 2747 }
+ − 2748
+ − 2749 ssize_t
771
+ − 2750 retry_read (int fildes, void *buf, size_t nbyte)
428
+ − 2751 {
771
+ − 2752 return retry_read_1 (fildes, buf, nbyte, 0);
428
+ − 2753 }
771
+ − 2754
+ − 2755 static ssize_t
+ − 2756 retry_write_1 (int fildes, const void *buf, size_t nbyte, int allow_quit)
428
+ − 2757 {
+ − 2758 ssize_t bytes_written = 0;
442
+ − 2759 const char *b = (const char *) buf;
428
+ − 2760
+ − 2761 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */
+ − 2762 while (nbyte > 0)
+ − 2763 {
+ − 2764 ssize_t rtnval = write (fildes, b, nbyte);
+ − 2765
+ − 2766 if (allow_quit)
853
+ − 2767 QUIT;
428
+ − 2768
+ − 2769 if (rtnval == -1)
+ − 2770 {
+ − 2771 if (errno == EINTR)
+ − 2772 continue;
+ − 2773 else
+ − 2774 return bytes_written ? bytes_written : -1;
+ − 2775 }
+ − 2776 b += rtnval;
+ − 2777 nbyte -= rtnval;
+ − 2778 bytes_written += rtnval;
+ − 2779 }
+ − 2780 return bytes_written;
+ − 2781 }
+ − 2782
+ − 2783 ssize_t
771
+ − 2784 retry_write (int fildes, const void *buf, size_t nbyte)
428
+ − 2785 {
771
+ − 2786 return retry_write_1 (fildes, buf, nbyte, 0);
428
+ − 2787 }
771
+ − 2788
+ − 2789 /* Versions of read() and write() that allow quitting out of the actual
+ − 2790 I/O. We don't use immediate_quit (i.e. direct longjmp() out of the
+ − 2791 signal handler) because that's way too losing.
+ − 2792
+ − 2793 (#### Actually, longjmp()ing out of the signal handler may not be
+ − 2794 as losing as I thought. See qxe_reliable_signal() in sysdep.c.) */
+ − 2795
+ − 2796 Bytecount
+ − 2797 read_allowing_quit (int fildes, void *buf, Bytecount size)
+ − 2798 {
+ − 2799 QUIT;
+ − 2800 return retry_read_1 (fildes, buf, size, 1);
+ − 2801 }
+ − 2802
+ − 2803 Bytecount
+ − 2804 write_allowing_quit (int fildes, const void *buf, Bytecount size)
+ − 2805 {
+ − 2806 QUIT;
+ − 2807 return retry_write_1 (fildes, buf, size, 1);
+ − 2808 }
428
+ − 2809
+ − 2810
+ − 2811 /**************** stdio calls ****************/
+ − 2812
+ − 2813 /* There is at least some evidence that the stdio calls are interruptible
+ − 2814 just like the normal system calls, at least on some systems. In any
+ − 2815 case, it doesn't hurt to encapsulate them. */
+ − 2816
+ − 2817 /* #### Should also encapsulate fflush().
+ − 2818 #### Should conceivably encapsulate getchar() etc. What a pain! */
+ − 2819
+ − 2820 FILE *
2367
+ − 2821 retry_fopen (const Extbyte *path, const Ascbyte *mode)
428
+ − 2822 {
771
+ − 2823 #ifdef WIN32_NATIVE
+ − 2824 int fd;
+ − 2825 int oflag;
2367
+ − 2826 const Ascbyte *mode_save = mode;
771
+ − 2827
+ − 2828 /* Force all file handles to be non-inheritable. This is necessary to
+ − 2829 ensure child processes don't unwittingly inherit handles that might
+ − 2830 prevent future file access. */
+ − 2831
+ − 2832 if (mode[0] == 'r')
+ − 2833 oflag = O_RDONLY;
+ − 2834 else if (mode[0] == 'w' || mode[0] == 'a')
+ − 2835 oflag = O_WRONLY | O_CREAT | O_TRUNC;
+ − 2836 else
+ − 2837 return NULL;
+ − 2838
+ − 2839 /* Only do simplistic option parsing. */
+ − 2840 while (*++mode)
+ − 2841 if (mode[0] == '+')
+ − 2842 {
+ − 2843 oflag &= ~(O_RDONLY | O_WRONLY);
+ − 2844 oflag |= O_RDWR;
+ − 2845 }
+ − 2846 else if (mode[0] == 'b')
+ − 2847 {
+ − 2848 oflag &= ~O_TEXT;
+ − 2849 oflag |= O_BINARY;
+ − 2850 }
+ − 2851 else if (mode[0] == 't')
+ − 2852 {
+ − 2853 oflag &= ~O_BINARY;
+ − 2854 oflag |= O_TEXT;
+ − 2855 }
+ − 2856 else break;
+ − 2857
+ − 2858 fd = underlying_open (path, oflag, 0644);
+ − 2859 if (fd < 0)
+ − 2860 return NULL;
+ − 2861
+ − 2862 return _fdopen (fd, mode_save);
428
+ − 2863 #elif defined (INTERRUPTIBLE_OPEN)
+ − 2864 {
+ − 2865 FILE *rtnval;
771
+ − 2866 while (!(rtnval = fopen (path, mode)) && (errno == EINTR))
428
+ − 2867 DO_NOTHING;
+ − 2868 return rtnval;
+ − 2869 }
+ − 2870 #else
771
+ − 2871 return fopen (path, mode);
+ − 2872 #endif /* defined (INTERRUPTIBLE_OPEN) */
428
+ − 2873 }
771
+ − 2874
+ − 2875 FILE *
2367
+ − 2876 qxe_fopen (const Ibyte *path, const Ascbyte *mode)
771
+ − 2877 {
+ − 2878 Extbyte *pathout;
+ − 2879 PATHNAME_CONVERT_OUT (path, pathout);
+ − 2880 return retry_fopen (pathout, mode);
+ − 2881 }
+ − 2882
428
+ − 2883 int
771
+ − 2884 retry_fclose (FILE *stream)
428
+ − 2885 {
+ − 2886 #ifdef INTERRUPTIBLE_CLOSE
+ − 2887 int rtnval;
+ − 2888
+ − 2889 while ((rtnval = fclose (stream)) == EOF
+ − 2890 && (errno == EINTR))
+ − 2891 ;
+ − 2892 return rtnval;
+ − 2893 #else
+ − 2894 return fclose (stream);
+ − 2895 #endif
+ − 2896 }
771
+ − 2897
428
+ − 2898 size_t
771
+ − 2899 retry_fread (void *ptr, size_t size, size_t nitem, FILE *stream)
428
+ − 2900 {
+ − 2901 #ifdef INTERRUPTIBLE_IO
+ − 2902 size_t rtnval;
+ − 2903 size_t items_read = 0;
+ − 2904 char *b = (char *) ptr;
+ − 2905
+ − 2906 while (nitem > 0)
+ − 2907 {
+ − 2908 rtnval = fread (b, size, nitem, stream);
+ − 2909 if (rtnval == 0)
+ − 2910 {
+ − 2911 if (ferror (stream) && errno == EINTR)
+ − 2912 continue;
+ − 2913 else
+ − 2914 return items_read;
+ − 2915 }
+ − 2916 b += size*rtnval;
+ − 2917 nitem -= rtnval;
+ − 2918 items_read += rtnval;
+ − 2919 }
+ − 2920 return (items_read);
+ − 2921 #else
+ − 2922 return fread (ptr, size, nitem, stream);
+ − 2923 #endif
+ − 2924 }
771
+ − 2925
428
+ − 2926 size_t
771
+ − 2927 retry_fwrite (const void *ptr, size_t size, size_t nitem, FILE *stream)
428
+ − 2928 {
+ − 2929 #ifdef INTERRUPTIBLE_IO
+ − 2930 size_t rtnval;
+ − 2931 size_t items_written = 0;
442
+ − 2932 const char *b = (const char *) ptr;
428
+ − 2933
+ − 2934 while (nitem > 0)
+ − 2935 {
+ − 2936 rtnval = fwrite (b, size, nitem, stream);
+ − 2937 if (rtnval == 0)
+ − 2938 {
+ − 2939 if (ferror (stream) && errno == EINTR)
+ − 2940 continue;
+ − 2941 else
+ − 2942 return items_written;
+ − 2943 }
+ − 2944 b += size*rtnval;
+ − 2945 nitem -= rtnval;
+ − 2946 items_written += rtnval;
+ − 2947 }
+ − 2948 return (items_written);
+ − 2949 #else
+ − 2950 return fwrite (ptr, size, nitem, stream);
+ − 2951 #endif
+ − 2952 }
+ − 2953
+ − 2954 /********************* directory calls *******************/
+ − 2955
+ − 2956 int
867
+ − 2957 qxe_chdir (const Ibyte *path)
428
+ − 2958 {
771
+ − 2959 Extbyte *pathout;
+ − 2960 PATHNAME_CONVERT_OUT (path, pathout);
442
+ − 2961 #ifdef WIN32_NATIVE
771
+ − 2962 if (XEUNICODE_P)
+ − 2963 return _wchdir ((const wchar_t *) pathout);
+ − 2964 else
+ − 2965 return _chdir (pathout);
428
+ − 2966 #else
771
+ − 2967 return chdir (pathout);
428
+ − 2968 #endif
+ − 2969 }
771
+ − 2970
+ − 2971 int
2340
+ − 2972 qxe_mkdir (const Ibyte *path,
+ − 2973 #ifdef WIN32_NATIVE
+ − 2974 mode_t UNUSED (mode)
+ − 2975 #else
+ − 2976 mode_t mode
+ − 2977 #endif
+ − 2978 )
771
+ − 2979 {
+ − 2980 Extbyte *pathout;
+ − 2981 PATHNAME_CONVERT_OUT (path, pathout);
+ − 2982 #ifdef WIN32_NATIVE
+ − 2983 if (XEUNICODE_P)
+ − 2984 return _wmkdir ((const wchar_t *) pathout);
+ − 2985 else
+ − 2986 return _mkdir (pathout);
+ − 2987 #else
+ − 2988 return mkdir (pathout, mode);
+ − 2989 #endif
+ − 2990 }
+ − 2991
428
+ − 2992 DIR *
867
+ − 2993 qxe_opendir (const Ibyte *filename)
428
+ − 2994 {
771
+ − 2995 #ifdef WIN32_NATIVE
+ − 2996 return mswindows_opendir (filename);
+ − 2997 #else
428
+ − 2998 DIR *rtnval;
771
+ − 2999 Extbyte *pathout;
+ − 3000 PATHNAME_CONVERT_OUT (filename, pathout);
+ − 3001
+ − 3002 while (!(rtnval = opendir (pathout))
428
+ − 3003 && (errno == EINTR))
+ − 3004 ;
+ − 3005 return rtnval;
771
+ − 3006 #endif /* WIN32_NATIVE */
428
+ − 3007 }
771
+ − 3008
428
+ − 3009 DIRENTRY *
771
+ − 3010 qxe_readdir (DIR *dirp)
428
+ − 3011 {
771
+ − 3012 #ifdef WIN32_NATIVE
+ − 3013 return mswindows_readdir (dirp);
+ − 3014 #else /* not WIN32_NATIVE */
428
+ − 3015 DIRENTRY *rtnval;
+ − 3016
+ − 3017 /* Apparently setting errno is necessary on some systems?
+ − 3018 Maybe readdir() doesn't always set errno ?! */
+ − 3019 while (!(errno = 0, rtnval = readdir (dirp))
+ − 3020 && (errno == EINTR))
+ − 3021 ;
+ − 3022 #ifndef MULE
+ − 3023 return rtnval;
+ − 3024 #else /* MULE */
+ − 3025 if (rtnval == NULL) /* End of directory */
+ − 3026 return NULL;
+ − 3027 {
442
+ − 3028 const Extbyte * const external_name = (const Extbyte *) rtnval->d_name;
665
+ − 3029 Bytecount external_len = strlen (rtnval->d_name);
867
+ − 3030 const Ibyte *internal_name;
462
+ − 3031 Bytecount internal_len;
513
+ − 3032
462
+ − 3033 TO_INTERNAL_FORMAT (DATA, (external_name, external_len),
+ − 3034 ALLOCA, (internal_name, internal_len),
+ − 3035 Qfile_name);
+ − 3036
+ − 3037 /* check for common case of ASCII filename */
+ − 3038 if (internal_len == external_len &&
+ − 3039 !memcmp (external_name, internal_name, internal_len))
428
+ − 3040 return rtnval;
+ − 3041
+ − 3042 { /* Non-ASCII filename */
867
+ − 3043 static Ibyte_dynarr *internal_DIRENTRY;
428
+ − 3044 if (!internal_DIRENTRY)
867
+ − 3045 internal_DIRENTRY = Dynarr_new (Ibyte);
428
+ − 3046 else
+ − 3047 Dynarr_reset (internal_DIRENTRY);
+ − 3048
867
+ − 3049 Dynarr_add_many (internal_DIRENTRY, (Ibyte *) rtnval,
428
+ − 3050 offsetof (DIRENTRY, d_name));
+ − 3051
+ − 3052
+ − 3053 Dynarr_add_many (internal_DIRENTRY, internal_name, internal_len);
444
+ − 3054 Dynarr_add (internal_DIRENTRY, '\0'); /* NUL-terminate */
428
+ − 3055 return (DIRENTRY *) Dynarr_atp (internal_DIRENTRY, 0);
+ − 3056 }
+ − 3057 }
+ − 3058 #endif /* MULE */
771
+ − 3059 #endif /* WIN32_NATIVE */
428
+ − 3060 }
771
+ − 3061
428
+ − 3062 int
771
+ − 3063 qxe_closedir (DIR *dirp)
428
+ − 3064 {
771
+ − 3065 #ifdef WIN32_NATIVE
+ − 3066 return mswindows_closedir (dirp);
+ − 3067 #else /* not WIN32_NATIVE */
428
+ − 3068 int rtnval;
+ − 3069
+ − 3070 while ((rtnval = closedir (dirp)) == -1
+ − 3071 && (errno == EINTR))
+ − 3072 ;
+ − 3073 return rtnval;
771
+ − 3074 #endif /* WIN32_NATIVE */
428
+ − 3075 }
771
+ − 3076
428
+ − 3077 int
867
+ − 3078 qxe_rmdir (const Ibyte *path)
771
+ − 3079 {
+ − 3080 Extbyte *pathout;
+ − 3081 PATHNAME_CONVERT_OUT (path, pathout);
+ − 3082 #ifdef WIN32_NATIVE
+ − 3083 if (XEUNICODE_P)
+ − 3084 return _wrmdir ((const wchar_t *) pathout);
+ − 3085 else
+ − 3086 return _rmdir (pathout);
+ − 3087 #else
+ − 3088 return rmdir (pathout);
+ − 3089 #endif
+ − 3090 }
+ − 3091
867
+ − 3092 Ibyte *
771
+ − 3093 qxe_allocating_getcwd (void)
428
+ − 3094 {
771
+ − 3095 #ifdef HAVE_GETCWD
+ − 3096 Bytecount cwdsize = 1024;
+ − 3097 Extbyte *cwd = xnew_array (Extbyte, cwdsize);
+ − 3098
+ − 3099 /* Many getcwd()'s can take a NULL argument and malloc() the right amount
+ − 3100 of data, but this is non-standard. */
+ − 3101 while (1)
+ − 3102 {
+ − 3103 #ifdef WIN32_NATIVE
+ − 3104 Extbyte *ret;
+ − 3105
+ − 3106 if (XEUNICODE_P)
+ − 3107 ret = (Extbyte *) _wgetcwd ((wchar_t *) cwd,
+ − 3108 cwdsize / sizeof (wchar_t));
+ − 3109 else
+ − 3110 ret = _getcwd (cwd, cwdsize);
+ − 3111
+ − 3112 if (ret)
+ − 3113 {
867
+ − 3114 Ibyte *retin;
771
+ − 3115 TSTR_TO_C_STRING_MALLOC (ret, retin);
1726
+ − 3116 xfree (cwd, Extbyte *);
771
+ − 3117 return retin;
+ − 3118 }
+ − 3119 #else
+ − 3120 Extbyte *ret = getcwd (cwd, cwdsize);
+ − 3121 if (ret)
+ − 3122 {
867
+ − 3123 Ibyte *retin;
771
+ − 3124 EXTERNAL_TO_C_STRING_MALLOC (ret, retin, Qfile_name);
1726
+ − 3125 xfree (cwd, Extbyte *);
771
+ − 3126 return retin;
+ − 3127 }
+ − 3128 #endif /* WIN32_NATIVE */
+ − 3129
+ − 3130 if (errno == ERANGE)
+ − 3131 {
+ − 3132 cwdsize *= 2;
+ − 3133 XREALLOC_ARRAY (cwd, Extbyte, cwdsize);
+ − 3134 }
+ − 3135 else
+ − 3136 {
1726
+ − 3137 xfree (cwd, Extbyte *);
771
+ − 3138 return NULL;
+ − 3139 }
+ − 3140 }
+ − 3141 #else
+ − 3142 Extbyte chingame_limitos_arbitrarios[PATH_MAX];
867
+ − 3143 Ibyte *ret2;
771
+ − 3144
+ − 3145 if (!getwd (chingame_limitos_arbitrarios))
+ − 3146 return 0;
+ − 3147 EXTERNAL_TO_C_STRING_MALLOC (chingame_limitos_arbitrarios, ret2, Qfile_name);
+ − 3148 return ret2;
+ − 3149 #endif /* HAVE_GETCWD */
428
+ − 3150 }
+ − 3151
+ − 3152 /***************** file-information calls ******************/
+ − 3153
+ − 3154 int
867
+ − 3155 qxe_access (const Ibyte *path, int mode)
428
+ − 3156 {
771
+ − 3157 #ifdef WIN32_NATIVE
+ − 3158 return mswindows_access (path, mode);
+ − 3159 #else /* not WIN32_NATIVE */
+ − 3160 Extbyte *pathout;
+ − 3161 PATHNAME_CONVERT_OUT (path, pathout);
+ − 3162 return access (pathout, mode);
+ − 3163 #endif /* WIN32_NATIVE */
428
+ − 3164 }
771
+ − 3165
+ − 3166 #if defined (HAVE_EACCESS)
428
+ − 3167 int
867
+ − 3168 qxe_eaccess (const Ibyte *path, int mode)
428
+ − 3169 {
771
+ − 3170 Extbyte *pathout;
+ − 3171 PATHNAME_CONVERT_OUT (path, pathout);
+ − 3172 return eaccess (pathout, mode);
428
+ − 3173 }
771
+ − 3174 #endif /* defined (HAVE_EACCESS) */
+ − 3175
428
+ − 3176 int
867
+ − 3177 qxe_lstat (const Ibyte *path, struct stat *buf)
428
+ − 3178 {
771
+ − 3179 /* if system does not have symbolic links, it does not have lstat.
+ − 3180 In that case, use ordinary stat instead. */
+ − 3181 #ifndef S_IFLNK
+ − 3182 return qxe_stat (path, buf);
+ − 3183 #else
+ − 3184 Extbyte *pathout;
+ − 3185 PATHNAME_CONVERT_OUT (path, pathout);
+ − 3186 return lstat (pathout, buf);
+ − 3187 #endif
428
+ − 3188 }
771
+ − 3189
+ − 3190 #if defined (HAVE_READLINK)
428
+ − 3191 int
867
+ − 3192 qxe_readlink (const Ibyte *path, Ibyte *buf, size_t bufsiz)
428
+ − 3193 {
771
+ − 3194 int retval;
+ − 3195 Extbyte *pathout;
+ − 3196
+ − 3197 PATHNAME_CONVERT_OUT (path, pathout);
+ − 3198 retval = readlink (pathout, (char *) buf, bufsiz);
+ − 3199 if (retval < 0)
+ − 3200 return retval;
+ − 3201 {
867
+ − 3202 Ibyte *intbuf;
771
+ − 3203 Bytecount tamanho;
+ − 3204
+ − 3205 TO_INTERNAL_FORMAT (DATA, (buf, retval),
+ − 3206 ALLOCA, (intbuf, tamanho), Qfile_name);
+ − 3207 /* the man page says this function does not null-terminate */
+ − 3208 if (tamanho >= (Bytecount) bufsiz)
+ − 3209 tamanho = bufsiz;
+ − 3210 memcpy (buf, intbuf, tamanho);
+ − 3211 return tamanho;
+ − 3212 }
428
+ − 3213 }
771
+ − 3214 #endif /* defined (HAVE_READLINK) */
+ − 3215
432
+ − 3216 int
771
+ − 3217 qxe_fstat (int fd, struct stat *buf)
432
+ − 3218 {
442
+ − 3219 #ifdef WIN32_NATIVE
+ − 3220 return mswindows_fstat (fd, buf);
+ − 3221 #else
432
+ − 3222 return fstat (fd, buf);
771
+ − 3223 #endif /* WIN32_NATIVE */
432
+ − 3224 }
+ − 3225
428
+ − 3226 int
867
+ − 3227 qxe_stat (const Ibyte *path, struct stat *buf)
428
+ − 3228 {
442
+ − 3229 #ifdef WIN32_NATIVE
+ − 3230 return mswindows_stat (path, buf);
771
+ − 3231 #else /* not WIN32_NATIVE */
+ − 3232 Extbyte *pathout;
+ − 3233 PATHNAME_CONVERT_OUT (path, pathout);
+ − 3234 return stat (pathout, buf);
+ − 3235 #endif /* WIN32_NATIVE */
428
+ − 3236 }
+ − 3237
771
+ − 3238
428
+ − 3239 /****************** file-manipulation calls *****************/
+ − 3240
+ − 3241 int
867
+ − 3242 qxe_chmod (const Ibyte *path, mode_t mode)
428
+ − 3243 {
771
+ − 3244 Extbyte *pathout;
+ − 3245 PATHNAME_CONVERT_OUT (path, pathout);
+ − 3246 #ifdef WIN32_NATIVE
+ − 3247 if (XEUNICODE_P)
+ − 3248 return _wchmod ((const wchar_t *) pathout, mode);
+ − 3249 else
+ − 3250 return _chmod (pathout, mode);
+ − 3251 #else
+ − 3252 return chmod (pathout, mode);
+ − 3253 #endif
428
+ − 3254 }
771
+ − 3255
+ − 3256 #if defined (HAVE_LINK)
428
+ − 3257 int
867
+ − 3258 qxe_link (const Ibyte *existing, const Ibyte *new)
428
+ − 3259 {
771
+ − 3260 #ifdef WIN32_NATIVE
+ − 3261 return mswindows_link (existing, new);
+ − 3262 #else /* not WIN32_NATIVE */
+ − 3263 Extbyte *existingout, *newout;
+ − 3264 PATHNAME_CONVERT_OUT (existing, existingout);
+ − 3265 PATHNAME_CONVERT_OUT (new, newout);
+ − 3266 return link (existingout, newout);
+ − 3267 #endif /* WIN32_NATIVE */
428
+ − 3268 }
771
+ − 3269 #endif /* defined (HAVE_LINK) */
+ − 3270
428
+ − 3271 int
867
+ − 3272 qxe_rename (const Ibyte *old, const Ibyte *new)
428
+ − 3273 {
442
+ − 3274 #ifdef WIN32_NATIVE
872
+ − 3275 return mswindows_rename (old, new);
771
+ − 3276 #else /* not WIN32_NATIVE */
+ − 3277 Extbyte *oldout, *newout;
+ − 3278 PATHNAME_CONVERT_OUT (old, oldout);
+ − 3279 PATHNAME_CONVERT_OUT (new, newout);
+ − 3280 return rename (oldout, newout);
442
+ − 3281 #endif /* WIN32_NATIVE */
428
+ − 3282 }
771
+ − 3283
+ − 3284 #if defined (HAVE_SYMLINK)
428
+ − 3285 int
867
+ − 3286 qxe_symlink (const Ibyte *name1, const Ibyte *name2)
428
+ − 3287 {
771
+ − 3288 Extbyte *name1out, *name2out;
+ − 3289 PATHNAME_CONVERT_OUT (name1, name1out);
+ − 3290 PATHNAME_CONVERT_OUT (name2, name2out);
+ − 3291 return symlink (name1out, name2out);
428
+ − 3292 }
771
+ − 3293 #endif /* defined (HAVE_SYMLINK) */
+ − 3294
428
+ − 3295 int
867
+ − 3296 qxe_unlink (const Ibyte *path)
428
+ − 3297 {
771
+ − 3298 #ifdef WIN32_NATIVE
+ − 3299 return mswindows_unlink (path);
+ − 3300 #else /* not WIN32_NATIVE */
+ − 3301 Extbyte *pathout;
+ − 3302 PATHNAME_CONVERT_OUT (path, pathout);
+ − 3303 return unlink (pathout);
+ − 3304 #endif /* WIN32_NATIVE */
428
+ − 3305 }
771
+ − 3306
+ − 3307
+ − 3308 /****************** process calls *****************/
+ − 3309
428
+ − 3310 int
867
+ − 3311 qxe_execve (const Ibyte *filename, Ibyte * const argv[],
+ − 3312 Ibyte * const envp[])
428
+ − 3313 {
771
+ − 3314 int i, argc, envc;
+ − 3315 Extbyte *pathext;
+ − 3316 Extbyte **new_argv;
+ − 3317 Extbyte **new_envp;
+ − 3318
+ − 3319 PATHNAME_CONVERT_OUT (filename, pathext);
+ − 3320
428
+ − 3321 for (argc = 0; argv[argc]; argc++)
+ − 3322 ;
771
+ − 3323 new_argv = alloca_array (Extbyte *, argc + 1);
428
+ − 3324 for (i = 0; i < argc; i++)
771
+ − 3325 C_STRING_TO_EXTERNAL (argv[i], new_argv[i], Qnative);
428
+ − 3326 new_argv[argc] = NULL;
771
+ − 3327
+ − 3328 for (envc = 0; envp[envc]; envc++)
+ − 3329 ;
+ − 3330 new_envp = alloca_array (Extbyte *, envc + 1);
+ − 3331 for (i = 0; i < envc; i++)
+ − 3332 C_STRING_TO_EXTERNAL (envp[i], new_envp[i], Qnative);
+ − 3333 new_envp[envc] = NULL;
+ − 3334
1318
+ − 3335 #if defined (WIN32_NATIVE)
+ − 3336 if (XEUNICODE_P)
+ − 3337 return _wexecve ((const wchar_t *) pathext,
+ − 3338 (const wchar_t * const *) new_argv,
+ − 3339 (const wchar_t * const *) new_envp);
+ − 3340 #endif
771
+ − 3341 return execve (pathext, new_argv, new_envp);
+ − 3342 }
+ − 3343
+ − 3344 pid_t
+ − 3345 qxe_getpid (void)
+ − 3346 {
+ − 3347 #ifdef WIN32_NATIVE
+ − 3348 return abs (getpid ());
+ − 3349 #else
+ − 3350 return getpid ();
+ − 3351 #endif
428
+ − 3352 }
771
+ − 3353
+ − 3354
+ − 3355 /****************** passwd calls *****************/
+ − 3356
+ − 3357 struct passwd cached_pwd;
+ − 3358
+ − 3359 static struct passwd *
+ − 3360 copy_in_passwd (struct passwd *pwd)
+ − 3361 {
+ − 3362 if (!pwd)
+ − 3363 return NULL;
+ − 3364
+ − 3365 if (cached_pwd.pw_name)
1726
+ − 3366 xfree (cached_pwd.pw_name, char *);
771
+ − 3367 if (cached_pwd.pw_passwd)
1726
+ − 3368 xfree (cached_pwd.pw_passwd, char *);
771
+ − 3369 if (cached_pwd.pw_gecos)
1726
+ − 3370 xfree (cached_pwd.pw_gecos, char *);
771
+ − 3371 if (cached_pwd.pw_dir)
1726
+ − 3372 xfree (cached_pwd.pw_dir, char *);
771
+ − 3373 if (cached_pwd.pw_shell)
1726
+ − 3374 xfree (cached_pwd.pw_shell, char *);
771
+ − 3375
+ − 3376 cached_pwd = *pwd;
+ − 3377 if (cached_pwd.pw_name)
+ − 3378 TO_INTERNAL_FORMAT (C_STRING, cached_pwd.pw_name,
+ − 3379 C_STRING_MALLOC, cached_pwd.pw_name, Qnative);
+ − 3380 if (cached_pwd.pw_passwd)
+ − 3381 TO_INTERNAL_FORMAT (C_STRING, cached_pwd.pw_passwd,
+ − 3382 C_STRING_MALLOC, cached_pwd.pw_passwd, Qnative);
+ − 3383 if (cached_pwd.pw_gecos)
+ − 3384 TO_INTERNAL_FORMAT (C_STRING, cached_pwd.pw_gecos,
+ − 3385 C_STRING_MALLOC, cached_pwd.pw_gecos, Qnative);
+ − 3386 if (cached_pwd.pw_dir)
+ − 3387 TO_INTERNAL_FORMAT (C_STRING, cached_pwd.pw_dir,
+ − 3388 C_STRING_MALLOC, cached_pwd.pw_dir, Qfile_name);
+ − 3389 if (cached_pwd.pw_shell)
+ − 3390 TO_INTERNAL_FORMAT (C_STRING, cached_pwd.pw_shell,
+ − 3391 C_STRING_MALLOC, cached_pwd.pw_shell, Qfile_name);
+ − 3392 return &cached_pwd;
+ − 3393 }
+ − 3394
+ − 3395 struct passwd *
867
+ − 3396 qxe_getpwnam (const Ibyte *name)
771
+ − 3397 {
+ − 3398 #ifdef WIN32_NATIVE
+ − 3399 /* Synthetic versions are defined in nt.c and already do conversion. */
+ − 3400 return getpwnam (name);
+ − 3401 #else
+ − 3402 Extbyte *nameext;
+ − 3403 C_STRING_TO_EXTERNAL (name, nameext, Qnative);
+ − 3404
+ − 3405 return copy_in_passwd (getpwnam (nameext));
+ − 3406 #endif /* WIN32_NATIVE */
+ − 3407 }
+ − 3408
+ − 3409 struct passwd *
+ − 3410 qxe_getpwuid (uid_t uid)
+ − 3411 {
+ − 3412 #ifdef WIN32_NATIVE
+ − 3413 /* Synthetic versions are defined in nt.c and already do conversion. */
+ − 3414 return getpwuid (uid);
+ − 3415 #else
+ − 3416 return copy_in_passwd (getpwuid (uid));
+ − 3417 #endif /* WIN32_NATIVE */
+ − 3418 }
+ − 3419
+ − 3420 #ifndef WIN32_NATIVE
+ − 3421
+ − 3422 struct passwd *
+ − 3423 qxe_getpwent (void)
+ − 3424 {
+ − 3425 /* No WIN32_NATIVE version of this. */
+ − 3426 return copy_in_passwd (getpwent ());
+ − 3427 }
+ − 3428
+ − 3429 #endif /* not WIN32_NATIVE */
+ − 3430
+ − 3431 /****************** time calls *****************/
+ − 3432
867
+ − 3433 static Ibyte *ctime_static;
+ − 3434
+ − 3435 Ibyte *
771
+ − 3436 qxe_ctime (const time_t *t)
+ − 3437 {
+ − 3438 Extbyte *str = (Extbyte *) ctime (t);
+ − 3439 if (!str) /* can happen on MS Windows */
867
+ − 3440 return (Ibyte *) "Sun Jan 01 00:00:00 1970";
771
+ − 3441 if (ctime_static)
1726
+ − 3442 xfree (ctime_static, Ibyte *);
771
+ − 3443 EXTERNAL_TO_C_STRING_MALLOC (str, ctime_static, Qnative);
+ − 3444 return ctime_static;
+ − 3445 }
428
+ − 3446
1204
+ − 3447
912
+ − 3448 /************************************************************************/
+ − 3449 /* Emulation of missing functions from wchar.h */
+ − 3450 /************************************************************************/
+ − 3451
+ − 3452 #ifndef HAVE_WCHAR_H
+ − 3453 size_t
2367
+ − 3454 wcslen (const wchar_t *s)
912
+ − 3455 {
+ − 3456 const wchar_t *p = s;
+ − 3457
+ − 3458 while (*p++)
+ − 3459 ;
+ − 3460
+ − 3461 return p - s;
+ − 3462 }
+ − 3463 #endif
1204
+ − 3464
+ − 3465 /************************************************************************/
+ − 3466 /* Emulation of missing functions from string.h */
+ − 3467 /************************************************************************/
+ − 3468
+ − 3469 #ifndef HAVE_STRLWR
+ − 3470 char *
+ − 3471 strlwr (char *s)
+ − 3472 {
1271
+ − 3473 REGISTER char *c;
+ − 3474
+ − 3475 for (c = s; *c; c++)
1204
+ − 3476 {
1271
+ − 3477 *c = tolower (*c);
1204
+ − 3478 }
1271
+ − 3479 return s;
1204
+ − 3480 }
+ − 3481 #endif
+ − 3482
1271
+ − 3483 #ifndef HAVE_STRUPR
1204
+ − 3484 char *
+ − 3485 strupr (char *s)
+ − 3486 {
1271
+ − 3487 REGISTER char *c;
+ − 3488
+ − 3489 for (c = s; *c; c++)
1204
+ − 3490 {
1271
+ − 3491 *c = toupper (*c);
1204
+ − 3492 }
1271
+ − 3493 return s;
1204
+ − 3494 }
+ − 3495 #endif
912
+ − 3496
428
+ − 3497
+ − 3498 /************************************************************************/
+ − 3499 /* Emulations of missing system calls */
+ − 3500 /************************************************************************/
+ − 3501
+ − 3502 /***** (these are primarily required for USG, it seems) *****/
+ − 3503
+ − 3504 /*
+ − 3505 * Emulate rename using unlink/link. Note that this is
+ − 3506 * only partially correct. Also, doesn't enforce restriction
+ − 3507 * that files be of same type (regular->regular, dir->dir, etc).
+ − 3508 */
+ − 3509
+ − 3510 #ifndef HAVE_RENAME
+ − 3511 int
771
+ − 3512 rename (const Extbyte *from, const Extbyte *to)
428
+ − 3513 {
+ − 3514 if (access (from, 0) == 0)
+ − 3515 {
+ − 3516 unlink (to);
+ − 3517 if (link (from, to) == 0)
+ − 3518 if (unlink (from) == 0)
+ − 3519 return (0);
+ − 3520 }
+ − 3521 return (-1);
+ − 3522 }
+ − 3523 #endif /* HAVE_RENAME */
+ − 3524
+ − 3525 #ifdef HPUX
+ − 3526 #ifndef HAVE_PERROR
+ − 3527
+ − 3528 /* HPUX curses library references perror, but as far as we know
+ − 3529 it won't be called. Anyway this definition will do for now. */
+ − 3530
+ − 3531 perror (void)
+ − 3532 {
+ − 3533 }
+ − 3534
+ − 3535 #endif /* not HAVE_PERROR */
+ − 3536 #endif /* HPUX */
+ − 3537
+ − 3538 #ifndef HAVE_DUP2
+ − 3539
+ − 3540 /*
+ − 3541 * Emulate BSD dup2. First close newd if it already exists.
+ − 3542 * Then, attempt to dup oldd. If not successful, call dup2 recursively
+ − 3543 * until we are, then close the unsuccessful ones.
+ − 3544 */
+ − 3545
+ − 3546 int
+ − 3547 dup2 (int oldd, int newd)
+ − 3548 {
+ − 3549 int fd, ret;
+ − 3550
771
+ − 3551 retry_close (newd);
428
+ − 3552
+ − 3553 #ifdef F_DUPFD
+ − 3554 fd = fcntl (oldd, F_DUPFD, newd);
+ − 3555 if (fd != newd)
563
+ − 3556 signal_ferror_with_frob (Qfile_error, lisp_strerror (errno),
+ − 3557 "can't dup2 (%i, %i)", oldd, newd);
428
+ − 3558 #else
+ − 3559 fd = dup (old);
+ − 3560 if (fd == -1)
+ − 3561 return -1;
+ − 3562 if (fd == new)
+ − 3563 return new;
+ − 3564 ret = dup2 (old, new);
771
+ − 3565 retry_close (fd);
428
+ − 3566 return ret;
+ − 3567 #endif /* F_DUPFD */
+ − 3568 }
+ − 3569
+ − 3570 #endif /* not HAVE_DUP2 */
+ − 3571
+ − 3572 /*
+ − 3573 * Gettimeofday. Simulate as much as possible. Only accurate
+ − 3574 * to nearest second. Emacs doesn't use tzp so ignore it for now.
+ − 3575 */
+ − 3576
+ − 3577 #if !defined (HAVE_GETTIMEOFDAY)
+ − 3578
+ − 3579 int
+ − 3580 gettimeofday (struct timeval *tp, struct timezone *tzp)
+ − 3581 {
+ − 3582 extern long time ();
+ − 3583
+ − 3584 tp->tv_sec = time ((long *)0);
+ − 3585 tp->tv_usec = 0;
+ − 3586 if (tzp != 0)
+ − 3587 tzp->tz_minuteswest = -1;
+ − 3588 return (0);
+ − 3589 }
+ − 3590
+ − 3591 #endif /* !HAVE_GETTIMEOFDAY */
+ − 3592
+ − 3593 /* No need to encapsulate utime and utimes explicitly because all
+ − 3594 access to those functions goes through the following. */
+ − 3595
+ − 3596 int
2340
+ − 3597 set_file_times (
+ − 3598 #if defined (WIN32_NATIVE) || defined (HAVE_UTIME) || defined (HAVE_UTIMES)
+ − 3599 Lisp_Object path, EMACS_TIME atime, EMACS_TIME mtime
+ − 3600 #else
+ − 3601 Lisp_Object UNUSED (path), EMACS_TIME UNUSED (atime),
+ − 3602 EMACS_TIME UNUSED (mtime)
+ − 3603 #endif
+ − 3604 )
428
+ − 3605 {
592
+ − 3606 #if defined (WIN32_NATIVE)
460
+ − 3607 struct utimbuf utb;
+ − 3608 utb.actime = EMACS_SECS (atime);
+ − 3609 utb.modtime = EMACS_SECS (mtime);
592
+ − 3610 return mswindows_utime (path, &utb);
+ − 3611 #elif defined (HAVE_UTIME)
+ − 3612 struct utimbuf utb;
+ − 3613 Extbyte *filename;
+ − 3614 utb.actime = EMACS_SECS (atime);
+ − 3615 utb.modtime = EMACS_SECS (mtime);
+ − 3616 LISP_STRING_TO_EXTERNAL (path, filename, Qfile_name);
460
+ − 3617 return utime (filename, &utb);
+ − 3618 #elif defined (HAVE_UTIMES)
428
+ − 3619 struct timeval tv[2];
592
+ − 3620 Extbyte *filename;
428
+ − 3621 tv[0] = atime;
+ − 3622 tv[1] = mtime;
592
+ − 3623 LISP_STRING_TO_EXTERNAL (path, filename, Qfile_name);
428
+ − 3624 return utimes (filename, tv);
460
+ − 3625 #else
+ − 3626 /* No file times setting function available. */
+ − 3627 return -1;
+ − 3628 #endif
428
+ − 3629 }
+ − 3630
+ − 3631 /* */
+ − 3632
+ − 3633 static long ticks_per_second;
+ − 3634 static long orig_user_ticks, orig_system_ticks;
+ − 3635 EMACS_TIME orig_real_time;
+ − 3636
+ − 3637 static int process_times_available;
+ − 3638
+ − 3639 /* Return the relative user and system tick count. We try to
+ − 3640 maintain calculations in terms of integers as long as possible
+ − 3641 for increased accuracy. */
+ − 3642
+ − 3643 static int
2340
+ − 3644 get_process_times_1 (
+ − 3645 #if defined (CLOCKS_PER_SEC) || defined (_SC_CLK_TCK) || defined (CLK_TCK) && !defined(WIN32_NATIVE)
+ − 3646 long *user_ticks, long *system_ticks
+ − 3647 #else
+ − 3648 long *UNUSED (user_ticks), long *UNUSED (system_ticks)
+ − 3649 #endif
+ − 3650 )
428
+ − 3651 {
442
+ − 3652 #if defined (_SC_CLK_TCK) || defined (CLK_TCK) && !defined(WIN32_NATIVE)
428
+ − 3653 /* We have the POSIX times() function available. */
777
+ − 3654 /* #### Perhaps we should just use a configure test for times()? */
428
+ − 3655 struct tms tttt;
+ − 3656 times (&tttt);
+ − 3657 *user_ticks = (long) tttt.tms_utime;
+ − 3658 *system_ticks = (long) tttt.tms_stime;
+ − 3659 return 1;
+ − 3660 #elif defined (CLOCKS_PER_SEC)
+ − 3661 *user_ticks = (long) clock ();
+ − 3662 *system_ticks = 0;
+ − 3663 return 1;
+ − 3664 #else
+ − 3665 return 0;
+ − 3666 #endif
+ − 3667 }
+ − 3668
+ − 3669 void
+ − 3670 init_process_times_very_early (void)
+ − 3671 {
+ − 3672 #if defined (_SC_CLK_TCK)
+ − 3673 ticks_per_second = sysconf (_SC_CLK_TCK);
+ − 3674 #elif defined (CLK_TCK)
+ − 3675 ticks_per_second = CLK_TCK;
+ − 3676 #elif defined (CLOCKS_PER_SEC)
+ − 3677 ticks_per_second = CLOCKS_PER_SEC;
+ − 3678 #endif
+ − 3679
+ − 3680 process_times_available = get_process_times_1 (&orig_user_ticks,
+ − 3681 &orig_system_ticks);
+ − 3682 EMACS_GET_TIME (orig_real_time);
+ − 3683 }
+ − 3684
+ − 3685 /* Return the user and system times used up by this process so far. */
+ − 3686 void
+ − 3687 get_process_times (double *user_time, double *system_time, double *real_time)
+ − 3688 {
+ − 3689 EMACS_TIME curr_real_time;
+ − 3690 EMACS_TIME elapsed_time;
+ − 3691 long curr_user_ticks, curr_system_ticks;
+ − 3692
+ − 3693 EMACS_GET_TIME (curr_real_time);
+ − 3694 EMACS_SUB_TIME (elapsed_time, curr_real_time, orig_real_time);
+ − 3695 *real_time = (EMACS_SECS (elapsed_time)
+ − 3696 + ((double) EMACS_USECS (elapsed_time)) / 1000000);
+ − 3697 if (get_process_times_1 (&curr_user_ticks, &curr_system_ticks))
+ − 3698 {
+ − 3699 *user_time = (((double) (curr_user_ticks - orig_user_ticks))
+ − 3700 / ticks_per_second);
+ − 3701 *system_time = (((double) (curr_system_ticks - orig_system_ticks))
+ − 3702 / ticks_per_second);
+ − 3703 }
+ − 3704 else
+ − 3705 {
+ − 3706 /* A lame OS */
+ − 3707 *user_time = *real_time;
+ − 3708 *system_time = 0;
+ − 3709 }
+ − 3710 }
+ − 3711
+ − 3712 #ifndef HAVE_RANDOM
+ − 3713 #ifdef random
+ − 3714 #define HAVE_RANDOM
+ − 3715 #endif
+ − 3716 #endif
+ − 3717
+ − 3718 /* Figure out how many bits the system's random number generator uses.
+ − 3719 `random' and `lrand48' are assumed to return 31 usable bits.
+ − 3720 BSD `rand' returns a 31 bit value but the low order bits are unusable;
+ − 3721 so we'll shift it and treat it like the 15-bit USG `rand'. */
+ − 3722
+ − 3723 #ifndef RAND_BITS
+ − 3724 # ifdef HAVE_RANDOM
+ − 3725 # define RAND_BITS 31
+ − 3726 # else /* !HAVE_RANDOM */
+ − 3727 # ifdef HAVE_LRAND48
+ − 3728 # define RAND_BITS 31
+ − 3729 # define random lrand48
+ − 3730 # else /* !HAVE_LRAND48 */
+ − 3731 # define RAND_BITS 15
+ − 3732 # if RAND_MAX == 32767
+ − 3733 # define random rand
+ − 3734 # else /* RAND_MAX != 32767 */
+ − 3735 # if RAND_MAX == 2147483647
+ − 3736 # define random() (rand () >> 16)
+ − 3737 # else /* RAND_MAX != 2147483647 */
+ − 3738 # ifdef USG
+ − 3739 # define random rand
+ − 3740 # else
+ − 3741 # define random() (rand () >> 16)
+ − 3742 # endif /* !BSD */
+ − 3743 # endif /* RAND_MAX != 2147483647 */
+ − 3744 # endif /* RAND_MAX != 32767 */
+ − 3745 # endif /* !HAVE_LRAND48 */
+ − 3746 # endif /* !HAVE_RANDOM */
+ − 3747 #endif /* !RAND_BITS */
+ − 3748
+ − 3749 void
+ − 3750 seed_random (long arg)
+ − 3751 {
+ − 3752 #ifdef HAVE_RANDOM
+ − 3753 srandom ((unsigned int)arg);
+ − 3754 #else
+ − 3755 # ifdef HAVE_LRAND48
+ − 3756 srand48 (arg);
+ − 3757 # else
+ − 3758 srand ((unsigned int)arg);
+ − 3759 # endif
+ − 3760 #endif
1983
+ − 3761 #ifdef HAVE_BIGNUM
+ − 3762 bignum_random_seed ((unsigned long) arg);
+ − 3763 #endif
428
+ − 3764 }
+ − 3765
+ − 3766 /*
+ − 3767 * Build a full Emacs-sized word out of whatever we've got.
+ − 3768 * This suffices even for a 64-bit architecture with a 15-bit rand.
+ − 3769 */
+ − 3770 long
+ − 3771 get_random (void)
+ − 3772 {
+ − 3773 long val = random ();
2039
+ − 3774 #if INT_VALBITS > RAND_BITS
428
+ − 3775 val = (val << RAND_BITS) ^ random ();
2039
+ − 3776 #if INT_VALBITS > 2*RAND_BITS
428
+ − 3777 val = (val << RAND_BITS) ^ random ();
2039
+ − 3778 #if INT_VALBITS > 3*RAND_BITS
428
+ − 3779 val = (val << RAND_BITS) ^ random ();
2039
+ − 3780 #if INT_VALBITS > 4*RAND_BITS
428
+ − 3781 val = (val << RAND_BITS) ^ random ();
+ − 3782 #endif /* need at least 5 */
+ − 3783 #endif /* need at least 4 */
+ − 3784 #endif /* need at least 3 */
+ − 3785 #endif /* need at least 2 */
2039
+ − 3786 return val & (EMACS_INT) ((1UL << INT_VALBITS) - 1);
428
+ − 3787 }
+ − 3788
+ − 3789
+ − 3790 /************************************************************************/
+ − 3791 /* Strings corresponding to defined signals */
+ − 3792 /************************************************************************/
+ − 3793
+ − 3794 #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST)
+ − 3795
442
+ − 3796 #if defined(WIN32_NATIVE) || defined(CYGWIN)
+ − 3797 const char *sys_siglist[] =
428
+ − 3798 {
771
+ − 3799 /* $$####begin-snarf */
428
+ − 3800 "bum signal!!",
+ − 3801 "hangup",
+ − 3802 "interrupt",
+ − 3803 "quit",
+ − 3804 "illegal instruction",
+ − 3805 "trace trap",
+ − 3806 "iot instruction",
+ − 3807 "emt instruction",
+ − 3808 "floating point exception",
+ − 3809 "kill",
+ − 3810 "bus error",
+ − 3811 "segmentation violation",
+ − 3812 "bad argument to system call",
+ − 3813 "write on a pipe with no one to read it",
+ − 3814 "alarm clock",
+ − 3815 "software termination signal from kill",
+ − 3816 "status signal",
+ − 3817 "sendable stop signal not from tty",
+ − 3818 "stop signal from tty",
+ − 3819 "continue a stopped process",
+ − 3820 "child status has changed",
+ − 3821 "background read attempted from control tty",
+ − 3822 "background write attempted from control tty",
+ − 3823 "input record available at control tty",
+ − 3824 "exceeded CPU time limit",
+ − 3825 "exceeded file size limit"
771
+ − 3826 /* $$####end-snarf */
428
+ − 3827 };
+ − 3828 #endif
+ − 3829
+ − 3830 #ifdef USG
+ − 3831 #ifdef AIX
442
+ − 3832 const char *sys_siglist[NSIG + 1] =
428
+ − 3833 {
+ − 3834 /* AIX has changed the signals a bit */
863
+ − 3835 DEFER_GETTEXT ("bogus signal"), /* 0 */
+ − 3836 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
+ − 3837 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
+ − 3838 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
+ − 3839 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
+ − 3840 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
+ − 3841 DEFER_GETTEXT ("IOT instruction"), /* 6 SIGIOT */
+ − 3842 DEFER_GETTEXT ("crash likely"), /* 7 SIGDANGER */
+ − 3843 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
+ − 3844 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
+ − 3845 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
+ − 3846 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
+ − 3847 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
+ − 3848 DEFER_GETTEXT ("write on a pipe with no one to read it"), /* 13 SIGPIPE */
+ − 3849 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
+ − 3850 DEFER_GETTEXT ("software termination signal"), /* 15 SIGTERM */
+ − 3851 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
+ − 3852 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
+ − 3853 DEFER_GETTEXT ("death of a child"), /* 18 SIGCLD */
+ − 3854 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
+ − 3855 DEFER_GETTEXT ("bogus signal"), /* 20 */
+ − 3856 DEFER_GETTEXT ("bogus signal"), /* 21 */
+ − 3857 DEFER_GETTEXT ("bogus signal"), /* 22 */
+ − 3858 DEFER_GETTEXT ("bogus signal"), /* 23 */
+ − 3859 DEFER_GETTEXT ("bogus signal"), /* 24 */
+ − 3860 DEFER_GETTEXT ("LAN I/O interrupt"), /* 25 SIGAIO */
+ − 3861 DEFER_GETTEXT ("PTY I/O interrupt"), /* 26 SIGPTY */
+ − 3862 DEFER_GETTEXT ("I/O intervention required"), /* 27 SIGIOINT */
428
+ − 3863 #ifdef AIXHFT
771
+ − 3864 "HFT grant", /* 28 SIGGRANT */
+ − 3865 "HFT retract", /* 29 SIGRETRACT */
+ − 3866 "HFT sound done", /* 30 SIGSOUND */
+ − 3867 "HFT input ready", /* 31 SIGMSG */
428
+ − 3868 #endif
771
+ − 3869 /* $$####end-snarf */
428
+ − 3870 0
+ − 3871 };
+ − 3872 #else /* USG, not AIX */
442
+ − 3873 const char *sys_siglist[NSIG + 1] =
428
+ − 3874 {
863
+ − 3875 DEFER_GETTEXT ("bogus signal"), /* 0 */
+ − 3876 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
+ − 3877 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
+ − 3878 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
+ − 3879 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
+ − 3880 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
+ − 3881 DEFER_GETTEXT ("IOT instruction"), /* 6 SIGIOT */
+ − 3882 DEFER_GETTEXT ("EMT instruction"), /* 7 SIGEMT */
+ − 3883 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
+ − 3884 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
+ − 3885 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
+ − 3886 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
+ − 3887 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
+ − 3888 DEFER_GETTEXT ("write on a pipe with no one to read it"), /* 13 SIGPIPE */
+ − 3889 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
+ − 3890 DEFER_GETTEXT ("software termination signal"), /* 15 SIGTERM */
+ − 3891 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
+ − 3892 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
+ − 3893 DEFER_GETTEXT ("death of a child"), /* 18 SIGCLD */
+ − 3894 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
428
+ − 3895 #ifdef sun
771
+ − 3896 "window size changed", /* 20 SIGWINCH */
+ − 3897 "urgent socket condition", /* 21 SIGURG */
+ − 3898 "pollable event occurred", /* 22 SIGPOLL */
+ − 3899 "stop (cannot be caught or ignored)", /* 23 SIGSTOP */
+ − 3900 "user stop requested from tty", /* 24 SIGTSTP */
+ − 3901 "stopped process has been continued", /* 25 SIGCONT */
+ − 3902 "background tty read attempted", /* 26 SIGTTIN */
+ − 3903 "background tty write attempted", /* 27 SIGTTOU */
+ − 3904 "virtual timer expired", /* 28 SIGVTALRM */
+ − 3905 "profiling timer expired", /* 29 SIGPROF */
+ − 3906 "exceeded cpu limit", /* 30 SIGXCPU */
+ − 3907 "exceeded file size limit", /* 31 SIGXFSZ */
+ − 3908 "process's lwps are blocked", /* 32 SIGWAITING */
+ − 3909 "special signal used by thread library", /* 33 SIGLWP */
428
+ − 3910 #ifdef SIGFREEZE
771
+ − 3911 "special signal used by CPR", /* 34 SIGFREEZE */
428
+ − 3912 #endif
+ − 3913 #ifdef SIGTHAW
771
+ − 3914 "special signal used by CPR", /* 35 SIGTHAW */
428
+ − 3915 #endif
+ − 3916 #endif /* sun */
771
+ − 3917 /* $$####end-snarf */
428
+ − 3918 0
+ − 3919 };
+ − 3920 #endif /* not AIX */
+ − 3921 #endif /* USG */
+ − 3922 #ifdef DGUX
442
+ − 3923 const char *sys_siglist[NSIG + 1] =
428
+ − 3924 {
771
+ − 3925 /* $$####begin-snarf */
+ − 3926 "null signal", /* 0 SIGNULL */
+ − 3927 "hangup", /* 1 SIGHUP */
+ − 3928 "interrupt", /* 2 SIGINT */
+ − 3929 "quit", /* 3 SIGQUIT */
+ − 3930 "illegal instruction", /* 4 SIGILL */
+ − 3931 "trace trap", /* 5 SIGTRAP */
+ − 3932 "abort termination", /* 6 SIGABRT */
+ − 3933 "SIGEMT", /* 7 SIGEMT */
+ − 3934 "floating point exception", /* 8 SIGFPE */
+ − 3935 "kill", /* 9 SIGKILL */
+ − 3936 "bus error", /* 10 SIGBUS */
+ − 3937 "segmentation violation", /* 11 SIGSEGV */
+ − 3938 "bad argument to system call", /* 12 SIGSYS */
+ − 3939 "write on a pipe with no reader", /* 13 SIGPIPE */
+ − 3940 "alarm clock", /* 14 SIGALRM */
+ − 3941 "software termination signal", /* 15 SIGTERM */
+ − 3942 "user defined signal 1", /* 16 SIGUSR1 */
+ − 3943 "user defined signal 2", /* 17 SIGUSR2 */
+ − 3944 "child stopped or terminated", /* 18 SIGCLD */
+ − 3945 "power-fail restart", /* 19 SIGPWR */
+ − 3946 "window size changed", /* 20 SIGWINCH */
+ − 3947 "undefined", /* 21 */
+ − 3948 "pollable event occurred", /* 22 SIGPOLL */
+ − 3949 "sendable stop signal not from tty", /* 23 SIGSTOP */
+ − 3950 "stop signal from tty", /* 24 SIGSTP */
+ − 3951 "continue a stopped process", /* 25 SIGCONT */
+ − 3952 "attempted background tty read", /* 26 SIGTTIN */
+ − 3953 "attempted background tty write", /* 27 SIGTTOU */
+ − 3954 "undefined", /* 28 */
+ − 3955 "undefined", /* 29 */
+ − 3956 "undefined", /* 30 */
+ − 3957 "undefined", /* 31 */
+ − 3958 "undefined", /* 32 */
+ − 3959 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
+ − 3960 "I/O is possible", /* 34 SIGIO */
+ − 3961 "exceeded cpu time limit", /* 35 SIGXCPU */
+ − 3962 "exceeded file size limit", /* 36 SIGXFSZ */
+ − 3963 "virtual time alarm", /* 37 SIGVTALRM */
+ − 3964 "profiling time alarm", /* 38 SIGPROF */
+ − 3965 "undefined", /* 39 */
+ − 3966 "file record locks revoked", /* 40 SIGLOST */
+ − 3967 "undefined", /* 41 */
+ − 3968 "undefined", /* 42 */
+ − 3969 "undefined", /* 43 */
+ − 3970 "undefined", /* 44 */
+ − 3971 "undefined", /* 45 */
+ − 3972 "undefined", /* 46 */
+ − 3973 "undefined", /* 47 */
+ − 3974 "undefined", /* 48 */
+ − 3975 "undefined", /* 49 */
+ − 3976 "undefined", /* 50 */
+ − 3977 "undefined", /* 51 */
+ − 3978 "undefined", /* 52 */
+ − 3979 "undefined", /* 53 */
+ − 3980 "undefined", /* 54 */
+ − 3981 "undefined", /* 55 */
+ − 3982 "undefined", /* 56 */
+ − 3983 "undefined", /* 57 */
+ − 3984 "undefined", /* 58 */
+ − 3985 "undefined", /* 59 */
+ − 3986 "undefined", /* 60 */
+ − 3987 "undefined", /* 61 */
+ − 3988 "undefined", /* 62 */
+ − 3989 "undefined", /* 63 */
+ − 3990 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
+ − 3991 /* $$####end-snarf */
428
+ − 3992 0
+ − 3993 };
+ − 3994 #endif /* DGUX */
+ − 3995
+ − 3996 #endif /* ! SYS_SIGLIST_DECLARED && ! HAVE_SYS_SIGLIST */
+ − 3997
+ − 3998
+ − 3999 /************************************************************************/
+ − 4000 /* Directory routines for systems that don't have them */
+ − 4001 /************************************************************************/
+ − 4002
+ − 4003 #ifdef SYSV_SYSTEM_DIR
+ − 4004
+ − 4005 #include <dirent.h>
+ − 4006
+ − 4007 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
+ − 4008 int
+ − 4009 closedir (DIR *dirp) /* stream from opendir */
+ − 4010 {
+ − 4011 int rtnval;
+ − 4012
771
+ − 4013 rtnval = retry_close (dirp->dd_fd);
428
+ − 4014
+ − 4015 /* Some systems (like Solaris) allocate the buffer and the DIR all
+ − 4016 in one block. Why in the world are we freeing this ourselves
+ − 4017 anyway? */
+ − 4018 #if ! (defined (sun) && defined (USG5_4))
1726
+ − 4019 xfree (dirp->dd_buf, char *); /* directory block defined in <dirent.h> */
428
+ − 4020 #endif
1726
+ − 4021 xfree (dirp, DIR *);
428
+ − 4022 return (rtnval);
+ − 4023 }
+ − 4024 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
+ − 4025 #endif /* SYSV_SYSTEM_DIR */
+ − 4026
+ − 4027 #ifdef NONSYSTEM_DIR_LIBRARY
+ − 4028
+ − 4029 DIR *
442
+ − 4030 opendir (const char *filename) /* name of directory */
428
+ − 4031 {
+ − 4032 DIR *dirp; /* -> malloc'ed storage */
+ − 4033 int fd; /* file descriptor for read */
+ − 4034 struct stat sbuf; /* result of fstat */
+ − 4035
771
+ − 4036 fd = open (filename, O_RDONLY);
428
+ − 4037 if (fd < 0)
+ − 4038 return 0;
+ − 4039
+ − 4040 if (fstat (fd, &sbuf) < 0
+ − 4041 || (sbuf.st_mode & S_IFMT) != S_IFDIR
+ − 4042 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0)
+ − 4043 {
771
+ − 4044 retry_close (fd);
428
+ − 4045 return 0; /* bad luck today */
+ − 4046 }
+ − 4047
+ − 4048 dirp->dd_fd = fd;
+ − 4049 dirp->dd_loc = dirp->dd_size = 0; /* refill needed */
+ − 4050
+ − 4051 return dirp;
+ − 4052 }
+ − 4053
+ − 4054 void
+ − 4055 closedir (DIR *dirp) /* stream from opendir */
+ − 4056 {
771
+ − 4057 retry_close (dirp->dd_fd);
1726
+ − 4058 xfree (dirp, DIR *);
428
+ − 4059 }
+ − 4060
+ − 4061
+ − 4062 #define DIRSIZ 14
+ − 4063 struct olddir
+ − 4064 {
+ − 4065 ino_t od_ino; /* inode */
+ − 4066 char od_name[DIRSIZ]; /* filename */
+ − 4067 };
+ − 4068
+ − 4069 static struct direct dir_static; /* simulated directory contents */
+ − 4070
+ − 4071 /* ARGUSED */
+ − 4072 struct direct *
+ − 4073 readdir (DIR *dirp) /* stream from opendir */
+ − 4074 {
+ − 4075 struct olddir *dp; /* -> directory data */
+ − 4076
+ − 4077 for (; ;)
+ − 4078 {
+ − 4079 if (dirp->dd_loc >= dirp->dd_size)
+ − 4080 dirp->dd_loc = dirp->dd_size = 0;
+ − 4081
+ − 4082 if (dirp->dd_size == 0 /* refill buffer */
771
+ − 4083 && (dirp->dd_size =
+ − 4084 retry_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
428
+ − 4085 return 0;
+ − 4086
+ − 4087 dp = (struct olddir *) &dirp->dd_buf[dirp->dd_loc];
+ − 4088 dirp->dd_loc += sizeof (struct olddir);
+ − 4089
+ − 4090 if (dp->od_ino != 0) /* not deleted entry */
+ − 4091 {
+ − 4092 dir_static.d_ino = dp->od_ino;
+ − 4093 strncpy (dir_static.d_name, dp->od_name, DIRSIZ);
+ − 4094 dir_static.d_name[DIRSIZ] = '\0';
+ − 4095 dir_static.d_namlen = strlen (dir_static.d_name);
+ − 4096 dir_static.d_reclen = sizeof (struct direct)
+ − 4097 - MAXNAMLEN + 3
+ − 4098 + dir_static.d_namlen - dir_static.d_namlen % 4;
+ − 4099 return &dir_static; /* -> simulated structure */
+ − 4100 }
+ − 4101 }
+ − 4102 }
+ − 4103
+ − 4104
+ − 4105 #endif /* NONSYSTEM_DIR_LIBRARY */
+ − 4106
+ − 4107
+ − 4108 /* mkdir and rmdir functions, for systems which don't have them. */
+ − 4109
+ − 4110 #ifndef HAVE_MKDIR
+ − 4111 /*
+ − 4112 * Written by Robert Rother, Mariah Corporation, August 1985.
+ − 4113 *
+ − 4114 * If you want it, it's yours. All I ask in return is that if you
+ − 4115 * figure out how to do this in a Bourne Shell script you send me
+ − 4116 * a copy.
+ − 4117 * sdcsvax!rmr or rmr@uscd
+ − 4118 *
+ − 4119 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
+ − 4120 * subroutine. 11Mar86; hoptoad!gnu
+ − 4121 *
+ − 4122 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
+ − 4123 * subroutine didn't return EEXIST. It does now.
+ − 4124 */
+ − 4125
+ − 4126 /*
+ − 4127 * Make a directory.
+ − 4128 */
+ − 4129 #ifdef MKDIR_PROTOTYPE
+ − 4130 MKDIR_PROTOTYPE
+ − 4131 #else
+ − 4132 int
442
+ − 4133 mkdir (const char *dpath, int dmode)
428
+ − 4134 #endif
+ − 4135 {
+ − 4136 int cpid, status, fd;
+ − 4137 struct stat statbuf;
+ − 4138
442
+ − 4139 if (stat (dpath, &statbuf) == 0) /* we do want stat() here */
428
+ − 4140 {
+ − 4141 errno = EEXIST; /* Stat worked, so it already exists */
+ − 4142 return -1;
+ − 4143 }
+ − 4144
+ − 4145 /* If stat fails for a reason other than non-existence, return error */
+ − 4146 if (errno != ENOENT)
+ − 4147 return -1;
+ − 4148
+ − 4149 synch_process_alive = 1;
+ − 4150 switch (cpid = fork ())
+ − 4151 {
+ − 4152
+ − 4153 case -1: /* Error in fork() */
+ − 4154 return -1; /* Errno is set already */
+ − 4155
+ − 4156 case 0: /* Child process */
+ − 4157 {
+ − 4158 /*
+ − 4159 * Cheap hack to set mode of new directory. Since this
+ − 4160 * child process is going away anyway, we zap its umask.
+ − 4161 * ####, this won't suffice to set SUID, SGID, etc. on this
+ − 4162 * directory. Does anybody care?
+ − 4163 */
+ − 4164 status = umask (0); /* Get current umask */
+ − 4165 status = umask (status | (0777 & ~dmode)); /* Set for mkdir */
771
+ − 4166 fd = open ("/dev/null", O_RDWR);
428
+ − 4167 if (fd >= 0)
+ − 4168 {
+ − 4169 if (fd != STDIN_FILENO) dup2 (fd, STDIN_FILENO);
+ − 4170 if (fd != STDOUT_FILENO) dup2 (fd, STDOUT_FILENO);
+ − 4171 if (fd != STDERR_FILENO) dup2 (fd, STDERR_FILENO);
+ − 4172 }
+ − 4173 execl ("/bin/mkdir", "mkdir", dpath, (char *) 0);
+ − 4174 _exit (-1); /* Can't exec /bin/mkdir */
+ − 4175 }
+ − 4176
+ − 4177 default: /* Parent process */
+ − 4178 wait_for_termination (cpid);
+ − 4179 }
+ − 4180
+ − 4181 if (synch_process_death != 0 || synch_process_retcode != 0)
+ − 4182 {
+ − 4183 errno = EIO; /* We don't know why, but */
+ − 4184 return -1; /* /bin/mkdir failed */
+ − 4185 }
+ − 4186
+ − 4187 return 0;
+ − 4188 }
+ − 4189 #endif /* not HAVE_MKDIR */
+ − 4190
+ − 4191 #ifndef HAVE_RMDIR
+ − 4192 int
442
+ − 4193 rmdir (const char *dpath)
428
+ − 4194 {
+ − 4195 int cpid, status, fd;
+ − 4196 struct stat statbuf;
+ − 4197
442
+ − 4198 if (stat (dpath, &statbuf) != 0) /* we do want stat() here */
428
+ − 4199 {
+ − 4200 /* Stat just set errno. We don't have to */
+ − 4201 return -1;
+ − 4202 }
+ − 4203
+ − 4204 synch_process_alive = 1;
+ − 4205 switch (cpid = fork ())
+ − 4206 {
+ − 4207
+ − 4208 case -1: /* Error in fork() */
+ − 4209 return (-1); /* Errno is set already */
+ − 4210
+ − 4211 case 0: /* Child process */
771
+ − 4212 fd = open ("/dev/null", O_RDWR);
428
+ − 4213 if (fd >= 0)
+ − 4214 {
+ − 4215 if (fd != STDIN_FILENO) dup2 (fd, STDIN_FILENO);
+ − 4216 if (fd != STDOUT_FILENO) dup2 (fd, STDOUT_FILENO);
+ − 4217 if (fd != STDERR_FILENO) dup2 (fd, STDERR_FILENO);
+ − 4218 }
+ − 4219 execl ("/bin/rmdir", "rmdir", dpath, (char *) 0);
+ − 4220 _exit (-1); /* Can't exec /bin/mkdir */
+ − 4221
+ − 4222 default: /* Parent process */
+ − 4223 wait_for_termination (cpid);
+ − 4224 }
+ − 4225
+ − 4226 if (synch_process_death != 0 ||
+ − 4227 synch_process_retcode != 0)
+ − 4228 {
+ − 4229 errno = EIO; /* We don't know why, but */
+ − 4230 return -1; /* /bin/rmdir failed */
+ − 4231 }
+ − 4232
+ − 4233 return 0;
+ − 4234 }
+ − 4235 #endif /* !HAVE_RMDIR */
+ − 4236
+ − 4237
+ − 4238 /************************************************************************/
+ − 4239 /* Misc. SunOS crap */
+ − 4240 /************************************************************************/
+ − 4241
+ − 4242 #ifdef USE_DL_STUBS
+ − 4243
+ − 4244 /* These are included on Sunos 4.1 when we do not use shared libraries.
+ − 4245 X11 libraries may refer to these functions but (we hope) do not
+ − 4246 actually call them. */
+ − 4247
+ − 4248 void *
+ − 4249 dlopen (void)
+ − 4250 {
+ − 4251 return 0;
+ − 4252 }
+ − 4253
+ − 4254 void *
+ − 4255 dlsym (void)
+ − 4256 {
+ − 4257 return 0;
+ − 4258 }
+ − 4259
+ − 4260 int
+ − 4261 dlclose (void)
+ − 4262 {
+ − 4263 return -1;
+ − 4264 }
+ − 4265
+ − 4266 #endif /* USE_DL_STUBS */