Mercurial > hg > xemacs-beta
annotate src/sysdep.c @ 5557:53c066311921
If XLookupKeysym() returned an XFree86 "special key", ignore it. Fixes Sh-F11.
src/ChangeLog addition:
2011-08-27 Aidan Kehoe <kehoea@parhasard.net>
* config.h.in: Make HAVE_X11_XF86KEYSYM_H available here.
* event-Xt.c: #include X11/XF86keysym.h if available.
* event-Xt.c (x_event_to_emacs_event):
If XLookupKeysym () returned one of the XFree86 "special action
keys" for the shifted keysym, treat that as NoSymbol, fixing a
long-standing bug with shifted function keys under X.org.
Details of why in:
http://mid.gmane.org/16960.15685.26911.644835@parhasard.net
ChangeLog addition:
2011-08-27 Aidan Kehoe <kehoea@parhasard.net>
* configure.ac: Check whether X11/XF86keysym.h is available, to
allow us to avoid a bug in the interaction of XKB and XLookupKeysym.
* configure: Regenerate.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Sat, 27 Aug 2011 20:35:23 +0100 |
| parents | 1f0b15040456 |
| children | 56144c8593a8 |
| 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 signal_handler_t | |
| 613 | 2162 qxe_reliable_signal (int signal_number, signal_handler_t action) |
| 428 | 2163 { |
|
5494
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2164 static struct sigaction new_action, old_action; |
|
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2165 |
|
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2166 /* XEmacs works better if system calls are not restarted. |
| 428 | 2167 This allows C-g to interrupt reads and writes, on most systems. |
| 2168 | |
| 2169 #### Another possibility is to just longjmp() out of the signal | |
| 2170 handler. According to W.R. Stevens, this should be OK on all | |
| 2171 systems. However, I don't want to deal with the potential | |
| 2172 evil ramifications of this at this point. */ | |
| 2173 sigemptyset (&new_action.sa_mask); | |
| 2174 new_action.sa_handler = action; | |
| 2175 #if defined (SA_INTERRUPT) /* don't restart system calls, under SunOS */ | |
| 2176 new_action.sa_flags = SA_INTERRUPT; | |
| 2177 #else | |
| 2178 new_action.sa_flags = 0; | |
| 2179 #endif | |
| 2180 sigaction (signal_number, &new_action, &old_action); | |
| 2181 return (signal_handler_t) (old_action.sa_handler); | |
| 2182 } | |
| 2183 | |
| 2184 #elif defined (HAVE_SIGBLOCK) | |
| 2185 | |
| 2186 /* We use sigvec() rather than signal() if we have it, because | |
| 2187 it lets us specify interruptible system calls. */ | |
| 2188 signal_handler_t | |
| 613 | 2189 qxe_reliable_signal (int signal_number, signal_handler_t action) |
| 428 | 2190 { |
| 2191 struct sigvec vec, ovec; | |
| 2192 | |
| 2193 vec.sv_handler = action; | |
| 2194 vec.sv_mask = 0; | |
| 2195 #ifdef SV_INTERRUPT /* don't restart system calls */ | |
| 2196 vec.sv_flags = SV_INTERRUPT; | |
| 2197 #else | |
| 2198 vec.sv_flags = 0; | |
| 2199 #endif | |
| 2200 | |
| 2201 sigvec (signal_number, &vec, &ovec); | |
| 2202 | |
| 2203 return (ovec.sv_handler); | |
| 2204 } | |
| 2205 | |
| 2206 #endif /* HAVE_SIGBLOCK (HAVE_SIGPROCMASK) */ | |
| 2207 | |
| 2208 | |
| 2209 /************************************************************************/ | |
| 2210 /* Emulation of strerror() and errno support */ | |
| 2211 /************************************************************************/ | |
| 2212 | |
| 2213 #ifndef HAVE_STRERROR | |
| 2214 | |
|
5494
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2215 #if !defined(__alpha) && !defined(MACH) && !defined(LINUX) && !defined(IRIX6_5) && !defined(__NetBSD__) |
| 428 | 2216 /* Linux added here by Raymond L. Toy <toy@alydar.crd.ge.com> for XEmacs. */ |
| 2217 /* Irix added here by gparker@sni-usa.com for XEmacs. */ | |
| 2218 /* NetBSD added here by James R Grinter <jrg@doc.ic.ac.uk> for XEmacs */ | |
| 442 | 2219 extern const char *sys_errlist[]; |
| 428 | 2220 extern int sys_nerr; |
| 2221 #endif | |
| 2222 | |
| 2223 #ifdef __NetBSD__ | |
| 2224 extern char *sys_errlist[]; | |
| 2225 extern int sys_nerr; | |
| 2226 #endif | |
| 2227 | |
| 2228 | |
| 442 | 2229 const char * |
| 428 | 2230 strerror (int errnum) |
| 2231 { | |
| 2232 if (errnum >= 0 && errnum < sys_nerr) | |
| 2233 return sys_errlist[errnum]; | |
| 442 | 2234 return ((const char *) GETTEXT ("Unknown error")); |
| 428 | 2235 } |
| 2236 | |
| 2237 #endif /* ! HAVE_STRERROR */ | |
| 2238 | |
| 2239 | |
| 2240 /************************************************************************/ | |
| 2241 /* Encapsulations of system calls */ | |
| 2242 /************************************************************************/ | |
| 2243 | |
| 2244 /***************** low-level calls ****************/ | |
| 2245 | |
| 2246 /* | |
| 2247 * On USG systems the system calls are INTERRUPTIBLE by signals | |
| 2248 * that the user program has elected to catch. Thus the system call | |
| 2249 * must be retried in these cases. To handle this without massive | |
| 2250 * changes in the source code, we remap the standard system call names | |
| 2251 * to names for our own functions in sysdep.c that do the system call | |
| 2252 * with retries. Actually, for portability reasons, it is good | |
| 2253 * programming practice, as this example shows, to limit all actual | |
| 2254 * system calls to a single occurrence in the source. Sure, this | |
| 2255 * adds an extra level of function call overhead but it is almost | |
| 2256 * always negligible. Fred Fish, Unisoft Systems Inc. | |
| 2257 */ | |
| 2258 | |
| 2259 /* Ben sez: read Dick Gabriel's essay about the Worse Is Better | |
| 2260 approach to programming and its connection to the silly | |
| 2261 interruptible-system-call business. To find it, look on | |
| 2340 | 2262 Jamie's home page (http://www.jwz.org/doc/worse-is-better.html). */ |
| 428 | 2263 |
| 771 | 2264 #ifdef WIN32_NATIVE |
| 2265 | |
| 2266 static int | |
| 2267 underlying_open_1 (const Extbyte *path, int oflag, int mode) | |
| 2268 { | |
| 2269 if (XEUNICODE_P) | |
| 2270 return _wopen ((const wchar_t *) path, oflag, mode); | |
| 2271 else | |
| 2272 return _open (path, oflag, mode); | |
| 2273 } | |
| 2274 | |
| 2275 #endif /* WIN32_NATIVE */ | |
| 2276 | |
| 2367 | 2277 /* Just call open() with normal open() semantics, with some fixups for |
| 2278 problems under Windows. */ | |
| 771 | 2279 |
| 2280 static int | |
| 2281 underlying_open (const Extbyte *path, int oflag, int mode) | |
| 2282 { | |
| 2283 #ifdef WIN32_NATIVE | |
| 2284 { | |
| 2285 /* Try to open file without _O_CREAT, to be able to write to hidden | |
| 2286 and system files. Force all file handles to be | |
| 2287 non-inheritable. */ | |
| 2288 int res = underlying_open_1 (path, (oflag & ~_O_CREAT) | _O_NOINHERIT, | |
| 2289 mode); | |
| 2290 if (res >= 0) | |
| 2291 return res; | |
| 2292 return underlying_open_1 (path, oflag | _O_NOINHERIT, mode); | |
| 2293 } | |
| 2294 #else | |
| 2295 return open (path, oflag, mode); | |
| 2296 #endif /* WIN32_NATIVE */ | |
| 2297 } | |
| 2298 | |
| 2367 | 2299 static int |
| 2300 retry_open_1 (const Extbyte *path, int oflag, int mode) | |
| 428 | 2301 { |
|
5494
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2302 int rtnval; |
|
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2303 while ((rtnval = underlying_open (path, oflag, mode)) == -1 |
|
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2304 && (errno == EINTR)) |
|
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2305 DO_NOTHING; |
|
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2306 return rtnval; |
| 428 | 2307 } |
| 771 | 2308 |
| 2367 | 2309 /* A version of open() that retries when interrupted. Operates on |
| 2310 externally-encoded filenames. */ | |
| 2311 | |
| 2312 int XCDECL | |
| 2313 retry_open (const Extbyte *path, int oflag, ...) | |
| 2314 { | |
| 2315 int mode; | |
| 2316 va_list ap; | |
| 2317 | |
| 2318 va_start (ap, oflag); | |
| 2319 mode = va_arg (ap, int); | |
| 2320 va_end (ap); | |
| 2321 | |
| 2322 return retry_open_1 (path, oflag, mode); | |
| 2323 } | |
| 2324 | |
| 2325 #if defined (WIN32_NATIVE) && defined (WEXTTEXT_IS_WIDE) | |
| 2326 | |
| 2327 /* Like retry_open() but operate on Wexttext filenames. */ | |
| 2328 | |
| 2329 int XCDECL | |
| 2330 wext_retry_open (const Wexttext *path, int oflag, ...) | |
| 2331 { | |
| 2332 int mode; | |
| 2333 va_list ap; | |
| 2334 | |
| 2335 va_start (ap, oflag); | |
| 2336 mode = va_arg (ap, int); | |
| 2337 va_end (ap); | |
| 2338 | |
| 2339 if (!XEUNICODE_P) | |
| 2340 return retry_open_1 (WEXTTEXT_TO_MULTIBYTE (path), oflag, mode); | |
| 2341 else | |
| 2342 return retry_open_1 ((Extbyte *) path, oflag, mode); | |
| 2343 } | |
| 2344 | |
| 2345 #endif | |
| 2346 | |
| 771 | 2347 /* The basic external entry point to open(). Handles conversion to |
| 2348 external encoding, interruptions, etc. */ | |
| 2349 | |
| 872 | 2350 int XCDECL |
| 867 | 2351 qxe_open (const Ibyte *path, int oflag, ...) |
| 771 | 2352 { |
| 2353 Extbyte *pathout; | |
| 2354 int mode; | |
| 2355 va_list ap; | |
| 2356 | |
| 2357 va_start (ap, oflag); | |
| 2358 mode = va_arg (ap, int); | |
| 2359 va_end (ap); | |
| 2360 | |
| 2361 PATHNAME_CONVERT_OUT (path, pathout); | |
| 2362 return retry_open (pathout, oflag, mode); | |
| 2363 } | |
| 2364 | |
| 2365 /* Like qxe_open, only when open() is interrupted by EINTR, check for | |
| 428 | 2366 QUIT. This allows the callers of this function to be interrupted |
| 2367 with C-g when, say, reading from named pipes. However, this should | |
| 1123 | 2368 be used with caution, as it can run random Lisp code (although it |
| 2369 cannot GC). | |
| 428 | 2370 |
| 2371 This function will not function as expected on systems where open() | |
| 2372 is not interrupted by C-g. However, the worst that can happen is | |
| 2373 the fallback to simple open(). */ | |
| 2374 int | |
| 867 | 2375 qxe_interruptible_open (const Ibyte *path, int oflag, int mode) |
| 428 | 2376 { |
| 2377 /* This function can GC */ | |
| 771 | 2378 Extbyte *pathout; |
| 2379 | |
| 2380 PATHNAME_CONVERT_OUT (path, pathout); | |
| 428 | 2381 |
| 442 | 2382 #ifdef WIN32_NATIVE |
| 440 | 2383 /* Make all handles non-inheritable */ |
| 2384 oflag |= _O_NOINHERIT; | |
| 2385 #endif | |
| 2386 | |
| 428 | 2387 for (;;) |
| 2388 { | |
| 771 | 2389 int rtnval = underlying_open (pathout, oflag, mode); |
| 428 | 2390 if (!(rtnval == -1 && errno == EINTR)) |
| 2391 return rtnval; | |
| 2392 /* open() was interrupted. Was QUIT responsible? */ | |
| 2393 QUIT; | |
| 2394 } | |
| 2395 } | |
| 2396 | |
| 2397 int | |
| 771 | 2398 retry_close (int filedes) |
| 428 | 2399 { |
| 2400 int did_retry = 0; | |
| 2401 REGISTER int rtnval; | |
| 2402 | |
| 2403 while ((rtnval = close (filedes)) == -1 | |
| 2404 && (errno == EINTR)) | |
| 2405 did_retry = 1; | |
| 2406 | |
| 2407 /* If close is interrupted SunOS 4.1 may or may not have closed the | |
| 2408 file descriptor. If it did the second close will fail with | |
| 2409 errno = EBADF. That means we have succeeded. */ | |
| 2410 if (rtnval == -1 && did_retry && errno == EBADF) | |
| 2411 return 0; | |
| 2412 | |
| 2413 return rtnval; | |
| 2414 } | |
| 771 | 2415 |
| 2416 static ssize_t | |
| 2417 retry_read_1 (int fildes, void *buf, size_t nbyte, int allow_quit) | |
| 428 | 2418 { |
| 2419 ssize_t rtnval; | |
| 2420 | |
| 2421 while ((rtnval = read (fildes, buf, nbyte)) == -1 | |
| 2422 && (errno == EINTR)) | |
| 2423 { | |
| 2424 if (allow_quit) | |
| 853 | 2425 QUIT; |
| 428 | 2426 } |
| 2427 return rtnval; | |
| 2428 } | |
| 2429 | |
| 2430 ssize_t | |
| 771 | 2431 retry_read (int fildes, void *buf, size_t nbyte) |
| 428 | 2432 { |
| 771 | 2433 return retry_read_1 (fildes, buf, nbyte, 0); |
| 428 | 2434 } |
| 771 | 2435 |
| 2436 static ssize_t | |
| 2437 retry_write_1 (int fildes, const void *buf, size_t nbyte, int allow_quit) | |
| 428 | 2438 { |
| 2439 ssize_t bytes_written = 0; | |
| 442 | 2440 const char *b = (const char *) buf; |
| 428 | 2441 |
| 2442 while (nbyte > 0) | |
| 2443 { | |
| 2444 ssize_t rtnval = write (fildes, b, nbyte); | |
| 2445 | |
| 2446 if (allow_quit) | |
| 853 | 2447 QUIT; |
| 428 | 2448 |
| 2449 if (rtnval == -1) | |
| 2450 { | |
| 2451 if (errno == EINTR) | |
| 2452 continue; | |
| 2453 else | |
| 2454 return bytes_written ? bytes_written : -1; | |
| 2455 } | |
| 2456 b += rtnval; | |
| 2457 nbyte -= rtnval; | |
| 2458 bytes_written += rtnval; | |
| 2459 } | |
| 2460 return bytes_written; | |
| 2461 } | |
| 2462 | |
| 2463 ssize_t | |
| 771 | 2464 retry_write (int fildes, const void *buf, size_t nbyte) |
| 428 | 2465 { |
| 771 | 2466 return retry_write_1 (fildes, buf, nbyte, 0); |
| 428 | 2467 } |
| 771 | 2468 |
| 2469 /* Versions of read() and write() that allow quitting out of the actual | |
| 2470 I/O. We don't use immediate_quit (i.e. direct longjmp() out of the | |
| 2471 signal handler) because that's way too losing. | |
| 2472 | |
| 2473 (#### Actually, longjmp()ing out of the signal handler may not be | |
| 2474 as losing as I thought. See qxe_reliable_signal() in sysdep.c.) */ | |
| 2475 | |
| 2476 Bytecount | |
| 2477 read_allowing_quit (int fildes, void *buf, Bytecount size) | |
| 2478 { | |
| 2479 QUIT; | |
| 2480 return retry_read_1 (fildes, buf, size, 1); | |
| 2481 } | |
| 2482 | |
| 2483 Bytecount | |
| 2484 write_allowing_quit (int fildes, const void *buf, Bytecount size) | |
| 2485 { | |
| 2486 QUIT; | |
| 2487 return retry_write_1 (fildes, buf, size, 1); | |
| 2488 } | |
| 428 | 2489 |
| 2490 | |
| 2491 /**************** stdio calls ****************/ | |
| 2492 | |
| 2493 /* There is at least some evidence that the stdio calls are interruptible | |
| 2494 just like the normal system calls, at least on some systems. In any | |
| 2495 case, it doesn't hurt to encapsulate them. */ | |
| 2496 | |
| 2497 /* #### Should also encapsulate fflush(). | |
| 2498 #### Should conceivably encapsulate getchar() etc. What a pain! */ | |
| 2499 | |
| 2500 FILE * | |
| 2367 | 2501 retry_fopen (const Extbyte *path, const Ascbyte *mode) |
| 428 | 2502 { |
| 771 | 2503 #ifdef WIN32_NATIVE |
| 2504 int fd; | |
| 2505 int oflag; | |
| 2367 | 2506 const Ascbyte *mode_save = mode; |
| 771 | 2507 |
| 2508 /* Force all file handles to be non-inheritable. This is necessary to | |
| 2509 ensure child processes don't unwittingly inherit handles that might | |
| 2510 prevent future file access. */ | |
| 2511 | |
| 2512 if (mode[0] == 'r') | |
| 2513 oflag = O_RDONLY; | |
| 2514 else if (mode[0] == 'w' || mode[0] == 'a') | |
| 2515 oflag = O_WRONLY | O_CREAT | O_TRUNC; | |
| 2516 else | |
| 2517 return NULL; | |
| 2518 | |
| 2519 /* Only do simplistic option parsing. */ | |
| 2520 while (*++mode) | |
| 2521 if (mode[0] == '+') | |
| 2522 { | |
| 2523 oflag &= ~(O_RDONLY | O_WRONLY); | |
| 2524 oflag |= O_RDWR; | |
| 2525 } | |
| 2526 else if (mode[0] == 'b') | |
| 2527 { | |
| 2528 oflag &= ~O_TEXT; | |
| 2529 oflag |= O_BINARY; | |
| 2530 } | |
| 2531 else if (mode[0] == 't') | |
| 2532 { | |
| 2533 oflag &= ~O_BINARY; | |
| 2534 oflag |= O_TEXT; | |
| 2535 } | |
| 2536 else break; | |
| 2537 | |
| 2538 fd = underlying_open (path, oflag, 0644); | |
| 2539 if (fd < 0) | |
| 2540 return NULL; | |
| 2541 | |
| 2542 return _fdopen (fd, mode_save); | |
| 428 | 2543 #else |
|
5494
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2544 FILE *rtnval; |
|
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2545 while (!(rtnval = fopen (path, mode)) && (errno == EINTR)) |
|
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2546 DO_NOTHING; |
|
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2547 return rtnval; |
|
861f2601a38b
Sync s/ files with GNU 23.1.92, delete obsolete stuff, simplify other stuff
Ben Wing <ben@xemacs.org>
parents:
4982
diff
changeset
|
2548 #endif /* (not) WIN32_NATIVE */ |
| 428 | 2549 } |
| 771 | 2550 |
| 2551 FILE * | |
| 2367 | 2552 qxe_fopen (const Ibyte *path, const Ascbyte *mode) |
| 771 | 2553 { |
| 2554 Extbyte *pathout; | |
| 2555 PATHNAME_CONVERT_OUT (path, pathout); | |
| 2556 return retry_fopen (pathout, mode); | |
| 2557 } | |
| 2558 | |
| 428 | 2559 int |
| 771 | 2560 retry_fclose (FILE *stream) |
| 428 | 2561 { |
| 2562 int rtnval; | |
| 2563 | |
| 2564 while ((rtnval = fclose (stream)) == EOF | |
| 2565 && (errno == EINTR)) | |
| 2566 ; | |
| 2567 return rtnval; | |
| 2568 } | |
| 771 | 2569 |
| 428 | 2570 size_t |
| 771 | 2571 retry_fread (void *ptr, size_t size, size_t nitem, FILE *stream) |
| 428 | 2572 { |
| 2573 size_t rtnval; | |
| 2574 size_t items_read = 0; | |
| 2575 char *b = (char *) ptr; | |
| 2576 | |
| 2577 while (nitem > 0) | |
| 2578 { | |
| 2579 rtnval = fread (b, size, nitem, stream); | |
| 2580 if (rtnval == 0) | |
| 2581 { | |
| 2582 if (ferror (stream) && errno == EINTR) | |
| 2583 continue; | |
| 2584 else | |
| 2585 return items_read; | |
| 2586 } | |
| 2587 b += size*rtnval; | |
| 2588 nitem -= rtnval; | |
| 2589 items_read += rtnval; | |
| 2590 } | |
| 2591 return (items_read); | |
| 2592 } | |
| 771 | 2593 |
| 428 | 2594 size_t |
| 771 | 2595 retry_fwrite (const void *ptr, size_t size, size_t nitem, FILE *stream) |
| 428 | 2596 { |
| 2597 size_t rtnval; | |
| 2598 size_t items_written = 0; | |
| 442 | 2599 const char *b = (const char *) ptr; |
| 428 | 2600 |
| 2601 while (nitem > 0) | |
| 2602 { | |
| 2603 rtnval = fwrite (b, size, nitem, stream); | |
| 2604 if (rtnval == 0) | |
| 2605 { | |
| 2606 if (ferror (stream) && errno == EINTR) | |
| 2607 continue; | |
| 2608 else | |
| 2609 return items_written; | |
| 2610 } | |
| 2611 b += size*rtnval; | |
| 2612 nitem -= rtnval; | |
| 2613 items_written += rtnval; | |
| 2614 } | |
| 2615 return (items_written); | |
| 2616 } | |
| 2617 | |
| 2618 /********************* directory calls *******************/ | |
| 2619 | |
| 2620 int | |
| 867 | 2621 qxe_chdir (const Ibyte *path) |
| 428 | 2622 { |
| 771 | 2623 Extbyte *pathout; |
| 2624 PATHNAME_CONVERT_OUT (path, pathout); | |
| 442 | 2625 #ifdef WIN32_NATIVE |
| 771 | 2626 if (XEUNICODE_P) |
| 2627 return _wchdir ((const wchar_t *) pathout); | |
| 2628 else | |
| 2629 return _chdir (pathout); | |
| 428 | 2630 #else |
| 771 | 2631 return chdir (pathout); |
| 428 | 2632 #endif |
| 2633 } | |
| 771 | 2634 |
| 2635 int | |
| 2340 | 2636 qxe_mkdir (const Ibyte *path, |
| 2637 #ifdef WIN32_NATIVE | |
| 2638 mode_t UNUSED (mode) | |
| 2639 #else | |
| 2640 mode_t mode | |
| 2641 #endif | |
| 2642 ) | |
| 771 | 2643 { |
| 2644 Extbyte *pathout; | |
| 2645 PATHNAME_CONVERT_OUT (path, pathout); | |
| 2646 #ifdef WIN32_NATIVE | |
| 2647 if (XEUNICODE_P) | |
| 2648 return _wmkdir ((const wchar_t *) pathout); | |
| 2649 else | |
| 2650 return _mkdir (pathout); | |
| 2651 #else | |
| 2652 return mkdir (pathout, mode); | |
| 2653 #endif | |
| 2654 } | |
| 2655 | |
| 428 | 2656 DIR * |
| 867 | 2657 qxe_opendir (const Ibyte *filename) |
| 428 | 2658 { |
| 771 | 2659 #ifdef WIN32_NATIVE |
| 2660 return mswindows_opendir (filename); | |
| 2661 #else | |
| 428 | 2662 DIR *rtnval; |
| 771 | 2663 Extbyte *pathout; |
| 2664 PATHNAME_CONVERT_OUT (filename, pathout); | |
| 2665 | |
| 2666 while (!(rtnval = opendir (pathout)) | |
| 428 | 2667 && (errno == EINTR)) |
| 2668 ; | |
| 2669 return rtnval; | |
| 771 | 2670 #endif /* WIN32_NATIVE */ |
| 428 | 2671 } |
| 771 | 2672 |
| 428 | 2673 DIRENTRY * |
| 771 | 2674 qxe_readdir (DIR *dirp) |
| 428 | 2675 { |
| 771 | 2676 #ifdef WIN32_NATIVE |
| 2677 return mswindows_readdir (dirp); | |
| 2678 #else /* not WIN32_NATIVE */ | |
| 428 | 2679 DIRENTRY *rtnval; |
| 2680 | |
| 2681 /* Apparently setting errno is necessary on some systems? | |
| 2682 Maybe readdir() doesn't always set errno ?! */ | |
| 2683 while (!(errno = 0, rtnval = readdir (dirp)) | |
| 2684 && (errno == EINTR)) | |
| 2685 ; | |
| 2686 #ifndef MULE | |
| 2687 return rtnval; | |
| 2688 #else /* MULE */ | |
| 2689 if (rtnval == NULL) /* End of directory */ | |
| 2690 return NULL; | |
| 2691 { | |
| 442 | 2692 const Extbyte * const external_name = (const Extbyte *) rtnval->d_name; |
| 665 | 2693 Bytecount external_len = strlen (rtnval->d_name); |
| 867 | 2694 const Ibyte *internal_name; |
| 462 | 2695 Bytecount internal_len; |
| 513 | 2696 |
| 462 | 2697 TO_INTERNAL_FORMAT (DATA, (external_name, external_len), |
| 2698 ALLOCA, (internal_name, internal_len), | |
| 2699 Qfile_name); | |
| 2700 | |
| 2701 /* check for common case of ASCII filename */ | |
| 2702 if (internal_len == external_len && | |
| 2703 !memcmp (external_name, internal_name, internal_len)) | |
| 428 | 2704 return rtnval; |
| 2705 | |
| 2706 { /* Non-ASCII filename */ | |
| 867 | 2707 static Ibyte_dynarr *internal_DIRENTRY; |
| 428 | 2708 if (!internal_DIRENTRY) |
| 867 | 2709 internal_DIRENTRY = Dynarr_new (Ibyte); |
| 428 | 2710 else |
| 2711 Dynarr_reset (internal_DIRENTRY); | |
| 2712 | |
| 867 | 2713 Dynarr_add_many (internal_DIRENTRY, (Ibyte *) rtnval, |
| 428 | 2714 offsetof (DIRENTRY, d_name)); |
| 2715 | |
| 2716 | |
| 2717 Dynarr_add_many (internal_DIRENTRY, internal_name, internal_len); | |
| 444 | 2718 Dynarr_add (internal_DIRENTRY, '\0'); /* NUL-terminate */ |
| 4967 | 2719 return (DIRENTRY *) Dynarr_begin (internal_DIRENTRY); |
| 428 | 2720 } |
| 2721 } | |
| 2722 #endif /* MULE */ | |
| 771 | 2723 #endif /* WIN32_NATIVE */ |
| 428 | 2724 } |
| 771 | 2725 |
| 428 | 2726 int |
| 771 | 2727 qxe_closedir (DIR *dirp) |
| 428 | 2728 { |
| 771 | 2729 #ifdef WIN32_NATIVE |
| 2730 return mswindows_closedir (dirp); | |
| 2731 #else /* not WIN32_NATIVE */ | |
| 428 | 2732 int rtnval; |
| 2733 | |
| 2734 while ((rtnval = closedir (dirp)) == -1 | |
| 2735 && (errno == EINTR)) | |
| 2736 ; | |
| 2737 return rtnval; | |
| 771 | 2738 #endif /* WIN32_NATIVE */ |
| 428 | 2739 } |
| 771 | 2740 |
| 428 | 2741 int |
| 867 | 2742 qxe_rmdir (const Ibyte *path) |
| 771 | 2743 { |
| 2744 Extbyte *pathout; | |
| 2745 PATHNAME_CONVERT_OUT (path, pathout); | |
| 2746 #ifdef WIN32_NATIVE | |
| 2747 if (XEUNICODE_P) | |
| 2748 return _wrmdir ((const wchar_t *) pathout); | |
| 2749 else | |
| 2750 return _rmdir (pathout); | |
| 2751 #else | |
| 2752 return rmdir (pathout); | |
| 2753 #endif | |
| 2754 } | |
| 2755 | |
| 867 | 2756 Ibyte * |
| 771 | 2757 qxe_allocating_getcwd (void) |
| 428 | 2758 { |
| 771 | 2759 #ifdef HAVE_GETCWD |
| 2760 Bytecount cwdsize = 1024; | |
| 2761 Extbyte *cwd = xnew_array (Extbyte, cwdsize); | |
| 2762 | |
| 2763 /* Many getcwd()'s can take a NULL argument and malloc() the right amount | |
| 2764 of data, but this is non-standard. */ | |
| 2765 while (1) | |
| 2766 { | |
| 2767 #ifdef WIN32_NATIVE | |
| 2768 Extbyte *ret; | |
| 2769 | |
| 2770 if (XEUNICODE_P) | |
| 2771 ret = (Extbyte *) _wgetcwd ((wchar_t *) cwd, | |
| 2772 cwdsize / sizeof (wchar_t)); | |
| 2773 else | |
| 2774 ret = _getcwd (cwd, cwdsize); | |
| 2775 | |
| 2776 if (ret) | |
| 2777 { | |
| 867 | 2778 Ibyte *retin; |
|
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
2779 retin = TSTR_TO_ITEXT_MALLOC (ret); |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
2780 xfree (cwd); |
| 771 | 2781 return retin; |
| 2782 } | |
| 2783 #else | |
| 2784 Extbyte *ret = getcwd (cwd, cwdsize); | |
| 2785 if (ret) | |
| 2786 { | |
| 867 | 2787 Ibyte *retin; |
|
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
2788 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
|
2789 xfree (cwd); |
| 771 | 2790 return retin; |
| 2791 } | |
| 2792 #endif /* WIN32_NATIVE */ | |
| 2793 | |
| 2794 if (errno == ERANGE) | |
| 2795 { | |
| 2796 cwdsize *= 2; | |
| 2797 XREALLOC_ARRAY (cwd, Extbyte, cwdsize); | |
| 2798 } | |
| 2799 else | |
| 2800 { | |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
2801 xfree (cwd); |
| 771 | 2802 return NULL; |
| 2803 } | |
| 2804 } | |
| 2805 #else | |
| 4854 | 2806 Extbyte chingame_limitos_arbitrarios[PATH_MAX_TCHAR]; |
| 867 | 2807 Ibyte *ret2; |
| 771 | 2808 |
| 2809 if (!getwd (chingame_limitos_arbitrarios)) | |
| 2810 return 0; | |
|
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
2811 ret2 = EXTERNAL_TO_ITEXT_MALLOC (chingame_limitos_arbitrarios, Qfile_name); |
| 771 | 2812 return ret2; |
| 2813 #endif /* HAVE_GETCWD */ | |
| 428 | 2814 } |
| 2815 | |
| 2816 /***************** file-information calls ******************/ | |
| 2817 | |
| 2818 int | |
| 867 | 2819 qxe_access (const Ibyte *path, int mode) |
| 428 | 2820 { |
| 771 | 2821 #ifdef WIN32_NATIVE |
| 2822 return mswindows_access (path, mode); | |
| 2823 #else /* not WIN32_NATIVE */ | |
| 2824 Extbyte *pathout; | |
| 2825 PATHNAME_CONVERT_OUT (path, pathout); | |
| 2826 return access (pathout, mode); | |
| 2827 #endif /* WIN32_NATIVE */ | |
| 428 | 2828 } |
| 771 | 2829 |
| 2830 #if defined (HAVE_EACCESS) | |
| 428 | 2831 int |
| 867 | 2832 qxe_eaccess (const Ibyte *path, int mode) |
| 428 | 2833 { |
| 771 | 2834 Extbyte *pathout; |
| 2835 PATHNAME_CONVERT_OUT (path, pathout); | |
| 2836 return eaccess (pathout, mode); | |
| 428 | 2837 } |
| 771 | 2838 #endif /* defined (HAVE_EACCESS) */ |
| 2839 | |
| 428 | 2840 int |
| 867 | 2841 qxe_lstat (const Ibyte *path, struct stat *buf) |
| 428 | 2842 { |
| 771 | 2843 /* if system does not have symbolic links, it does not have lstat. |
| 2844 In that case, use ordinary stat instead. */ | |
| 2845 #ifndef S_IFLNK | |
| 2846 return qxe_stat (path, buf); | |
| 2526 | 2847 #elif defined (WIN32_NATIVE) |
| 2848 if (mswindows_shortcuts_are_symlinks) | |
| 2849 { | |
| 2850 /* We want to resolve the directory component and leave the rest | |
| 2851 alone. */ | |
| 2852 Ibyte *dirend = find_end_of_directory_component (path, qxestrlen (path)); | |
| 2853 Bytecount len; | |
| 2854 | |
| 2855 if (dirend != path) | |
| 2856 { | |
| 2857 Ibyte *resdir; | |
| 2858 Ichar lastch; | |
| 2859 DECLARE_EISTRING (resname); | |
| 2860 DECLARE_EISTRING (dir); | |
| 2861 | |
| 2862 eicpy_raw (dir, path, dirend - path); | |
| 2863 PATHNAME_RESOLVE_LINKS (eidata (dir), resdir); | |
| 2864 eicpy_rawz (resname, resdir); | |
| 2865 lastch = eigetch_char (resname, eicharlen (resname) - 1); | |
| 2866 if (!IS_DIRECTORY_SEP (lastch)) | |
| 2867 eicat_ch (resname, '\\'); | |
| 2868 eicat_rawz (resname, dirend); | |
| 2869 path = eidata (resname); | |
| 2870 } | |
| 2871 | |
| 2872 /* However, if what we are trying to stat is a link, we need to add | |
| 2873 the .LNK so that the actual file is statted. */ | |
| 2874 len = qxestrlen (path); | |
| 2875 if (len > 4 && qxestrcasecmp_ascii (path + len - 4, ".LNK")) | |
| 2876 { | |
| 2877 DECLARE_EISTRING (name2); | |
| 2878 Ibyte *resolved; | |
| 2879 | |
| 2880 eicpy_rawz (name2, path); | |
| 2881 eicat_ascii (name2, ".LNK"); | |
| 2882 resolved = mswindows_read_link (eidata (name2)); | |
| 2883 if (resolved) | |
| 2884 { | |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
2885 xfree (resolved); |
| 2526 | 2886 return mswindows_stat (eidata (name2), buf); |
| 2887 } | |
| 2888 } | |
| 2889 } | |
| 2890 | |
| 2891 return mswindows_stat (path, buf); | |
| 771 | 2892 #else |
| 2893 Extbyte *pathout; | |
| 2894 PATHNAME_CONVERT_OUT (path, pathout); | |
| 2895 return lstat (pathout, buf); | |
| 2896 #endif | |
| 428 | 2897 } |
| 771 | 2898 |
| 2899 #if defined (HAVE_READLINK) | |
| 428 | 2900 int |
| 867 | 2901 qxe_readlink (const Ibyte *path, Ibyte *buf, size_t bufsiz) |
| 428 | 2902 { |
| 771 | 2903 int retval; |
| 2904 Extbyte *pathout; | |
| 2905 | |
| 2906 PATHNAME_CONVERT_OUT (path, pathout); | |
| 2907 retval = readlink (pathout, (char *) buf, bufsiz); | |
| 2908 if (retval < 0) | |
| 2909 return retval; | |
| 2910 { | |
| 867 | 2911 Ibyte *intbuf; |
| 771 | 2912 Bytecount tamanho; |
| 2913 | |
| 2914 TO_INTERNAL_FORMAT (DATA, (buf, retval), | |
| 2915 ALLOCA, (intbuf, tamanho), Qfile_name); | |
| 2916 /* the man page says this function does not null-terminate */ | |
| 2917 if (tamanho >= (Bytecount) bufsiz) | |
| 2918 tamanho = bufsiz; | |
| 2919 memcpy (buf, intbuf, tamanho); | |
| 2920 return tamanho; | |
| 2921 } | |
| 428 | 2922 } |
| 771 | 2923 #endif /* defined (HAVE_READLINK) */ |
| 2924 | |
| 432 | 2925 int |
| 771 | 2926 qxe_fstat (int fd, struct stat *buf) |
| 432 | 2927 { |
| 442 | 2928 #ifdef WIN32_NATIVE |
| 2929 return mswindows_fstat (fd, buf); | |
| 2930 #else | |
| 432 | 2931 return fstat (fd, buf); |
| 771 | 2932 #endif /* WIN32_NATIVE */ |
| 432 | 2933 } |
| 2934 | |
| 428 | 2935 int |
| 867 | 2936 qxe_stat (const Ibyte *path, struct stat *buf) |
| 428 | 2937 { |
| 442 | 2938 #ifdef WIN32_NATIVE |
| 2526 | 2939 Ibyte *resolved; |
| 2940 PATHNAME_RESOLVE_LINKS (path, resolved); | |
| 2941 return mswindows_stat (resolved, buf); | |
| 771 | 2942 #else /* not WIN32_NATIVE */ |
| 2943 Extbyte *pathout; | |
| 2944 PATHNAME_CONVERT_OUT (path, pathout); | |
| 2945 return stat (pathout, buf); | |
| 2946 #endif /* WIN32_NATIVE */ | |
| 428 | 2947 } |
| 2948 | |
| 771 | 2949 |
| 428 | 2950 /****************** file-manipulation calls *****************/ |
| 2951 | |
| 2952 int | |
| 867 | 2953 qxe_chmod (const Ibyte *path, mode_t mode) |
| 428 | 2954 { |
| 771 | 2955 Extbyte *pathout; |
| 2956 PATHNAME_CONVERT_OUT (path, pathout); | |
| 2957 #ifdef WIN32_NATIVE | |
| 2958 if (XEUNICODE_P) | |
| 2959 return _wchmod ((const wchar_t *) pathout, mode); | |
| 2960 else | |
| 2961 return _chmod (pathout, mode); | |
| 2962 #else | |
| 2963 return chmod (pathout, mode); | |
| 2964 #endif | |
| 428 | 2965 } |
| 771 | 2966 |
| 2967 #if defined (HAVE_LINK) | |
| 428 | 2968 int |
| 2957 | 2969 qxe_link (const Ibyte *existing, const Ibyte *new_) |
| 428 | 2970 { |
| 771 | 2971 #ifdef WIN32_NATIVE |
| 2957 | 2972 return mswindows_link (existing, new_); |
| 771 | 2973 #else /* not WIN32_NATIVE */ |
| 2974 Extbyte *existingout, *newout; | |
| 2975 PATHNAME_CONVERT_OUT (existing, existingout); | |
| 2957 | 2976 PATHNAME_CONVERT_OUT (new_, newout); |
| 771 | 2977 return link (existingout, newout); |
| 2978 #endif /* WIN32_NATIVE */ | |
| 428 | 2979 } |
| 771 | 2980 #endif /* defined (HAVE_LINK) */ |
| 2981 | |
| 428 | 2982 int |
| 2957 | 2983 qxe_rename (const Ibyte *old, const Ibyte *new_) |
| 428 | 2984 { |
| 442 | 2985 #ifdef WIN32_NATIVE |
| 2957 | 2986 return mswindows_rename (old, new_); |
| 771 | 2987 #else /* not WIN32_NATIVE */ |
| 2988 Extbyte *oldout, *newout; | |
| 2989 PATHNAME_CONVERT_OUT (old, oldout); | |
| 2957 | 2990 PATHNAME_CONVERT_OUT (new_, newout); |
| 771 | 2991 return rename (oldout, newout); |
| 442 | 2992 #endif /* WIN32_NATIVE */ |
| 428 | 2993 } |
| 771 | 2994 |
| 2995 #if defined (HAVE_SYMLINK) | |
| 428 | 2996 int |
| 867 | 2997 qxe_symlink (const Ibyte *name1, const Ibyte *name2) |
| 428 | 2998 { |
| 771 | 2999 Extbyte *name1out, *name2out; |
| 3000 PATHNAME_CONVERT_OUT (name1, name1out); | |
| 3001 PATHNAME_CONVERT_OUT (name2, name2out); | |
| 3002 return symlink (name1out, name2out); | |
| 428 | 3003 } |
| 771 | 3004 #endif /* defined (HAVE_SYMLINK) */ |
| 3005 | |
| 428 | 3006 int |
| 867 | 3007 qxe_unlink (const Ibyte *path) |
| 428 | 3008 { |
| 771 | 3009 #ifdef WIN32_NATIVE |
| 3010 return mswindows_unlink (path); | |
| 3011 #else /* not WIN32_NATIVE */ | |
| 3012 Extbyte *pathout; | |
| 3013 PATHNAME_CONVERT_OUT (path, pathout); | |
| 3014 return unlink (pathout); | |
| 3015 #endif /* WIN32_NATIVE */ | |
| 428 | 3016 } |
| 771 | 3017 |
| 3018 | |
| 3019 /****************** process calls *****************/ | |
| 3020 | |
| 428 | 3021 int |
| 867 | 3022 qxe_execve (const Ibyte *filename, Ibyte * const argv[], |
| 3023 Ibyte * const envp[]) | |
| 428 | 3024 { |
| 771 | 3025 int i, argc, envc; |
| 3026 Extbyte *pathext; | |
| 3027 Extbyte **new_argv; | |
| 3028 Extbyte **new_envp; | |
| 3029 | |
| 3030 PATHNAME_CONVERT_OUT (filename, pathext); | |
| 3031 | |
| 428 | 3032 for (argc = 0; argv[argc]; argc++) |
| 3033 ; | |
| 771 | 3034 new_argv = alloca_array (Extbyte *, argc + 1); |
| 428 | 3035 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
|
3036 new_argv[i] = ITEXT_TO_EXTERNAL (argv[i], Qcommand_argument_encoding); |
| 428 | 3037 new_argv[argc] = NULL; |
| 771 | 3038 |
| 3039 for (envc = 0; envp[envc]; envc++) | |
| 3040 ; | |
| 3041 new_envp = alloca_array (Extbyte *, envc + 1); | |
| 3042 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
|
3043 new_envp[i] = ITEXT_TO_EXTERNAL (envp[i], Qenvironment_variable_encoding); |
| 771 | 3044 new_envp[envc] = NULL; |
| 3045 | |
| 1318 | 3046 #if defined (WIN32_NATIVE) |
| 3047 if (XEUNICODE_P) | |
| 3048 return _wexecve ((const wchar_t *) pathext, | |
| 3049 (const wchar_t * const *) new_argv, | |
| 3050 (const wchar_t * const *) new_envp); | |
| 3051 #endif | |
| 771 | 3052 return execve (pathext, new_argv, new_envp); |
| 3053 } | |
| 3054 | |
| 3055 pid_t | |
| 3056 qxe_getpid (void) | |
| 3057 { | |
| 3058 #ifdef WIN32_NATIVE | |
| 3059 return abs (getpid ()); | |
| 3060 #else | |
| 3061 return getpid (); | |
| 3062 #endif | |
| 428 | 3063 } |
| 771 | 3064 |
| 3065 | |
| 3066 /****************** passwd calls *****************/ | |
| 3067 | |
| 3068 struct passwd cached_pwd; | |
| 3069 | |
| 3070 static struct passwd * | |
| 3071 copy_in_passwd (struct passwd *pwd) | |
| 3072 { | |
| 3073 if (!pwd) | |
| 3074 return NULL; | |
| 3075 | |
| 3076 if (cached_pwd.pw_name) | |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3077 xfree (cached_pwd.pw_name); |
| 771 | 3078 if (cached_pwd.pw_passwd) |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3079 xfree (cached_pwd.pw_passwd); |
| 771 | 3080 if (cached_pwd.pw_gecos) |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3081 xfree (cached_pwd.pw_gecos); |
| 771 | 3082 if (cached_pwd.pw_dir) |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3083 xfree (cached_pwd.pw_dir); |
| 771 | 3084 if (cached_pwd.pw_shell) |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3085 xfree (cached_pwd.pw_shell); |
| 771 | 3086 |
| 3087 cached_pwd = *pwd; | |
|
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3088 |
|
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3089 #define FROB(field, encoding) \ |
|
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3090 do \ |
|
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3091 { \ |
|
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3092 if (cached_pwd.field) \ |
|
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3093 cached_pwd.field = (CIbyte *) \ |
|
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3094 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
|
3095 } while (0) |
|
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3096 |
|
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3097 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
|
3098 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
|
3099 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
|
3100 FROB (pw_dir, Qfile_name); |
|
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3101 FROB (pw_shell, Qfile_name); |
|
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3102 #undef FROB |
| 771 | 3103 return &cached_pwd; |
| 3104 } | |
| 3105 | |
| 3106 struct passwd * | |
| 867 | 3107 qxe_getpwnam (const Ibyte *name) |
| 771 | 3108 { |
| 3109 #ifdef WIN32_NATIVE | |
| 3110 /* Synthetic versions are defined in nt.c and already do conversion. */ | |
| 3111 return getpwnam (name); | |
| 3112 #else | |
|
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3113 Extbyte *nameext = ITEXT_TO_EXTERNAL (name, Quser_name_encoding); |
| 771 | 3114 |
| 3115 return copy_in_passwd (getpwnam (nameext)); | |
| 3116 #endif /* WIN32_NATIVE */ | |
| 3117 } | |
| 3118 | |
| 3119 struct passwd * | |
| 3120 qxe_getpwuid (uid_t uid) | |
| 3121 { | |
| 3122 #ifdef WIN32_NATIVE | |
| 3123 /* Synthetic versions are defined in nt.c and already do conversion. */ | |
| 3124 return getpwuid (uid); | |
| 3125 #else | |
| 3126 return copy_in_passwd (getpwuid (uid)); | |
| 3127 #endif /* WIN32_NATIVE */ | |
| 3128 } | |
| 3129 | |
| 3130 #ifndef WIN32_NATIVE | |
| 3131 | |
| 3132 struct passwd * | |
| 3133 qxe_getpwent (void) | |
| 3134 { | |
| 3135 /* No WIN32_NATIVE version of this. */ | |
| 3136 return copy_in_passwd (getpwent ()); | |
| 3137 } | |
| 3138 | |
| 3139 #endif /* not WIN32_NATIVE */ | |
| 3140 | |
| 3141 /****************** time calls *****************/ | |
| 3142 | |
| 867 | 3143 static Ibyte *ctime_static; |
| 3144 | |
| 3145 Ibyte * | |
| 771 | 3146 qxe_ctime (const time_t *t) |
| 3147 { | |
| 3148 Extbyte *str = (Extbyte *) ctime (t); | |
| 3149 if (!str) /* can happen on MS Windows */ | |
| 867 | 3150 return (Ibyte *) "Sun Jan 01 00:00:00 1970"; |
| 771 | 3151 if (ctime_static) |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3152 xfree (ctime_static); |
|
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3153 ctime_static = EXTERNAL_TO_ITEXT_MALLOC (str, Qtime_function_encoding); |
| 771 | 3154 return ctime_static; |
| 3155 } | |
| 428 | 3156 |
| 1204 | 3157 |
| 912 | 3158 /************************************************************************/ |
| 3159 /* Emulation of missing functions from wchar.h */ | |
| 3160 /************************************************************************/ | |
| 3161 | |
| 3162 #ifndef HAVE_WCHAR_H | |
| 3163 size_t | |
| 2367 | 3164 wcslen (const wchar_t *s) |
| 912 | 3165 { |
| 3700 | 3166 const wchar_t *p = s; |
| 3648 | 3167 if (s == NULL) return NULL; |
| 912 | 3168 |
| 3169 while (*p++) | |
| 3170 ; | |
| 3171 | |
| 3172 return p - s; | |
| 3173 } | |
| 3174 #endif | |
| 1204 | 3175 |
| 3176 /************************************************************************/ | |
| 3177 /* Emulation of missing functions from string.h */ | |
| 3178 /************************************************************************/ | |
| 3179 | |
| 3180 #ifndef HAVE_STRLWR | |
| 3181 char * | |
| 3182 strlwr (char *s) | |
| 3183 { | |
| 3700 | 3184 REGISTER char *c; |
| 3648 | 3185 if (s == NULL) return NULL; |
| 1271 | 3186 |
| 3187 for (c = s; *c; c++) | |
| 1204 | 3188 { |
| 1271 | 3189 *c = tolower (*c); |
| 1204 | 3190 } |
| 1271 | 3191 return s; |
| 1204 | 3192 } |
| 3193 #endif | |
| 3194 | |
| 1271 | 3195 #ifndef HAVE_STRUPR |
| 1204 | 3196 char * |
| 3197 strupr (char *s) | |
| 3198 { | |
| 1271 | 3199 REGISTER char *c; |
| 3200 | |
| 3201 for (c = s; *c; c++) | |
| 1204 | 3202 { |
| 1271 | 3203 *c = toupper (*c); |
| 1204 | 3204 } |
| 1271 | 3205 return s; |
| 1204 | 3206 } |
| 3207 #endif | |
| 912 | 3208 |
| 428 | 3209 |
| 3210 /************************************************************************/ | |
| 3211 /* Emulations of missing system calls */ | |
| 3212 /************************************************************************/ | |
| 3213 | |
| 3214 /***** (these are primarily required for USG, it seems) *****/ | |
| 3215 | |
| 3216 /* | |
| 3217 * Emulate rename using unlink/link. Note that this is | |
| 3218 * only partially correct. Also, doesn't enforce restriction | |
| 3219 * that files be of same type (regular->regular, dir->dir, etc). | |
| 3220 */ | |
| 3221 | |
| 3222 #ifndef HAVE_RENAME | |
| 3223 int | |
| 771 | 3224 rename (const Extbyte *from, const Extbyte *to) |
| 428 | 3225 { |
| 3226 if (access (from, 0) == 0) | |
| 3227 { | |
| 3228 unlink (to); | |
| 3229 if (link (from, to) == 0) | |
| 3230 if (unlink (from) == 0) | |
| 3231 return (0); | |
| 3232 } | |
| 3233 return (-1); | |
| 3234 } | |
| 3235 #endif /* HAVE_RENAME */ | |
| 3236 | |
| 3237 #ifdef HPUX | |
| 3238 #ifndef HAVE_PERROR | |
| 3239 | |
| 3240 /* HPUX curses library references perror, but as far as we know | |
| 3241 it won't be called. Anyway this definition will do for now. */ | |
| 3242 | |
| 3243 perror (void) | |
| 3244 { | |
| 3245 } | |
| 3246 | |
| 3247 #endif /* not HAVE_PERROR */ | |
| 3248 #endif /* HPUX */ | |
| 3249 | |
| 3250 #ifndef HAVE_DUP2 | |
| 3251 | |
| 3252 /* | |
| 3253 * Emulate BSD dup2. First close newd if it already exists. | |
| 3254 * Then, attempt to dup oldd. If not successful, call dup2 recursively | |
| 3255 * until we are, then close the unsuccessful ones. | |
| 3256 */ | |
| 3257 | |
| 3258 int | |
| 3259 dup2 (int oldd, int newd) | |
| 3260 { | |
| 3261 int fd, ret; | |
| 3262 | |
| 771 | 3263 retry_close (newd); |
| 428 | 3264 |
| 3265 #ifdef F_DUPFD | |
| 3266 fd = fcntl (oldd, F_DUPFD, newd); | |
| 3267 if (fd != newd) | |
| 563 | 3268 signal_ferror_with_frob (Qfile_error, lisp_strerror (errno), |
| 3269 "can't dup2 (%i, %i)", oldd, newd); | |
| 428 | 3270 #else |
| 2957 | 3271 fd = dup (oldd); |
| 428 | 3272 if (fd == -1) |
| 3273 return -1; | |
| 2957 | 3274 if (fd == newd) |
| 3275 return newd; | |
| 3276 ret = dup2 (oldd, newd); | |
| 771 | 3277 retry_close (fd); |
| 428 | 3278 return ret; |
| 3279 #endif /* F_DUPFD */ | |
| 3280 } | |
| 3281 | |
| 3282 #endif /* not HAVE_DUP2 */ | |
| 3283 | |
| 3284 /* | |
| 3285 * Gettimeofday. Simulate as much as possible. Only accurate | |
| 3286 * to nearest second. Emacs doesn't use tzp so ignore it for now. | |
| 3287 */ | |
| 3288 | |
| 3289 #if !defined (HAVE_GETTIMEOFDAY) | |
| 3290 | |
| 3291 int | |
| 3292 gettimeofday (struct timeval *tp, struct timezone *tzp) | |
| 3293 { | |
| 3294 extern long time (); | |
| 3295 | |
| 3296 tp->tv_sec = time ((long *)0); | |
| 3297 tp->tv_usec = 0; | |
| 3298 if (tzp != 0) | |
| 3299 tzp->tz_minuteswest = -1; | |
| 3300 return (0); | |
| 3301 } | |
| 3302 | |
| 3303 #endif /* !HAVE_GETTIMEOFDAY */ | |
| 3304 | |
| 3305 /* No need to encapsulate utime and utimes explicitly because all | |
| 3306 access to those functions goes through the following. */ | |
| 3307 | |
| 3308 int | |
| 2340 | 3309 set_file_times ( |
| 3310 #if defined (WIN32_NATIVE) || defined (HAVE_UTIME) || defined (HAVE_UTIMES) | |
| 3311 Lisp_Object path, EMACS_TIME atime, EMACS_TIME mtime | |
| 3312 #else | |
| 3313 Lisp_Object UNUSED (path), EMACS_TIME UNUSED (atime), | |
| 3314 EMACS_TIME UNUSED (mtime) | |
| 3315 #endif | |
| 3316 ) | |
| 428 | 3317 { |
| 592 | 3318 #if defined (WIN32_NATIVE) |
| 460 | 3319 struct utimbuf utb; |
| 3320 utb.actime = EMACS_SECS (atime); | |
| 3321 utb.modtime = EMACS_SECS (mtime); | |
| 592 | 3322 return mswindows_utime (path, &utb); |
| 3323 #elif defined (HAVE_UTIME) | |
| 3324 struct utimbuf utb; | |
| 3325 Extbyte *filename; | |
| 3326 utb.actime = EMACS_SECS (atime); | |
| 3327 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
|
3328 LISP_PATHNAME_CONVERT_OUT (path, filename); |
| 460 | 3329 return utime (filename, &utb); |
| 3330 #elif defined (HAVE_UTIMES) | |
| 428 | 3331 struct timeval tv[2]; |
| 592 | 3332 Extbyte *filename; |
| 428 | 3333 tv[0] = atime; |
| 3334 tv[1] = mtime; | |
|
4981
4aebb0131297
Cleanups/renaming of EXTERNAL_TO_C_STRING and friends
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3335 LISP_PATHNAME_CONVERT_OUT (path, filename); |
| 428 | 3336 return utimes (filename, tv); |
| 460 | 3337 #else |
| 3338 /* No file times setting function available. */ | |
| 3339 return -1; | |
| 3340 #endif | |
| 428 | 3341 } |
| 3342 | |
| 3343 /* */ | |
| 3344 | |
| 3345 static long ticks_per_second; | |
| 3346 static long orig_user_ticks, orig_system_ticks; | |
| 3347 EMACS_TIME orig_real_time; | |
| 3348 | |
| 3349 static int process_times_available; | |
| 3350 | |
| 3351 /* Return the relative user and system tick count. We try to | |
| 3352 maintain calculations in terms of integers as long as possible | |
| 3353 for increased accuracy. */ | |
| 3354 | |
| 3355 static int | |
| 2340 | 3356 get_process_times_1 ( |
| 3357 #if defined (CLOCKS_PER_SEC) || defined (_SC_CLK_TCK) || defined (CLK_TCK) && !defined(WIN32_NATIVE) | |
| 3358 long *user_ticks, long *system_ticks | |
| 3359 #else | |
| 3360 long *UNUSED (user_ticks), long *UNUSED (system_ticks) | |
| 3361 #endif | |
| 3362 ) | |
| 428 | 3363 { |
| 442 | 3364 #if defined (_SC_CLK_TCK) || defined (CLK_TCK) && !defined(WIN32_NATIVE) |
| 428 | 3365 /* We have the POSIX times() function available. */ |
| 777 | 3366 /* #### Perhaps we should just use a configure test for times()? */ |
| 428 | 3367 struct tms tttt; |
| 3368 times (&tttt); | |
| 3369 *user_ticks = (long) tttt.tms_utime; | |
| 3370 *system_ticks = (long) tttt.tms_stime; | |
| 3371 return 1; | |
| 3372 #elif defined (CLOCKS_PER_SEC) | |
| 3373 *user_ticks = (long) clock (); | |
| 3374 *system_ticks = 0; | |
| 3375 return 1; | |
| 3376 #else | |
| 3377 return 0; | |
| 3378 #endif | |
| 3379 } | |
| 3380 | |
| 3381 void | |
| 3382 init_process_times_very_early (void) | |
| 3383 { | |
| 3384 #if defined (_SC_CLK_TCK) | |
| 3385 ticks_per_second = sysconf (_SC_CLK_TCK); | |
| 3386 #elif defined (CLK_TCK) | |
| 3387 ticks_per_second = CLK_TCK; | |
| 3388 #elif defined (CLOCKS_PER_SEC) | |
| 3389 ticks_per_second = CLOCKS_PER_SEC; | |
| 3390 #endif | |
| 3391 | |
| 3392 process_times_available = get_process_times_1 (&orig_user_ticks, | |
| 3393 &orig_system_ticks); | |
| 3394 EMACS_GET_TIME (orig_real_time); | |
| 3395 } | |
| 3396 | |
| 3397 /* Return the user and system times used up by this process so far. */ | |
| 3398 void | |
| 3399 get_process_times (double *user_time, double *system_time, double *real_time) | |
| 3400 { | |
| 3401 EMACS_TIME curr_real_time; | |
| 3402 EMACS_TIME elapsed_time; | |
| 3403 long curr_user_ticks, curr_system_ticks; | |
| 3404 | |
| 3405 EMACS_GET_TIME (curr_real_time); | |
| 3406 EMACS_SUB_TIME (elapsed_time, curr_real_time, orig_real_time); | |
| 3407 *real_time = (EMACS_SECS (elapsed_time) | |
| 3408 + ((double) EMACS_USECS (elapsed_time)) / 1000000); | |
| 3409 if (get_process_times_1 (&curr_user_ticks, &curr_system_ticks)) | |
| 3410 { | |
| 3411 *user_time = (((double) (curr_user_ticks - orig_user_ticks)) | |
| 3412 / ticks_per_second); | |
| 3413 *system_time = (((double) (curr_system_ticks - orig_system_ticks)) | |
| 3414 / ticks_per_second); | |
| 3415 } | |
| 3416 else | |
| 3417 { | |
| 3418 /* A lame OS */ | |
| 3419 *user_time = *real_time; | |
| 3420 *system_time = 0; | |
| 3421 } | |
| 3422 } | |
| 3423 | |
| 3424 #ifndef HAVE_RANDOM | |
| 3425 #ifdef random | |
| 3426 #define HAVE_RANDOM | |
| 3427 #endif | |
| 3428 #endif | |
| 3429 | |
| 3430 /* Figure out how many bits the system's random number generator uses. | |
| 3431 `random' and `lrand48' are assumed to return 31 usable bits. | |
| 3432 BSD `rand' returns a 31 bit value but the low order bits are unusable; | |
| 3433 so we'll shift it and treat it like the 15-bit USG `rand'. */ | |
| 3434 | |
| 3435 #ifndef RAND_BITS | |
| 3436 # ifdef HAVE_RANDOM | |
| 3437 # define RAND_BITS 31 | |
| 3438 # else /* !HAVE_RANDOM */ | |
| 3439 # ifdef HAVE_LRAND48 | |
| 3440 # define RAND_BITS 31 | |
| 3441 # define random lrand48 | |
| 3442 # else /* !HAVE_LRAND48 */ | |
| 3443 # define RAND_BITS 15 | |
| 3444 # if RAND_MAX == 32767 | |
| 3445 # define random rand | |
| 3446 # else /* RAND_MAX != 32767 */ | |
| 3447 # if RAND_MAX == 2147483647 | |
| 3448 # define random() (rand () >> 16) | |
| 3449 # else /* RAND_MAX != 2147483647 */ | |
| 3450 # ifdef USG | |
| 3451 # define random rand | |
| 3452 # else | |
| 3453 # define random() (rand () >> 16) | |
| 3454 # endif /* !BSD */ | |
| 3455 # endif /* RAND_MAX != 2147483647 */ | |
| 3456 # endif /* RAND_MAX != 32767 */ | |
| 3457 # endif /* !HAVE_LRAND48 */ | |
| 3458 # endif /* !HAVE_RANDOM */ | |
| 3459 #endif /* !RAND_BITS */ | |
| 3460 | |
| 3461 void | |
| 3462 seed_random (long arg) | |
| 3463 { | |
| 3464 #ifdef HAVE_RANDOM | |
| 3465 srandom ((unsigned int)arg); | |
| 3466 #else | |
| 3467 # ifdef HAVE_LRAND48 | |
| 3468 srand48 (arg); | |
| 3469 # else | |
| 3470 srand ((unsigned int)arg); | |
| 3471 # endif | |
| 3472 #endif | |
| 1983 | 3473 #ifdef HAVE_BIGNUM |
| 3474 bignum_random_seed ((unsigned long) arg); | |
| 3475 #endif | |
| 428 | 3476 } |
| 3477 | |
| 3478 /* | |
| 3479 * Build a full Emacs-sized word out of whatever we've got. | |
| 3480 * This suffices even for a 64-bit architecture with a 15-bit rand. | |
| 3481 */ | |
| 3482 long | |
| 3483 get_random (void) | |
| 3484 { | |
| 3485 long val = random (); | |
| 2039 | 3486 #if INT_VALBITS > RAND_BITS |
| 428 | 3487 val = (val << RAND_BITS) ^ random (); |
| 2039 | 3488 #if INT_VALBITS > 2*RAND_BITS |
| 428 | 3489 val = (val << RAND_BITS) ^ random (); |
| 2039 | 3490 #if INT_VALBITS > 3*RAND_BITS |
| 428 | 3491 val = (val << RAND_BITS) ^ random (); |
| 2039 | 3492 #if INT_VALBITS > 4*RAND_BITS |
| 428 | 3493 val = (val << RAND_BITS) ^ random (); |
| 3494 #endif /* need at least 5 */ | |
| 3495 #endif /* need at least 4 */ | |
| 3496 #endif /* need at least 3 */ | |
| 3497 #endif /* need at least 2 */ | |
| 2039 | 3498 return val & (EMACS_INT) ((1UL << INT_VALBITS) - 1); |
| 428 | 3499 } |
| 3500 | |
| 3501 | |
| 3502 /************************************************************************/ | |
| 3503 /* Strings corresponding to defined signals */ | |
| 3504 /************************************************************************/ | |
| 3505 | |
| 2762 | 3506 #if (!defined(HAVE_DECL_SYS_SIGLIST) || !HAVE_DECL_SYS_SIGLIST ) && !defined (HAVE_SYS_SIGLIST) |
| 428 | 3507 |
| 442 | 3508 #if defined(WIN32_NATIVE) || defined(CYGWIN) |
| 3509 const char *sys_siglist[] = | |
| 428 | 3510 { |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3511 /* @@@begin-snarf@@@ */ |
| 428 | 3512 "bum signal!!", |
| 3513 "hangup", | |
| 3514 "interrupt", | |
| 3515 "quit", | |
| 3516 "illegal instruction", | |
| 3517 "trace trap", | |
| 3518 "iot instruction", | |
| 3519 "emt instruction", | |
| 3520 "floating point exception", | |
| 3521 "kill", | |
| 3522 "bus error", | |
| 3523 "segmentation violation", | |
| 3524 "bad argument to system call", | |
| 3525 "write on a pipe with no one to read it", | |
| 3526 "alarm clock", | |
| 3527 "software termination signal from kill", | |
| 3528 "status signal", | |
| 3529 "sendable stop signal not from tty", | |
| 3530 "stop signal from tty", | |
| 3531 "continue a stopped process", | |
| 3532 "child status has changed", | |
| 3533 "background read attempted from control tty", | |
| 3534 "background write attempted from control tty", | |
| 3535 "input record available at control tty", | |
| 3536 "exceeded CPU time limit", | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3537 "exceeded file size limit", |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3538 /* @@@end-snarf@@@ */ |
| 428 | 3539 }; |
| 3540 #endif | |
| 3541 | |
| 3542 #ifdef USG | |
| 3543 #ifdef AIX | |
| 442 | 3544 const char *sys_siglist[NSIG + 1] = |
| 428 | 3545 { |
| 3546 /* 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
|
3547 /* @@@begin-snarf@@@ */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3548 "bogus signal", /* 0 */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3549 "hangup", /* 1 SIGHUP */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3550 "interrupt", /* 2 SIGINT */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3551 "quit", /* 3 SIGQUIT */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3552 "illegal instruction", /* 4 SIGILL */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3553 "trace trap", /* 5 SIGTRAP */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3554 "IOT instruction", /* 6 SIGIOT */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3555 "crash likely", /* 7 SIGDANGER */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3556 "floating point exception", /* 8 SIGFPE */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3557 "kill", /* 9 SIGKILL */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3558 "bus error", /* 10 SIGBUS */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3559 "segmentation violation", /* 11 SIGSEGV */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3560 "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
|
3561 "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
|
3562 "alarm clock", /* 14 SIGALRM */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3563 "software termination signal", /* 15 SIGTERM */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3564 "user defined signal 1", /* 16 SIGUSR1 */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3565 "user defined signal 2", /* 17 SIGUSR2 */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3566 "death of a child", /* 18 SIGCLD */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3567 "power-fail restart", /* 19 SIGPWR */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3568 "bogus signal", /* 20 */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3569 "bogus signal", /* 21 */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3570 "bogus signal", /* 22 */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3571 "bogus signal", /* 23 */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3572 "bogus signal", /* 24 */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3573 "LAN I/O interrupt", /* 25 SIGAIO */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3574 "PTY I/O interrupt", /* 26 SIGPTY */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3575 "I/O intervention required", /* 27 SIGIOINT */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3576 /* @@@end-snarf@@@ */ |
| 428 | 3577 0 |
| 3578 }; | |
| 3579 #else /* USG, not AIX */ | |
| 442 | 3580 const char *sys_siglist[NSIG + 1] = |
| 428 | 3581 { |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3582 /* @@@begin-snarf@@@ */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3583 "bogus signal", /* 0 */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3584 "hangup", /* 1 SIGHUP */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3585 "interrupt", /* 2 SIGINT */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3586 "quit", /* 3 SIGQUIT */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3587 "illegal instruction", /* 4 SIGILL */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3588 "trace trap", /* 5 SIGTRAP */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3589 "IOT instruction", /* 6 SIGIOT */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3590 "EMT instruction", /* 7 SIGEMT */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3591 "floating point exception", /* 8 SIGFPE */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3592 "kill", /* 9 SIGKILL */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3593 "bus error", /* 10 SIGBUS */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3594 "segmentation violation", /* 11 SIGSEGV */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3595 "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
|
3596 "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
|
3597 "alarm clock", /* 14 SIGALRM */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3598 "software termination signal", /* 15 SIGTERM */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3599 "user defined signal 1", /* 16 SIGUSR1 */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3600 "user defined signal 2", /* 17 SIGUSR2 */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3601 "death of a child", /* 18 SIGCLD */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3602 "power-fail restart", /* 19 SIGPWR */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3603 #ifdef sun |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3604 "window size changed", /* 20 SIGWINCH */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3605 "urgent socket condition", /* 21 SIGURG */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3606 "pollable event occurred", /* 22 SIGPOLL */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3607 "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
|
3608 "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
|
3609 "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
|
3610 "background tty read attempted", /* 26 SIGTTIN */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3611 "background tty write attempted", /* 27 SIGTTOU */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3612 "virtual timer expired", /* 28 SIGVTALRM */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3613 "profiling timer expired", /* 29 SIGPROF */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3614 "exceeded cpu limit", /* 30 SIGXCPU */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3615 "exceeded file size limit", /* 31 SIGXFSZ */ |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3616 "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
|
3617 "special signal used by thread library", /* 33 SIGLWP */ |
| 428 | 3618 #ifdef SIGFREEZE |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3619 "special signal used by CPR", /* 34 SIGFREEZE */ |
| 428 | 3620 #endif |
| 3621 #ifdef SIGTHAW | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3622 "special signal used by CPR", /* 35 SIGTHAW */ |
| 428 | 3623 #endif |
| 3624 #endif /* sun */ | |
|
4952
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 #endif /* not AIX */ | |
| 3629 #endif /* USG */ | |
| 3630 | |
| 2762 | 3631 #endif /* (!defined(HAVE_DECL_SYS_SIGLIST) || !HAVE_DECL_SYS_SIGLIST ) && !defined (HAVE_SYS_SIGLIST) */ |
| 428 | 3632 |
| 3633 | |
| 3634 /************************************************************************/ | |
| 3635 /* Directory routines for systems that don't have them */ | |
| 3636 /************************************************************************/ | |
| 3637 | |
| 3638 #ifdef SYSV_SYSTEM_DIR | |
| 3639 | |
| 3640 #include <dirent.h> | |
| 3641 | |
|
4759
aa5ed11f473b
Remove support for obsolete systems. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents:
3700
diff
changeset
|
3642 #if !defined(HAVE_CLOSEDIR) |
| 428 | 3643 int |
| 3644 closedir (DIR *dirp) /* stream from opendir */ | |
| 3645 { | |
| 3646 int rtnval; | |
| 3647 | |
| 771 | 3648 rtnval = retry_close (dirp->dd_fd); |
| 428 | 3649 |
| 3650 /* Some systems (like Solaris) allocate the buffer and the DIR all | |
| 3651 in one block. Why in the world are we freeing this ourselves | |
| 3652 anyway? */ | |
| 3653 #if ! (defined (sun) && defined (USG5_4)) | |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3654 xfree (dirp->dd_buf); /* directory block defined in <dirent.h> */ |
| 428 | 3655 #endif |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3656 xfree (dirp); |
| 428 | 3657 return (rtnval); |
| 3658 } | |
|
4759
aa5ed11f473b
Remove support for obsolete systems. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents:
3700
diff
changeset
|
3659 #endif /* not HAVE_CLOSEDIR */ |
| 428 | 3660 #endif /* SYSV_SYSTEM_DIR */ |
| 3661 | |
| 3662 #ifdef NONSYSTEM_DIR_LIBRARY | |
| 3663 | |
| 3664 DIR * | |
| 442 | 3665 opendir (const char *filename) /* name of directory */ |
| 428 | 3666 { |
| 3667 DIR *dirp; /* -> malloc'ed storage */ | |
| 3668 int fd; /* file descriptor for read */ | |
| 3669 struct stat sbuf; /* result of fstat */ | |
| 3670 | |
| 771 | 3671 fd = open (filename, O_RDONLY); |
| 428 | 3672 if (fd < 0) |
| 3673 return 0; | |
| 3674 | |
| 3675 if (fstat (fd, &sbuf) < 0 | |
| 3676 || (sbuf.st_mode & S_IFMT) != S_IFDIR | |
| 3677 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0) | |
| 3678 { | |
| 771 | 3679 retry_close (fd); |
| 428 | 3680 return 0; /* bad luck today */ |
| 3681 } | |
| 3682 | |
| 3683 dirp->dd_fd = fd; | |
| 3684 dirp->dd_loc = dirp->dd_size = 0; /* refill needed */ | |
| 3685 | |
| 3686 return dirp; | |
| 3687 } | |
| 3688 | |
| 3689 void | |
| 3690 closedir (DIR *dirp) /* stream from opendir */ | |
| 3691 { | |
| 771 | 3692 retry_close (dirp->dd_fd); |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3693 xfree (dirp); |
| 428 | 3694 } |
| 3695 | |
| 3696 | |
| 3697 #define DIRSIZ 14 | |
| 3698 struct olddir | |
| 3699 { | |
| 3700 ino_t od_ino; /* inode */ | |
| 3701 char od_name[DIRSIZ]; /* filename */ | |
| 3702 }; | |
| 3703 | |
| 3704 static struct direct dir_static; /* simulated directory contents */ | |
| 3705 | |
| 3706 /* ARGUSED */ | |
| 3707 struct direct * | |
| 3708 readdir (DIR *dirp) /* stream from opendir */ | |
| 3709 { | |
| 3710 struct olddir *dp; /* -> directory data */ | |
| 3711 | |
| 3712 for (; ;) | |
| 3713 { | |
| 3714 if (dirp->dd_loc >= dirp->dd_size) | |
| 3715 dirp->dd_loc = dirp->dd_size = 0; | |
| 3716 | |
| 3717 if (dirp->dd_size == 0 /* refill buffer */ | |
| 771 | 3718 && (dirp->dd_size = |
| 3719 retry_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0) | |
| 428 | 3720 return 0; |
| 3721 | |
| 3722 dp = (struct olddir *) &dirp->dd_buf[dirp->dd_loc]; | |
| 3723 dirp->dd_loc += sizeof (struct olddir); | |
| 3724 | |
| 3725 if (dp->od_ino != 0) /* not deleted entry */ | |
| 3726 { | |
| 3727 dir_static.d_ino = dp->od_ino; | |
| 3728 strncpy (dir_static.d_name, dp->od_name, DIRSIZ); | |
| 3729 dir_static.d_name[DIRSIZ] = '\0'; | |
| 3730 dir_static.d_namlen = strlen (dir_static.d_name); | |
| 3731 dir_static.d_reclen = sizeof (struct direct) | |
| 3732 - MAXNAMLEN + 3 | |
| 3733 + dir_static.d_namlen - dir_static.d_namlen % 4; | |
| 3734 return &dir_static; /* -> simulated structure */ | |
| 3735 } | |
| 3736 } | |
| 3737 } | |
| 3738 | |
| 3739 | |
| 3740 #endif /* NONSYSTEM_DIR_LIBRARY */ | |
| 3741 | |
| 3742 | |
| 3743 /* mkdir and rmdir functions, for systems which don't have them. */ | |
| 3744 | |
| 3745 #ifndef HAVE_MKDIR | |
| 3746 /* | |
| 3747 * Written by Robert Rother, Mariah Corporation, August 1985. | |
| 3748 * | |
| 3749 * If you want it, it's yours. All I ask in return is that if you | |
| 3750 * figure out how to do this in a Bourne Shell script you send me | |
| 3751 * a copy. | |
| 3752 * sdcsvax!rmr or rmr@uscd | |
| 3753 * | |
| 3754 * Severely hacked over by John Gilmore to make a 4.2BSD compatible | |
| 3755 * subroutine. 11Mar86; hoptoad!gnu | |
| 3756 * | |
| 3757 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir, | |
| 3758 * subroutine didn't return EEXIST. It does now. | |
| 3759 */ | |
| 3760 | |
| 3761 /* | |
| 3762 * Make a directory. | |
| 3763 */ | |
| 3764 #ifdef MKDIR_PROTOTYPE | |
| 3765 MKDIR_PROTOTYPE | |
| 3766 #else | |
| 3767 int | |
| 442 | 3768 mkdir (const char *dpath, int dmode) |
| 428 | 3769 #endif |
| 3770 { | |
| 3771 int cpid, status, fd; | |
| 3772 struct stat statbuf; | |
| 3773 | |
| 442 | 3774 if (stat (dpath, &statbuf) == 0) /* we do want stat() here */ |
| 428 | 3775 { |
| 3776 errno = EEXIST; /* Stat worked, so it already exists */ | |
| 3777 return -1; | |
| 3778 } | |
| 3779 | |
| 3780 /* If stat fails for a reason other than non-existence, return error */ | |
| 3781 if (errno != ENOENT) | |
| 3782 return -1; | |
| 3783 | |
| 3784 synch_process_alive = 1; | |
| 3785 switch (cpid = fork ()) | |
| 3786 { | |
| 3787 | |
| 3788 case -1: /* Error in fork() */ | |
| 3789 return -1; /* Errno is set already */ | |
| 3790 | |
| 3791 case 0: /* Child process */ | |
| 3792 { | |
| 3793 /* | |
| 3794 * Cheap hack to set mode of new directory. Since this | |
| 3795 * child process is going away anyway, we zap its umask. | |
| 3796 * ####, this won't suffice to set SUID, SGID, etc. on this | |
| 3797 * directory. Does anybody care? | |
| 3798 */ | |
| 3799 status = umask (0); /* Get current umask */ | |
| 3800 status = umask (status | (0777 & ~dmode)); /* Set for mkdir */ | |
| 771 | 3801 fd = open ("/dev/null", O_RDWR); |
| 428 | 3802 if (fd >= 0) |
| 3803 { | |
| 3804 if (fd != STDIN_FILENO) dup2 (fd, STDIN_FILENO); | |
| 3805 if (fd != STDOUT_FILENO) dup2 (fd, STDOUT_FILENO); | |
| 3806 if (fd != STDERR_FILENO) dup2 (fd, STDERR_FILENO); | |
| 3807 } | |
| 3808 execl ("/bin/mkdir", "mkdir", dpath, (char *) 0); | |
| 3809 _exit (-1); /* Can't exec /bin/mkdir */ | |
| 3810 } | |
| 3811 | |
| 3812 default: /* Parent process */ | |
| 3813 wait_for_termination (cpid); | |
| 3814 } | |
| 3815 | |
| 3816 if (synch_process_death != 0 || synch_process_retcode != 0) | |
| 3817 { | |
| 3818 errno = EIO; /* We don't know why, but */ | |
| 3819 return -1; /* /bin/mkdir failed */ | |
| 3820 } | |
| 3821 | |
| 3822 return 0; | |
| 3823 } | |
| 3824 #endif /* not HAVE_MKDIR */ | |
| 3825 | |
| 3826 #ifndef HAVE_RMDIR | |
| 3827 int | |
| 442 | 3828 rmdir (const char *dpath) |
| 428 | 3829 { |
| 3830 int cpid, status, fd; | |
| 3831 struct stat statbuf; | |
| 3832 | |
| 442 | 3833 if (stat (dpath, &statbuf) != 0) /* we do want stat() here */ |
| 428 | 3834 { |
| 3835 /* Stat just set errno. We don't have to */ | |
| 3836 return -1; | |
| 3837 } | |
| 3838 | |
| 3839 synch_process_alive = 1; | |
| 3840 switch (cpid = fork ()) | |
| 3841 { | |
| 3842 | |
| 3843 case -1: /* Error in fork() */ | |
| 3844 return (-1); /* Errno is set already */ | |
| 3845 | |
| 3846 case 0: /* Child process */ | |
| 771 | 3847 fd = open ("/dev/null", O_RDWR); |
| 428 | 3848 if (fd >= 0) |
| 3849 { | |
| 3850 if (fd != STDIN_FILENO) dup2 (fd, STDIN_FILENO); | |
| 3851 if (fd != STDOUT_FILENO) dup2 (fd, STDOUT_FILENO); | |
| 3852 if (fd != STDERR_FILENO) dup2 (fd, STDERR_FILENO); | |
| 3853 } | |
| 3854 execl ("/bin/rmdir", "rmdir", dpath, (char *) 0); | |
| 3855 _exit (-1); /* Can't exec /bin/mkdir */ | |
| 3856 | |
| 3857 default: /* Parent process */ | |
| 3858 wait_for_termination (cpid); | |
| 3859 } | |
| 3860 | |
| 3861 if (synch_process_death != 0 || | |
| 3862 synch_process_retcode != 0) | |
| 3863 { | |
| 3864 errno = EIO; /* We don't know why, but */ | |
| 3865 return -1; /* /bin/rmdir failed */ | |
| 3866 } | |
| 3867 | |
| 3868 return 0; | |
| 3869 } | |
| 3870 #endif /* !HAVE_RMDIR */ | |
| 3871 | |
| 3872 | |
| 3873 /************************************************************************/ | |
| 3874 /* Misc. SunOS crap */ | |
| 3875 /************************************************************************/ | |
| 3876 | |
| 3877 #ifdef USE_DL_STUBS | |
| 3878 | |
| 3879 /* These are included on Sunos 4.1 when we do not use shared libraries. | |
| 3880 X11 libraries may refer to these functions but (we hope) do not | |
| 3881 actually call them. */ | |
| 3882 | |
| 3883 void * | |
| 3884 dlopen (void) | |
| 3885 { | |
| 3886 return 0; | |
| 3887 } | |
| 3888 | |
| 3889 void * | |
| 3890 dlsym (void) | |
| 3891 { | |
| 3892 return 0; | |
| 3893 } | |
| 3894 | |
| 3895 int | |
| 3896 dlclose (void) | |
| 3897 { | |
| 3898 return -1; | |
| 3899 } | |
| 3900 | |
| 3901 #endif /* USE_DL_STUBS */ |
