/* Interfaces to system-dependent kernel and library entries. Copyright (C) 1985-1988, 1993-1995, 1999-2022 Free Software Foundation, Inc. This file is part of GNU Emacs. GNU Emacs is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ #include #include #include "sysstdio.h" #ifdef HAVE_PWD_H #include #include #endif /* HAVE_PWD_H */ #include #include #include #include #include #include #include #include #include "lisp.h" #include "sheap.h" #include "sysselect.h" #include "blockinput.h" #ifdef HAVE_LINUX_FS_H # include # include #endif #ifdef CYGWIN # include #endif #if defined DARWIN_OS || defined __FreeBSD__ || defined __OpenBSD__ # include #endif #if defined __OpenBSD__ # include #endif #ifdef DARWIN_OS # include #endif #ifdef __FreeBSD__ /* Sparc/ARM machine/frame.h has 'struct frame' which conflicts with Emacs's 'struct frame', so rename it. */ # define frame freebsd_frame # include # undef frame # include #endif #ifdef HAVE_SOCKETS #include #include #endif /* HAVE_SOCKETS */ #ifdef WINDOWSNT #define read sys_read #define write sys_write #ifndef STDERR_FILENO #define STDERR_FILENO fileno(GetStdHandle(STD_ERROR_HANDLE)) #endif #include "w32.h" #endif /* WINDOWSNT */ #include #include #include /* Get SI_SRPC_DOMAIN, if it is available. */ #ifdef HAVE_SYS_SYSTEMINFO_H #include #endif #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */ #include "msdos.h" #endif #include #include #include #include "syssignal.h" #include "systime.h" #include "systty.h" #include "syswait.h" #ifdef HAVE_SYS_RESOURCE_H # include #endif #ifdef HAVE_SYS_UTSNAME_H # include # include #endif #include "keyboard.h" #include "frame.h" #include "termhooks.h" #include "termchar.h" #include "termopts.h" #include "process.h" #include "cm.h" #ifndef MAX_RW_COUNT #define MAX_RW_COUNT (INT_MAX >> 18 << 18) #endif /* Read from FD to a buffer BUF with size NBYTE. If interrupted, process any quits and pending signals immediately if INTERRUPTIBLE, and then retry the read unless quitting. Return the number of bytes read, which might be less than NBYTE. On error, set errno to a value other than EINTR, and return -1. */ static ptrdiff_t emacs_intr_read (int fd, void *buf, ptrdiff_t nbyte, bool interruptible) { /* No caller should ever pass a too-large size to emacs_read. */ eassert (nbyte <= MAX_RW_COUNT); ssize_t result; do { if (interruptible) maybe_quit (); result = read (fd, buf, nbyte); } while (result < 0 && errno == EINTR); return result; } ptrdiff_t emacs_read (int fd, void *buf, ptrdiff_t nbyte) { return emacs_intr_read (fd, buf, nbyte, false); } /* Like emacs_read, but also process quits and pending signals. */ ptrdiff_t emacs_read_quit (int fd, void *buf, ptrdiff_t nbyte) { return emacs_intr_read (fd, buf, nbyte, true); }