X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=childio.c;h=da1a45281ddf535e0ae5bcce93ec44dbe27231bf;hb=1c03d229073e56dda9e5856db5adaae51576a3bb;hp=fd3b1e187f4711df4b2b9be7a538e5e7a6a9d974;hpb=0db7cb3a6d76078255f3d19cb8364ce3dc536458;p=xboard.git diff --git a/childio.c b/childio.c index fd3b1e1..da1a452 100644 --- a/childio.c +++ b/childio.c @@ -1,11 +1,11 @@ /* - * childio.c -- set up communication with child processes + * childio.c -- set up communication with child processes * * Copyright 1991 by Digital Equipment Corporation, Maynard, - * Massachusetts. + * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009 Free Software Foundation, Inc. + * 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. * * The following terms apply to Digital Equipment Corporation's copyright * interest in XBoard: @@ -59,6 +59,7 @@ #include "config.h" +#include #include #if HAVE_UNISTD_H # include @@ -66,12 +67,13 @@ #include "common.h" #include "frontend.h" +#include "backend.h" /* for safeStrCpy */ #if !USE_PTYS /* This code is for systems where pipes work properly */ -void SetUpChildIO(to_prog, from_prog) - int to_prog[2], from_prog[2]; +void +SetUpChildIO (int to_prog[2], int from_prog[2]) { signal(SIGPIPE, SIG_IGN); pipe(to_prog); @@ -97,8 +99,8 @@ void SetUpChildIO(to_prog, from_prog) int PseudoTTY P((char pty_name[])); -int SetUpChildIO(to_prog, from_prog) - int to_prog[2], from_prog[2]; +int +SetUpChildIO (int to_prog[2], int from_prog[2]) { char pty_name[MSG_SIZ]; @@ -125,19 +127,19 @@ int SetUpChildIO(to_prog, from_prog) #if HAVE_GRANTPT /* This code is for SVR4 */ -int PseudoTTY(pty_name) - char pty_name[]; +int +PseudoTTY (char pty_name[]) { extern char *ptsname(); char *ptss; int fd; - + fd = open("/dev/ptmx", O_RDWR); if (fd < 0) return fd; if (grantpt(fd) == -1) return -1; if (unlockpt(fd) == -1) return -1; if (!(ptss = ptsname(fd))) return -1; - strcpy(pty_name, ptss); + safeStrCpy(pty_name, ptss, sizeof(pty_name)/sizeof(pty_name[0])); return fd; } @@ -145,15 +147,15 @@ int PseudoTTY(pty_name) #if HAVE__GETPTY /* This code is for IRIX */ -int PseudoTTY(pty_name) - char pty_name[]; +int +PseudoTTY (char pty_name[]) { int fd; char *ptyn; ptyn = _getpty(&fd, O_RDWR, 0600, 0); if (ptyn == NULL) return -1; - strcpy(pty_name, ptyn); + safeStrCpy(pty_name, ptyn, sizeof(pty_name)/sizeof(pty_name[0])); return fd; } @@ -161,15 +163,15 @@ int PseudoTTY(pty_name) #if HAVE_LIBSEQ /* This code is for Sequent DYNIX/ptx. Untested. --tpm */ -int PseudoTTY(pty_name) - char pty_name[]; +int +PseudoTTY (char pty_name[]) { int fd; char *slave, *master; fd = getpseudotty(&slave, &master); if (fd < 0) return fd; - strcpy(pty_name, slave); + safeStrCpy(pty_name, slave, sizeof(pty_name)/sizeof(pty_name[0])); return fd; } @@ -184,8 +186,8 @@ int PseudoTTY(pty_name) #define LAST_PTY_LETTER 'z' #endif -int PseudoTTY(pty_name) - char pty_name[]; +int +PseudoTTY (char pty_name[]) { struct stat stb; register c, i; @@ -208,7 +210,7 @@ int PseudoTTY(pty_name) #ifdef PTY_NAME_SPRINTF PTY_NAME_SPRINTF #else - sprintf (pty_name, "/dev/pty%c%x", c, i); + sprintf (pty_name, "/dev/pty%c%x", c, i); #endif /* no PTY_NAME_SPRINTF */ #ifdef PTY_OPEN @@ -232,7 +234,7 @@ int PseudoTTY(pty_name) #ifdef PTY_TTY_NAME_SPRINTF PTY_TTY_NAME_SPRINTF #else - sprintf (pty_name, "/dev/tty%c%x", c, i); + sprintf (pty_name, "/dev/tty%c%x", c, i); #endif /* no PTY_TTY_NAME_SPRINTF */ #ifndef UNIPLUS if (access (pty_name, 6) != 0)