Partially sync files.el from XEmacs 21.5 for wildcard support.
[sxemacs] / src / sysdep.c
index 7d0536b..7ffad2f 100644 (file)
@@ -41,10 +41,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 #include "ui/TTY/console-tty.h" /* for stuff in stuff_char and
                                   others. Seriously in need of
                                   refactoring... */
-#else
-#include "syssignal.h"
-#include "ui/systty.h"
-#endif                         /* HAVE_TTY */
+#else  /* !HAVE_TTY */
+#include "syssignal.h"         /* always include before systty.h */
+#include "ui/TTY/systty.h"
+#endif  /* HAVE_TTY */
 
 #include "ui/console-stream.h"
 
@@ -806,14 +806,14 @@ void setup_pty(int fd)
 
 void init_baud_rate(struct device *d)
 {
-       struct console *con = XCONSOLE(DEVICE_CONSOLE(d));
        if (DEVICE_WIN_P(d) || DEVICE_STREAM_P(d)) {
                DEVICE_BAUD_RATE(d) = 38400;
                return;
-       }
+       } 
 #ifdef HAVE_TTY
        assert(DEVICE_TTY_P(d));
        {
+               struct console *con = XCONSOLE(DEVICE_CONSOLE(d));
                int input_fd = CONSOLE_TTY_DATA(con)->infd;
 #if defined (HAVE_TERMIOS)
                struct termios sg;
@@ -871,20 +871,26 @@ static void init_sigio_on_device(struct device *d)
                int owner = getpid();
                int ioctl_status;
                if (DEVICE_TTY_P(d)) {
+#ifdef HAVE_UNIXOID_EVENT_LOOP
                        ioctl_status = ioctl(filedesc, FIOGSAIOOWN,
                                             &DEVICE_OLD_FCNTL_OWNER(d));
+#endif
                        ioctl_status = ioctl(filedesc, FIOSSAIOOWN, &owner);
                }
 #ifdef HAVE_WINDOW_SYSTEM
                else if (!DEVICE_STREAM_P(d)) {
+#ifdef HAVE_UNIXOID_EVENT_LOOP
                        ioctl_status = ioctl(filedesc, SIOCGPGRP,
                                             &DEVICE_OLD_FCNTL_OWNER(d));
+#endif
                        ioctl_status = ioctl(filedesc, SIOCSPGRP, &owner);
                }
 #endif
        }
 #elif defined (F_SETOWN) && !defined (F_SETOWN_BUG)
+#  ifdef HAVE_UNIXOID_EVENT_LOOP
        DEVICE_OLD_FCNTL_OWNER(d) = fcntl(filedesc, F_GETOWN, 0);
+#  endif
 # ifdef F_SETOWN_SOCK_NEG
        /* stdin is a socket here */
        fcntl(filedesc, F_SETOWN, -getpid());
@@ -902,18 +908,24 @@ static void reset_sigio_on_device(struct device *d)
        {                       /* HPUX stuff */
                int ioctl_status;
                if (DEVICE_TTY_P(d)) {
+#  ifdef HAVE_UNIXOID_EVENT_LOOP
                        ioctl_status = ioctl(filedesc, FIOSSAIOOWN,
                                             &DEVICE_OLD_FCNTL_OWNER(d));
+#  endif
                }
 #ifdef HAVE_WINDOW_SYSTEM
                else if (!DEVICE_STREAM_P(d)) {
+#  ifdef HAVE_UNIXOID_EVENT_LOOP
                        ioctl_status = ioctl(filedesc, SIOCSPGRP,
                                             &DEVICE_OLD_FCNTL_OWNER(d));
+#  endif
                }
 #endif
        }
 #elif defined (F_SETOWN) && !defined (F_SETOWN_BUG)
+#  ifdef HAVE_UNIXOID_EVENT_LOOP
        fcntl(filedesc, F_SETOWN, DEVICE_OLD_FCNTL_OWNER(d));
+#  endif
 #endif
 }
 
@@ -2102,6 +2114,7 @@ void init_system_name(void)
 #   endif
                        if (hp) {
                                const char *fqdn = (const char *)hp->h_name;
+                               size_t len = 0;
 
                                if (!strchr(fqdn, '.')) {
                                        /* We still don't have a fully qualified domain name.
@@ -2112,8 +2125,9 @@ void init_system_name(void)
                                        if (*alias)
                                                fqdn = *alias;
                                }
-                               hostname = (char *)alloca(strlen(fqdn) + 1);
-                               strcpy(hostname, fqdn);
+                               len = strlen(fqdn) + 1;
+                               hostname = (char *)alloca(len);
+                               xstrncpy(hostname, fqdn,len);
                        }
 #  else                                /* !(HAVE_GETADDRINFO && HAVE_GETNAMEINFO) */
                        struct addrinfo hints, *res;
@@ -2131,7 +2145,7 @@ void init_system_name(void)
                                ssize_t canon_len=strlen(res->ai_canonname)+1;
 
                                hostname = (char *)alloca(canon_len);
-                               strncpy(hostname, res->ai_canonname, canon_len);
+                               xstrncpy(hostname, res->ai_canonname, canon_len);
                                freeaddrinfo(res);
                        }
 #  endif                       /* !(HAVE_GETADDRINFO && HAVE_GETNAMEINFO) */
@@ -2298,6 +2312,18 @@ const char *strerror(int errnum)
    Jamie's home page (http://www.jwz.org/worse-is-better.html). */
 
 #ifdef ENCAPSULATE_OPEN
+
+int raw_open(const char *path, int oflag, ...)
+{
+       int mode;
+       va_list ap;
+
+       va_start(ap, oflag);
+       mode = va_arg(ap, int);
+       va_end(ap);
+       return open(path, oflag, mode);
+}
+
 int sys_open(const char *path, int oflag, ...)
 {
        int mode;
@@ -2955,6 +2981,10 @@ get_process_times(double *user_time, double *system_time, double *real_time)
 #endif
 #endif
 
+#if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
+# include "ent/ent-gmp.h"
+#endif /* MPZ && (GMP || MP) */
+
 /* Figure out how many bits the system's random number generator uses.
    `random' and `lrand48' are assumed to return 31 usable bits.
    BSD `rand' returns a 31 bit value but the low order bits are unusable;
@@ -3281,7 +3311,7 @@ struct direct *readdir(DIR * dirp)
 
                if (dp->od_ino != 0) {  /* not deleted entry */
                        dir_static.d_ino = dp->od_ino;
-                       strncpy(dir_static.d_name, dp->od_name, DIRSIZ);
+                       xstrncpy(dir_static.d_name, dp->od_name, DIRSIZ);
                        dir_static.d_name[DIRSIZ] = '\0';
                        dir_static.d_namlen = strlen(dir_static.d_name);
                        dir_static.d_reclen = sizeof(struct direct)