📄 sysdep.c
字号:
#else /* no FIONREAD */ /* Hoping it will return -1 if nothing available or 0 if all 0 chars requested are read. */ if (proc_buffered_char[fd] >= 0) avail = 1; else { avail = read (fd, &buf, 1); if (avail > 0) proc_buffered_char[fd] = buf; }#endif /* no FIONREAD */ } if (status >= 0 && avail > 0) { (*rfds) |= bit; ravail++; } } } } if (*local_timeout == 0 || ravail != 0 || process_tick != update_tick) break; old_alarm = alarm (0); old_trap = (int (*)()) signal (SIGALRM, select_alarm); select_alarmed = 0; alarm (SELECT_PAUSE); /* Wait for a SIGALRM (or maybe a SIGTINT) */ while (select_alarmed == 0 && *local_timeout != 0 && process_tick == update_tick) { /* If we are interested in terminal input, wait by reading the terminal. That makes instant wakeup for terminal input at least. */ if (orfds & 1) { read_input_waiting (); if (kbd_count) select_alarmed = 1; } else pause(); } (*local_timeout) -= SELECT_PAUSE; /* Reset the old alarm if there was one */ alarm (0); signal (SIGALRM, old_trap); if (old_alarm != 0) { /* Reset or forge an interrupt for the original handler. */ old_alarm -= SELECT_PAUSE; if (old_alarm <= 0) kill (getpid (), SIGALRM); /* Fake an alarm with the orig' handler */ else alarm (old_alarm); } if (*local_timeout == 0) /* Stop on timer being cleared */ break; } return ravail;}/* Read keyboard input into the standard buffer, waiting for at least one character. *//* Make all keyboard buffers much bigger when using X windows. */#ifdef HAVE_X_WINDOWS#define BUFFER_SIZE_FACTOR 16#else#define BUFFER_SIZE_FACTOR 1#endifread_input_waiting (){ extern int kbd_count; extern unsigned char kbd_buffer[]; extern unsigned char *kbd_ptr; int val; if (read_socket_hook) { read_alarm_should_throw = 0; if (! setjmp (read_alarm_throw)) val = (*read_socket_hook) (0, kbd_buffer, 256 * BUFFER_SIZE_FACTOR); else val = -1; } else val = read (fileno (stdin), kbd_buffer, 1); if (val > 0) { kbd_ptr = kbd_buffer; kbd_count = val; }}#endif /* not HAVE_SELECT */#ifdef BSD4_1/* VARARGS */setpriority (){ return 0;}/* * Partially emulate 4.2 open call. * open is defined as this in 4.1. * * - added by Michael Bloom @ Citicorp/TTI * */intsys_open (path, oflag, mode) char *path; int oflag, mode;{ if (oflag & O_CREAT) return creat (path, mode); else return open (path, oflag);}init_sigio (){ if (noninteractive) return; lmode = LINTRUP | lmode; ioctl (0, TIOCLSET, &lmode);}reset_sigio (){ if (noninteractive) return; lmode = ~LINTRUP & lmode; ioctl (0, TIOCLSET, &lmode);}request_sigio (){ sigrelse (SIGTINT); interrupts_deferred = 0;}unrequest_sigio (){ sighold (SIGTINT); interrupts_deferred = 1;}/* still inside #ifdef BSD4_1 */#ifdef subprocessesint sigheld; /* Mask of held signals */sigholdx (signum) int signum;{ sigheld |= sigbit (signum); sighold (signum);}sigisheld (signum) int signum;{ sigheld |= sigbit (signum);}sigunhold (signum) int signum;{ sigheld &= ~sigbit (signum); sigrelse (signum);}sigfree () /* Free all held signals */{ int i; for (i = 0; i < NSIG; i++) if (sigheld & sigbit (i)) sigrelse (i); sigheld = 0;}sigbit (i){ return 1 << (i - 1);}#endif /* subprocesses */#endif /* BSD4_1 */#ifndef BSTRINGvoidbzero (b, length) register char *b; register int length;{#ifdef VMS short zero = 0; long max_str = 65535; while (length > max_str) { (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b); length -= max_str; b += max_str; } (void) LIB$MOVC5 (&zero, &zero, &zero, &length, b);#else while (length-- > 0) *b++ = 0;#endif /* not VMS */}/* Saying `void' requires a declaration, above, where bcopy is used and that declaration causes pain for systems where bcopy is a macro. */bcopy (b1, b2, length) register char *b1; register char *b2; register int length;{#ifdef VMS long max_str = 65535; while (length > max_str) { (void) LIB$MOVC3 (&max_str, b1, b2); length -= max_str; b1 += max_str; b2 += max_str; } (void) LIB$MOVC3 (&length, b1, b2);#else while (length-- > 0) *b2++ = *b1++;#endif /* not VMS */}intbcmp (b1, b2, length) /* This could be a macro! */ register char *b1; register char *b2; register int length;{#ifdef VMS struct dsc$descriptor_s src1 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b1}; struct dsc$descriptor_s src2 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b2}; return STR$COMPARE (&src1, &src2);#else while (length-- > 0) if (*b1++ != *b2++) return 1; return 0;#endif /* not VMS */}#endif /* not BSTRING */#ifdef BSD4_1long random (){ return (rand ());}srandom (arg) int arg;{ srand (arg);}#endif BSD4_1#ifdef HPUX#ifdef X11#define HAVE_RANDOM#endif#endif#ifdef USG#ifndef HAVE_RANDOM/* * The BSD random(3) returns numbers in the range of * 0 to 2e31 - 1. The USG rand(3C) returns numbers in the * range of 0 to 2e15 - 1. This is probably not significant * in this usage. */ longrandom (){ /* Arrange to return a range centered on zero. */ return rand () - (1 << 14);}srandom (arg) int arg;{ srand (arg);}#endif /* HAVE_RANDOM */#endif /* USG */#ifdef VMS#ifdef getenv/* If any place else asks for the TERM variable, allow it to be overridden with the EMACS_TERM variable before attempting to translate the logical name TERM. As a last resort, ask for VAX C's special idea of the TERM variable. */#undef getenvchar *sys_getenv (name) char *name;{ register char *val; static char buf[256]; static struct dsc$descriptor_s equiv = {sizeof(buf), DSC$K_DTYPE_T, DSC$K_CLASS_S, buf}; static struct dsc$descriptor_s d_name = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0}; short eqlen; if (!strcmp (name, "TERM")) { val = (char *) getenv ("EMACS_TERM"); if (val) return val; } d_name.dsc$w_length = strlen (name); d_name.dsc$a_pointer = name; if (lib$sys_trnlog (&d_name, &eqlen, &equiv) == 1) { char *str = (char *) xmalloc (eqlen + 1); bcopy (buf, str, eqlen); str[eqlen] = '\0'; /* This is a storage leak, but a pain to fix. With luck, no one will ever notice. */ return str; } return (char *) getenv (name);}#endif /* getenv */#ifdef abort/* Since VMS doesn't believe in core dumps, the only way to debug this beast is to force a call on the debugger from within the image. */#undef abortsys_abort (){ reset_sys_modes (); LIB$SIGNAL (SS$_DEBUG);}#endif /* abort */#endif /* VMS */#ifdef VMS#ifdef LINK_CRTL_SHARE#ifdef SHAREABLE_LIB_BUG/* Variables declared noshare and initialized in shareable libraries cannot be shared. The VMS linker incorrectly forces you to use a private version which is uninitialized... If not for this "feature", we could use the C library definition of sys_nerr and sys_errlist. */int sys_nerr = 35;char *sys_errlist[] = { "error 0", "not owner", "no such file or directory", "no such process", "interrupted system call", "i/o error", "no such device or address", "argument list too long", "exec format error", "bad file number", "no child process", "no more processes", "not enough memory", "permission denied", "bad address", "block device required", "mount devices busy", "file exists", "cross-device link", "no such device", "not a directory", "is a directory", "invalid argument", "file table overflow", "too many open files", "not a typewriter", "text file busy", "file too big", "no space left on device", "illegal seek", "read-only file system", "too many links", "broken pipe", "math argument", "result too large", "I/O stream empty", "vax/vms specific error code nontranslatable error" };#endif /* SHAREABLE_LIB_BUG */#endif /* LINK_CRTL_SHARE */#endif /* VMS */#ifdef INTERRUPTABLE_OPENint/* VARARGS 2 */sys_open (path, oflag, mode) char *path; int oflag, mode;{ register int rtnval; while ((rtnval = open (path, oflag, mode)) == -1 && (errno == EINTR)); return (rtnval);}#endif /* INTERRUPTABLE_OPEN */#ifdef INTERRUPTABLE_CLOSEsys_close (fd) int fd;{ register int rtnval; while ((rtnval = close(fd)) == -1 && (errno == EINTR)); return rtnval;}#endif /* INTERRUPTABLE_CLOSE */#ifdef INTERRUPTABLE_IOintsys_read (fildes, buf, nbyte) int fildes; char *buf; unsigned int nbyte;{ register int rtnval; while ((rtnval = read (fildes, buf, nbyte)) == -1 && (errno == EINTR)); return (rtnval);}intsys_write (fildes, buf, nbyte) int fildes; char *buf; unsigned int nbyte;{ register int rtnval; while ((rtnval = write (fildes, buf, nbyte)) == -1 && (errno == EINTR)); return (rtnval);}#endif /* INTERRUPTABLE_IO */#ifdef USG/* * All of the following are for USG. * * On USG systems the system calls are interruptable by signals * that the user program has elected to catch. Thus the system call * must be retried in these cases. To handle this without massive * changes in the source code, we remap the standard system call names * to names for our own functions in sysdep.c that do the system call * with retries. Actually, for portability reasons, it is good * programming practice, as this example shows, to limit all actual * system calls to a single occurance in the source. Sure, this * adds an extra level of function call overhead but it is almost * always negligible. Fred Fish, Unisoft Systems Inc. */char *sys_siglist[NSIG + 1] ={#ifdef AIX/* AIX has changed the signals a bit */ "bogus signal", /* 0 */ "hangup", /* 1 SIGHUP */ "interrupt", /* 2 SIGINT */ "quit", /* 3 SIGQUIT */ "illegal instruction", /* 4 SIGILL */ "trace trap", /* 5 SIGTRAP */ "IOT instruction", /* 6 SIGIOT */ "crash likely", /* 7 SIGDANGER */ "floating point exception", /* 8 SIGFPE */ "kill", /* 9 SIGKILL */ "bus error", /* 10 SIGBUS */ "segmentation violation", /* 11 SIGSEGV */ "bad argument to system call", /* 12 SIGSYS */ "write on a pipe with no one to read it", /* 13 SIGPIPE */ "alarm clock", /* 14 SIGALRM */ "software termination signum", /* 15 SIGTERM */ "user defined signal 1", /* 16 SIGUSR1 */ "user defined signal 2", /* 17 SIGUSR2 */ "death of a child", /* 18 SIGCLD */ "power-fail restart", /* 19 SIGPWR */ "bogus signal", /* 20 */ "bogus signal", /* 21 */ "bogus signal", /* 22 */ "bogus signal", /* 23 */ "bogus signal", /* 24 */ "LAN I/O interrupt", /* 25 SIGAIO */ "PTY I/O interrupt", /* 26 SIGPTY */ "I/O intervention required", /* 27 SIGIOINT */ "HFT grant", /* 28 SIGGRANT */ "HFT retract", /* 29 SIGRETRACT */ "HFT sound done", /* 30 SIGSOUND */ "HFT input ready", /* 31 SIGMSG */#else /* not AIX */ "bogus signal", /* 0 */ "hangup", /* 1 SIGHUP */ "interrupt", /* 2 SIGINT */ "quit", /* 3 SIGQUIT */ "illegal instruction", /* 4 SIGILL */ "trace trap", /* 5 SIGTRAP */ "IOT instruction", /* 6 SIGIOT */ "EMT instruction", /* 7 SIGEMT */ "floating point exception", /* 8 SIGFPE */ "kill", /* 9 SIGKILL */ "bus error", /* 10 SIGBUS */ "segmentation violation", /* 11 SIGSEGV */ "bad argument to system call", /* 12 SIGSYS */ "write on a pipe with no one to read it", /* 13 SIGPIPE */ "alarm clock", /* 14 SIGALRM */ "software termination signum", /* 15 SIGTERM */ "user defined signal 1", /* 16 SIGUSR1 */ "user defined signal 2", /* 17 SIGUSR2 */ "death of a child", /* 18 SIGCLD */ "power-fail restart", /* 19 SIGPWR */#endif /* not AIX */ 0 };/* * Warning, this function may not duplicate 4.2 action properly * under error conditions. */#ifndef MAXPATHLEN/* In 4.1, param.h fails to define this. */#define MAXPATHLEN 1024#endif#ifndef HAVE_GETWDchar *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -