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