summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
Diffstat (limited to 'unix')
-rw-r--r--unix/tclUnixChan.c136
-rw-r--r--unix/tclUnixPipe.c141
2 files changed, 139 insertions, 138 deletions
diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c
index d8eaccc..323d9e2 100644
--- a/unix/tclUnixChan.c
+++ b/unix/tclUnixChan.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixChan.c,v 1.101 2009/06/15 16:24:45 rmax Exp $
+ * RCS: @(#) $Id: tclUnixChan.c,v 1.102 2009/11/09 13:47:23 dkf Exp $
*/
#include "tclInt.h" /* Internal definitions for Tcl. */
@@ -233,7 +233,6 @@ static Tcl_ChannelType ttyChannelType = {
NULL, /* truncate proc. */
};
#endif /* SUPPORTS_TTY */
-
/*
*----------------------------------------------------------------------
@@ -256,11 +255,10 @@ static Tcl_ChannelType ttyChannelType = {
static int
FileBlockModeProc(
ClientData instanceData, /* File state. */
- int mode) /* The mode to set. Can be one of
- * TCL_MODE_BLOCKING or
- * TCL_MODE_NONBLOCKING. */
+ int mode) /* The mode to set. Can be TCL_MODE_BLOCKING
+ * or TCL_MODE_NONBLOCKING. */
{
- FileState *fsPtr = (FileState *) instanceData;
+ FileState *fsPtr = instanceData;
if (TclUnixSetBlockingMode(fsPtr->fd, mode) < 0) {
return errno;
@@ -295,7 +293,7 @@ FileInputProc(
* buffer? */
int *errorCodePtr) /* Where to store error code. */
{
- FileState *fsPtr = (FileState *) instanceData;
+ FileState *fsPtr = instanceData;
int bytesRead; /* How many bytes were actually read from the
* input device? */
@@ -341,7 +339,7 @@ FileOutputProc(
int toWrite, /* How many bytes to write? */
int *errorCodePtr) /* Where to store error code. */
{
- FileState *fsPtr = (FileState *) instanceData;
+ FileState *fsPtr = instanceData;
int written;
*errorCodePtr = 0;
@@ -385,7 +383,7 @@ FileCloseProc(
ClientData instanceData, /* File state. */
Tcl_Interp *interp) /* For error reporting - unused. */
{
- FileState *fsPtr = (FileState *) instanceData;
+ FileState *fsPtr = instanceData;
int errorCode = 0;
Tcl_DeleteFileHandler(fsPtr->fd);
@@ -431,7 +429,7 @@ FileSeekProc(
* one of SEEK_START, SEEK_SET or SEEK_END. */
int *errorCodePtr) /* To store error code. */
{
- FileState *fsPtr = (FileState *) instanceData;
+ FileState *fsPtr = instanceData;
Tcl_WideInt oldLoc, newLoc;
/*
@@ -492,7 +490,7 @@ FileWideSeekProc(
* one of SEEK_START, SEEK_CUR or SEEK_END. */
int *errorCodePtr) /* To store error code. */
{
- FileState *fsPtr = (FileState *) instanceData;
+ FileState *fsPtr = instanceData;
Tcl_WideInt newLoc;
newLoc = TclOSseek(fsPtr->fd, (Tcl_SeekOffset) offset, mode);
@@ -525,7 +523,7 @@ FileWatchProc(
* TCL_READABLE, TCL_WRITABLE and
* TCL_EXCEPTION. */
{
- FileState *fsPtr = (FileState *) instanceData;
+ FileState *fsPtr = instanceData;
/*
* Make sure we only register for events that are valid on this file. Note
@@ -536,8 +534,7 @@ FileWatchProc(
mask &= fsPtr->validMask;
if (mask) {
Tcl_CreateFileHandler(fsPtr->fd, mask,
- (Tcl_FileProc *) Tcl_NotifyChannel,
- (ClientData) fsPtr->channel);
+ (Tcl_FileProc *) Tcl_NotifyChannel, fsPtr->channel);
} else {
Tcl_DeleteFileHandler(fsPtr->fd);
}
@@ -567,10 +564,10 @@ FileGetHandleProc(
int direction, /* TCL_READABLE or TCL_WRITABLE */
ClientData *handlePtr) /* Where to store the handle. */
{
- FileState *fsPtr = (FileState *) instanceData;
+ FileState *fsPtr = instanceData;
if (direction & fsPtr->validMask) {
- *handlePtr = (ClientData) INT2PTR(fsPtr->fd);
+ *handlePtr = INT2PTR(fsPtr->fd);
return TCL_OK;
}
return TCL_ERROR;
@@ -637,7 +634,7 @@ TtySetOptionProc(
const char *optionName, /* Which option to set? */
const char *value) /* New value for option. */
{
- FileState *fsPtr = (FileState *) instanceData;
+ FileState *fsPtr = instanceData;
unsigned int len, vlen;
TtyAttrs tty;
#ifdef USE_TERMIOS
@@ -652,6 +649,7 @@ TtySetOptionProc(
/*
* Option -mode baud,parity,databits,stopbits
*/
+
if ((len > 2) && (strncmp(optionName, "-mode", len) == 0)) {
if (TtyParseMode(interp, value, &tty.baud, &tty.parity, &tty.data,
&tty.stop) != TCL_OK) {
@@ -683,7 +681,9 @@ TtySetOptionProc(
CLEAR_BITS(iostate.c_cflag, CRTSCTS);
#endif /* CRTSCTS */
if (strncasecmp(value, "NONE", vlen) == 0) {
- /* leave all handshake options disabled */
+ /*
+ * Leave all handshake options disabled.
+ */
} else if (strncasecmp(value, "XONXOFF", vlen) == 0) {
SET_BITS(iostate.c_iflag, IXON | IXOFF | IXANY);
} else if (strncasecmp(value, "RTSCTS", vlen) == 0) {
@@ -713,22 +713,11 @@ TtySetOptionProc(
*/
if ((len > 1) && (strncmp(optionName, "-xchar", len) == 0)) {
- GETIOSTATE(fsPtr->fd, &iostate);
+ Tcl_DString ds;
+
if (Tcl_SplitList(interp, value, &argc, &argv) == TCL_ERROR) {
return TCL_ERROR;
- }
- if (argc == 2) {
- Tcl_DString ds;
- Tcl_DStringInit(&ds);
-
- Tcl_UtfToExternalDString(NULL, argv[0], -1, &ds);
- iostate.c_cc[VSTART] = *(const cc_t *) Tcl_DStringValue(&ds);
- Tcl_DStringSetLength(&ds, 0);
-
- Tcl_UtfToExternalDString(NULL, argv[1], -1, &ds);
- iostate.c_cc[VSTOP] = *(const cc_t *) Tcl_DStringValue(&ds);
- Tcl_DStringFree(&ds);
- } else {
+ } else if (argc != 2) {
if (interp) {
Tcl_AppendResult(interp, "bad value for -xchar: "
"should be a list of two elements", NULL);
@@ -736,8 +725,19 @@ TtySetOptionProc(
ckfree((char *) argv);
return TCL_ERROR;
}
- SETIOSTATE(fsPtr->fd, &iostate);
+
+ GETIOSTATE(fsPtr->fd, &iostate);
+
+ Tcl_UtfToExternalDString(NULL, argv[0], -1, &ds);
+ iostate.c_cc[VSTART] = *(const cc_t *) Tcl_DStringValue(&ds);
+ Tcl_DStringSetLength(&ds, 0);
+
+ Tcl_UtfToExternalDString(NULL, argv[1], -1, &ds);
+ iostate.c_cc[VSTOP] = *(const cc_t *) Tcl_DStringValue(&ds);
+ Tcl_DStringFree(&ds);
ckfree((char *) argv);
+
+ SETIOSTATE(fsPtr->fd, &iostate);
return TCL_OK;
}
@@ -868,7 +868,7 @@ TtyGetOptionProc(
const char *optionName, /* Option to get. */
Tcl_DString *dsPtr) /* Where to store value(s). */
{
- FileState *fsPtr = (FileState *) instanceData;
+ FileState *fsPtr = instanceData;
unsigned int len;
char buf[3*TCL_INTEGER_SPACE + 16];
int valid = 0; /* Flag if valid option parsed. */
@@ -902,17 +902,17 @@ TtyGetOptionProc(
if (len==0 || (len>1 && strncmp(optionName, "-xchar", len)==0)) {
IOSTATE iostate;
Tcl_DString ds;
- valid = 1;
+ valid = 1;
GETIOSTATE(fsPtr->fd, &iostate);
Tcl_DStringInit(&ds);
- Tcl_ExternalToUtfDString(NULL, (const char *) &iostate.c_cc[VSTART], 1, &ds);
- Tcl_DStringAppendElement(dsPtr, (const char *) Tcl_DStringValue(&ds));
+ Tcl_ExternalToUtfDString(NULL, (char *) &iostate.c_cc[VSTART], 1, &ds);
+ Tcl_DStringAppendElement(dsPtr, Tcl_DStringValue(&ds));
Tcl_DStringSetLength(&ds, 0);
- Tcl_ExternalToUtfDString(NULL, (const char *) &iostate.c_cc[VSTOP], 1, &ds);
- Tcl_DStringAppendElement(dsPtr, (const char *) Tcl_DStringValue(&ds));
+ Tcl_ExternalToUtfDString(NULL, (char *) &iostate.c_cc[VSTOP], 1, &ds);
+ Tcl_DStringAppendElement(dsPtr, Tcl_DStringValue(&ds));
Tcl_DStringFree(&ds);
}
if (len == 0) {
@@ -949,6 +949,7 @@ TtyGetOptionProc(
* Option is readonly and returned by [fconfigure chan -ttystatus] but not
* returned by unnamed [fconfigure chan].
*/
+
if ((len > 4) && (strncmp(optionName, "-ttystatus", len) == 0)) {
int status;
@@ -1186,7 +1187,7 @@ TtyGetAttributes(
case PARENB : parity = 'e'; break;
case PARENB | PARODD : parity = 'o'; break;
}
-#endif /* !PAREXT */
+#endif /* PAREXT */
data = iostate.c_cflag & CSIZE;
data = (data == CS5) ? 5 : (data == CS6) ? 6 : (data == CS7) ? 7 : 8;
@@ -1391,11 +1392,13 @@ TtyParseMode(
* sure to allow for the case where strchr is a macro. [Bug: 5089]
*/
+ if (strchr(
#if defined(PAREXT) || defined(USE_TERMIO)
- if (strchr("noems", parity) == NULL) {
+ "noems",
#else
- if (strchr("noe", parity) == NULL) {
+ "noe",
#endif /* PAREXT|USE_TERMIO */
+ parity) == NULL) {
if (interp != NULL) {
Tcl_AppendResult(interp, bad, " parity: should be ",
#if defined(PAREXT) || defined(USE_TERMIO)
@@ -1453,21 +1456,20 @@ TtyInit(
* initialized. */
int initialize)
{
- TtyState *ttyPtr;
+ TtyState *ttyPtr = (TtyState *) ckalloc((unsigned) sizeof(TtyState));
int stateUpdated = 0;
- ttyPtr = (TtyState *) ckalloc((unsigned) sizeof(TtyState));
GETIOSTATE(fd, &ttyPtr->savedState);
if (initialize) {
IOSTATE iostate = ttyPtr->savedState;
#if defined(USE_TERMIOS) || defined(USE_TERMIO)
- if (iostate.c_iflag != IGNBRK ||
- iostate.c_oflag != 0 ||
- iostate.c_lflag != 0 ||
- iostate.c_cflag & CREAD ||
- iostate.c_cc[VMIN] != 1 ||
- iostate.c_cc[VTIME] != 0) {
+ if (iostate.c_iflag != IGNBRK
+ || iostate.c_oflag != 0
+ || iostate.c_lflag != 0
+ || iostate.c_cflag & CREAD
+ || iostate.c_cc[VMIN] != 1
+ || iostate.c_cc[VTIME] != 0) {
stateUpdated = 1;
}
iostate.c_iflag = IGNBRK;
@@ -1479,8 +1481,8 @@ TtyInit(
#endif /* USE_TERMIOS|USE_TERMIO */
#ifdef USE_SGTTY
- if ((iostate.sg_flags & (EVENP | ODDP)) ||
- !(iostate.sg_flags & RAW)) {
+ if ((iostate.sg_flags & (EVENP | ODDP))
+ || !(iostate.sg_flags & RAW)) {
ttyPtr->stateUpdated = 1;
}
iostate.sg_flags &= EVENP | ODDP;
@@ -1675,9 +1677,8 @@ Tcl_MakeFileChannel(
sprintf(channelName, "serial%d", fd);
} else
#endif /* SUPPORTS_TTY */
- if (getsockname(fd, (struct sockaddr *)&sockaddr, &sockaddrLen) == 0
- && sockaddrLen > 0
- && sockaddr.sa_family == AF_INET) {
+ if ((getsockname(fd, &sockaddr, &sockaddrLen) == 0)
+ && (sockaddrLen > 0) && (sockaddr.sa_family == AF_INET)) {
return TclpMakeTcpClientChannelMode((ClientData) INT2PTR(fd), mode);
} else {
channelTypePtr = &fileChannelType;
@@ -1849,8 +1850,7 @@ Tcl_GetOpenFile(
|| (strcmp(chanTypePtr->typeName, "tcp") == 0)
|| (strcmp(chanTypePtr->typeName, "pipe") == 0)) {
if (Tcl_GetChannelHandle(chan,
- (forWriting ? TCL_WRITABLE : TCL_READABLE),
- (ClientData*) &data) == TCL_OK) {
+ (forWriting ? TCL_WRITABLE : TCL_READABLE), &data) == TCL_OK) {
fd = PTR2INT(data);
/*
@@ -1865,7 +1865,7 @@ Tcl_GetOpenFile(
"\"", NULL);
return TCL_ERROR;
}
- *filePtr = (ClientData) f;
+ *filePtr = f;
return TCL_OK;
}
}
@@ -1917,7 +1917,7 @@ TclUnixWaitForFile(
int numFound, result = 0;
fd_set readableMask;
fd_set writableMask;
- fd_set exceptionalMask;
+ fd_set exceptionMask;
#ifndef _DARWIN_C_SOURCE
/*
@@ -1958,7 +1958,7 @@ TclUnixWaitForFile(
FD_ZERO(&readableMask);
FD_ZERO(&writableMask);
- FD_ZERO(&exceptionalMask);
+ FD_ZERO(&exceptionMask);
/*
* Loop in a mini-event loop of our own, waiting for either the file to
@@ -1983,14 +1983,14 @@ TclUnixWaitForFile(
* Setup the select masks for the fd.
*/
- if (mask & TCL_READABLE) {
+ if (mask & TCL_READABLE) {
FD_SET(fd, &readableMask);
}
- if (mask & TCL_WRITABLE) {
+ if (mask & TCL_WRITABLE) {
FD_SET(fd, &writableMask);
}
if (mask & TCL_EXCEPTION) {
- FD_SET(fd, &exceptionalMask);
+ FD_SET(fd, &exceptionMask);
}
/*
@@ -1998,15 +1998,15 @@ TclUnixWaitForFile(
*/
numFound = select(fd + 1, &readableMask, &writableMask,
- &exceptionalMask, timeoutPtr);
+ &exceptionMask, timeoutPtr);
if (numFound == 1) {
- if (FD_ISSET(fd, &readableMask)) {
+ if (FD_ISSET(fd, &readableMask)) {
SET_BITS(result, TCL_READABLE);
}
- if (FD_ISSET(fd, &writableMask)) {
+ if (FD_ISSET(fd, &writableMask)) {
SET_BITS(result, TCL_WRITABLE);
}
- if (FD_ISSET(fd, &exceptionalMask)) {
+ if (FD_ISSET(fd, &exceptionMask)) {
SET_BITS(result, TCL_EXCEPTION);
}
result &= mask;
@@ -2059,7 +2059,7 @@ FileTruncateProc(
ClientData instanceData,
Tcl_WideInt length)
{
- FileState *fsPtr = (FileState *) instanceData;
+ FileState *fsPtr = instanceData;
int result;
#ifdef HAVE_TYPE_OFF64_T
diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c
index 0d92556..69250f8 100644
--- a/unix/tclUnixPipe.c
+++ b/unix/tclUnixPipe.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixPipe.c,v 1.48 2009/01/09 11:21:46 dkf Exp $
+ * RCS: @(#) $Id: tclUnixPipe.c,v 1.49 2009/11/09 13:47:23 dkf Exp $
*/
#include "tclInt.h"
@@ -25,8 +25,8 @@
* the same as NULL.
*/
-#define MakeFile(fd) ((TclFile)INT2PTR(((int)(fd))+1))
-#define GetFd(file) (PTR2INT(file)-1)
+#define MakeFile(fd) ((TclFile) INT2PTR(((int) (fd)) + 1))
+#define GetFd(file) (PTR2INT(file) - 1)
/*
* This structure describes per-instance state of a pipe based channel.
@@ -53,8 +53,6 @@ typedef struct PipeState {
static int PipeBlockModeProc(ClientData instanceData, int mode);
static int PipeClose2Proc(ClientData instanceData,
Tcl_Interp *interp, int flags);
-/* static int PipeCloseProc(ClientData instanceData,
- Tcl_Interp *interp); */
static int PipeGetHandleProc(ClientData instanceData,
int direction, ClientData *handlePtr);
static int PipeInputProc(ClientData instanceData, char *buf,
@@ -113,12 +111,11 @@ TclpMakeFile(
{
ClientData data;
- if (Tcl_GetChannelHandle(channel, direction,
- (ClientData *) &data) == TCL_OK) {
- return MakeFile(PTR2INT(data));
- } else {
- return (TclFile) NULL;
+ if (Tcl_GetChannelHandle(channel, direction, &data) != TCL_OK) {
+ return NULL;
}
+
+ return MakeFile(PTR2INT(data));
}
/*
@@ -423,9 +420,8 @@ TclpCreateProcess(
* deallocated later
*/
- dsArray = (Tcl_DString *)
- TclStackAlloc(interp, argc * sizeof(Tcl_DString));
- newArgv = (char **) TclStackAlloc(interp, (argc+1) * sizeof(char *));
+ dsArray = TclStackAlloc(interp, argc * sizeof(Tcl_DString));
+ newArgv = TclStackAlloc(interp, (argc+1) * sizeof(char *));
newArgv[argc] = NULL;
for (i = 0; i < argc; i++) {
newArgv[i] = Tcl_UtfToExternalDString(NULL, argv[i], -1, &dsArray[i]);
@@ -438,6 +434,7 @@ TclpCreateProcess(
* might corrupt the parent: so ensure standard channels are initialized in
* the parent, otherwise SetupStdFile() might initialize them in the child.
*/
+
if (!inputFile) {
Tcl_GetStdChannel(TCL_STDIN);
}
@@ -448,6 +445,7 @@ TclpCreateProcess(
Tcl_GetStdChannel(TCL_STDERR);
}
#endif
+
pid = fork();
if (pid == 0) {
int joinThisError = errorFile && (errorFile == outputFile);
@@ -465,7 +463,7 @@ TclpCreateProcess(
((dup2(1,2) == -1) || (fcntl(2, F_SETFD, 0) != 0)))) {
sprintf(errSpace,
"%dforked process couldn't set up input/output: ", errno);
- (void)write(fd, errSpace, (size_t) strlen(errSpace));
+ (void) write(fd, errSpace, (size_t) strlen(errSpace));
_exit(1);
}
@@ -476,7 +474,7 @@ TclpCreateProcess(
RestoreSignals();
execvp(newArgv[0], newArgv); /* INTL: Native. */
sprintf(errSpace, "%dcouldn't execute \"%.150s\": ", errno, argv[0]);
- (void)write(fd, errSpace, (size_t) strlen(errSpace));
+ (void) write(fd, errSpace, (size_t) strlen(errSpace));
_exit(1);
}
@@ -764,7 +762,7 @@ TclpCreateCommandChannel(
sprintf(channelName, "file%d", channelId);
statePtr->channel = Tcl_CreateChannel(&pipeChannelType, channelName,
- (ClientData) statePtr, mode);
+ statePtr, mode);
return statePtr->channel;
}
@@ -776,21 +774,21 @@ TclpCreateCommandChannel(
* System dependent interface to create a pipe for the [chan pipe]
* command. Stolen from TclX.
*
- * Parameters:
- * o interp - Errors returned in result.
- * o rchan, wchan - Returned read and write side.
- * o flags - Reserved for future use.
* Results:
- * TCL_OK or TCL_ERROR.
+ * TCL_OK or TCL_ERROR.
+ *
+ * Side effects:
+ * Registers two channels.
*
*----------------------------------------------------------------------
*/
+
int
Tcl_CreatePipe(
- Tcl_Interp *interp,
- Tcl_Channel *rchan,
- Tcl_Channel *wchan,
- int flags)
+ Tcl_Interp *interp, /* Errors returned in result. */
+ Tcl_Channel *rchan, /* Returned read side. */
+ Tcl_Channel *wchan, /* Returned write side. */
+ int flags) /* Reserved for future use. */
{
int fileNums[2];
@@ -803,16 +801,13 @@ Tcl_CreatePipe(
fcntl(fileNums[0], F_SETFD, FD_CLOEXEC);
fcntl(fileNums[1], F_SETFD, FD_CLOEXEC);
- *rchan = Tcl_MakeFileChannel((ClientData) INT2PTR(fileNums[0]),
- TCL_READABLE);
+ *rchan = Tcl_MakeFileChannel(INT2PTR(fileNums[0]), TCL_READABLE);
Tcl_RegisterChannel(interp, *rchan);
- *wchan = Tcl_MakeFileChannel((ClientData) INT2PTR(fileNums[1]),
- TCL_WRITABLE);
+ *wchan = Tcl_MakeFileChannel(INT2PTR(fileNums[1]), TCL_WRITABLE);
Tcl_RegisterChannel(interp, *wchan);
return TCL_OK;
}
-
/*
*----------------------------------------------------------------------
@@ -891,15 +886,13 @@ PipeBlockModeProc(
{
PipeState *psPtr = instanceData;
- if (psPtr->inFile) {
- if (TclUnixSetBlockingMode(GetFd(psPtr->inFile), mode) < 0) {
- return errno;
- }
+ if (psPtr->inFile
+ && TclUnixSetBlockingMode(GetFd(psPtr->inFile), mode) < 0) {
+ return errno;
}
- if (psPtr->outFile) {
- if (TclUnixSetBlockingMode(GetFd(psPtr->outFile), mode) < 0) {
- return errno;
- }
+ if (psPtr->outFile
+ && TclUnixSetBlockingMode(GetFd(psPtr->outFile), mode) < 0) {
+ return errno;
}
psPtr->isNonBlocking = (mode == TCL_MODE_NONBLOCKING);
@@ -930,31 +923,35 @@ PipeClose2Proc(
Tcl_Interp *interp, /* For error reporting. */
int flags) /* Flags that indicate which side to close. */
{
- PipeState *pipePtr= (PipeState *) instanceData;
+ PipeState *pipePtr = instanceData;
Tcl_Channel errChan;
int errorCode, result;
errorCode = 0;
result = 0;
- if (((!flags)||(flags & TCL_CLOSE_READ)) && (pipePtr->inFile != NULL)) {
+ if (((!flags) || (flags & TCL_CLOSE_READ)) && (pipePtr->inFile != NULL)) {
if (TclpCloseFile(pipePtr->inFile) < 0) {
errorCode = errno;
} else {
- pipePtr->inFile=NULL;
+ pipePtr->inFile = NULL;
}
}
- if (((!flags)||(flags & TCL_CLOSE_WRITE)) && (pipePtr->outFile != NULL) && (errorCode == 0)) {
+ if (((!flags) || (flags & TCL_CLOSE_WRITE)) && (pipePtr->outFile != NULL)
+ && (errorCode == 0)) {
if (TclpCloseFile(pipePtr->outFile) < 0) {
errorCode = errno;
} else {
- pipePtr->outFile=NULL;
+ pipePtr->outFile = NULL;
}
}
- /* if half-closing, stop here. */
+ /*
+ * If half-closing, stop here.
+ */
+
if (flags) {
- return errorCode;
+ return errorCode;
}
if (pipePtr->isNonBlocking || TclInExit()) {
@@ -978,7 +975,8 @@ PipeClose2Proc(
if (pipePtr->errorFile) {
errChan = Tcl_MakeFileChannel(
- (ClientData) INT2PTR(GetFd(pipePtr->errorFile)), TCL_READABLE);
+ INT2PTR(GetFd(pipePtr->errorFile)),
+ TCL_READABLE);
} else {
errChan = NULL;
}
@@ -1022,7 +1020,7 @@ PipeInputProc(
* buffer? */
int *errorCodePtr) /* Where to store error code. */
{
- PipeState *psPtr = (PipeState *) instanceData;
+ PipeState *psPtr = instanceData;
int bytesRead; /* How many bytes were actually read from the
* input device? */
@@ -1043,9 +1041,8 @@ PipeInputProc(
if (bytesRead < 0) {
*errorCodePtr = errno;
return -1;
- } else {
- return bytesRead;
}
+ return bytesRead;
}
/*
@@ -1073,7 +1070,7 @@ PipeOutputProc(
int toWrite, /* How many bytes to write? */
int *errorCodePtr) /* Where to store error code. */
{
- PipeState *psPtr = (PipeState *) instanceData;
+ PipeState *psPtr = instanceData;
int written;
*errorCodePtr = 0;
@@ -1090,9 +1087,8 @@ PipeOutputProc(
if (written < 0) {
*errorCodePtr = errno;
return -1;
- } else {
- return written;
}
+ return written;
}
/*
@@ -1119,15 +1115,14 @@ PipeWatchProc(
* TCL_READABLE, TCL_WRITABLE and
* TCL_EXCEPTION. */
{
- PipeState *psPtr = (PipeState *) instanceData;
+ PipeState *psPtr = instanceData;
int newmask;
if (psPtr->inFile) {
newmask = mask & (TCL_READABLE | TCL_EXCEPTION);
if (newmask) {
Tcl_CreateFileHandler(GetFd(psPtr->inFile), mask,
- (Tcl_FileProc *) Tcl_NotifyChannel,
- (ClientData) psPtr->channel);
+ (Tcl_FileProc *) Tcl_NotifyChannel, psPtr->channel);
} else {
Tcl_DeleteFileHandler(GetFd(psPtr->inFile));
}
@@ -1136,8 +1131,7 @@ PipeWatchProc(
newmask = mask & (TCL_WRITABLE | TCL_EXCEPTION);
if (newmask) {
Tcl_CreateFileHandler(GetFd(psPtr->outFile), mask,
- (Tcl_FileProc *) Tcl_NotifyChannel,
- (ClientData) psPtr->channel);
+ (Tcl_FileProc *) Tcl_NotifyChannel, psPtr->channel);
} else {
Tcl_DeleteFileHandler(GetFd(psPtr->outFile));
}
@@ -1168,14 +1162,14 @@ PipeGetHandleProc(
int direction, /* TCL_READABLE or TCL_WRITABLE */
ClientData *handlePtr) /* Where to store the handle. */
{
- PipeState *psPtr = (PipeState *) instanceData;
+ PipeState *psPtr = instanceData;
if (direction == TCL_READABLE && psPtr->inFile) {
- *handlePtr = (ClientData) INT2PTR(GetFd(psPtr->inFile));
+ *handlePtr = INT2PTR(GetFd(psPtr->inFile));
return TCL_OK;
}
if (direction == TCL_WRITABLE && psPtr->outFile) {
- *handlePtr = (ClientData) INT2PTR(GetFd(psPtr->outFile));
+ *handlePtr = INT2PTR(GetFd(psPtr->outFile));
return TCL_OK;
}
return TCL_ERROR;
@@ -1204,9 +1198,8 @@ Tcl_WaitPid(
int options)
{
int result;
- pid_t real_pid;
+ pid_t real_pid = (pid_t) PTR2INT(pid);
- real_pid = (pid_t) PTR2INT(pid);
while (1) {
result = (int) waitpid(real_pid, statPtr, options);
if ((result != -1) || (errno != EINTR)) {
@@ -1240,27 +1233,35 @@ Tcl_PidObjCmd(
int objc, /* Number of arguments. */
Tcl_Obj *const *objv) /* Argument strings. */
{
+ Tcl_Channel chan;
+ PipeState *pipePtr;
+ int i;
+ Tcl_Obj *resultPtr, *longObjPtr;
+
if (objc > 2) {
Tcl_WrongNumArgs(interp, 1, objv, "?channelId?");
return TCL_ERROR;
}
+
if (objc == 1) {
Tcl_SetObjResult(interp, Tcl_NewLongObj((long) getpid()));
} else {
- Tcl_Channel chan;
- const Tcl_ChannelType *chanTypePtr;
- PipeState *pipePtr;
- int i;
- Tcl_Obj *resultPtr, *longObjPtr;
+ /*
+ * Get the channel and make sure that it refers to a pipe.
+ */
chan = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), NULL);
- if (chan == (Tcl_Channel) NULL) {
+ if (chan == NULL) {
return TCL_ERROR;
}
- chanTypePtr = Tcl_GetChannelType(chan);
- if (chanTypePtr != &pipeChannelType) {
+ if (Tcl_GetChannelType(chan) != &pipeChannelType) {
return TCL_OK;
}
+
+ /*
+ * Extract the process IDs from the pipe structure.
+ */
+
pipePtr = (PipeState *) Tcl_GetChannelInstanceData(chan);
resultPtr = Tcl_NewObj();
for (i = 0; i < pipePtr->numPids; i++) {