| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "tclInt.h" |
| 16 |
#include "tclPort.h" |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include <signal.h> |
| 24 |
#include <sys/resource.h> |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#define MakeFile(fd) ((TclFile)((fd)+1)) |
| 33 |
#define GetFd(file) (((int)file)-1) |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
typedef struct Pipe { |
| 41 |
TclFile readFile; |
| 42 |
|
| 43 |
TclFile writeFile; |
| 44 |
|
| 45 |
int readCount; |
| 46 |
|
| 47 |
|
| 48 |
int writeCount; |
| 49 |
|
| 50 |
|
| 51 |
} Pipe; |
| 52 |
|
| 53 |
#define MAX_PIPES 10 |
| 54 |
static Pipe testPipes[MAX_PIPES]; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
static char *gotsig = "0"; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
static void TestFileHandlerProc _ANSI_ARGS_((ClientData clientData, |
| 67 |
int mask)); |
| 68 |
static int TestfilehandlerCmd _ANSI_ARGS_((ClientData dummy, |
| 69 |
Tcl_Interp *interp, int argc, CONST char **argv)); |
| 70 |
static int TestfilewaitCmd _ANSI_ARGS_((ClientData dummy, |
| 71 |
Tcl_Interp *interp, int argc, CONST char **argv)); |
| 72 |
static int TestfindexecutableCmd _ANSI_ARGS_((ClientData dummy, |
| 73 |
Tcl_Interp *interp, int argc, CONST char **argv)); |
| 74 |
static int TestgetopenfileCmd _ANSI_ARGS_((ClientData dummy, |
| 75 |
Tcl_Interp *interp, int argc, CONST char **argv)); |
| 76 |
static int TestgetdefencdirCmd _ANSI_ARGS_((ClientData dummy, |
| 77 |
Tcl_Interp *interp, int argc, CONST char **argv)); |
| 78 |
static int TestsetdefencdirCmd _ANSI_ARGS_((ClientData dummy, |
| 79 |
Tcl_Interp *interp, int argc, CONST char **argv)); |
| 80 |
int TclplatformtestInit _ANSI_ARGS_((Tcl_Interp *interp)); |
| 81 |
static int TestalarmCmd _ANSI_ARGS_((ClientData dummy, |
| 82 |
Tcl_Interp *interp, int argc, CONST char **argv)); |
| 83 |
static int TestgotsigCmd _ANSI_ARGS_((ClientData dummy, |
| 84 |
Tcl_Interp *interp, int argc, CONST char **argv)); |
| 85 |
static void AlarmHandler _ANSI_ARGS_(()); |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
int |
| 105 |
TclplatformtestInit(interp) |
| 106 |
Tcl_Interp *interp; |
| 107 |
{ |
| 108 |
Tcl_CreateCommand(interp, "testfilehandler", TestfilehandlerCmd, |
| 109 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
| 110 |
Tcl_CreateCommand(interp, "testfilewait", TestfilewaitCmd, |
| 111 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
| 112 |
Tcl_CreateCommand(interp, "testfindexecutable", TestfindexecutableCmd, |
| 113 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
| 114 |
Tcl_CreateCommand(interp, "testgetopenfile", TestgetopenfileCmd, |
| 115 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
| 116 |
Tcl_CreateCommand(interp, "testgetdefenc", TestgetdefencdirCmd, |
| 117 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
| 118 |
Tcl_CreateCommand(interp, "testsetdefenc", TestsetdefencdirCmd, |
| 119 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
| 120 |
Tcl_CreateCommand(interp, "testalarm", TestalarmCmd, |
| 121 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
| 122 |
Tcl_CreateCommand(interp, "testgotsig", TestgotsigCmd, |
| 123 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL); |
| 124 |
return TCL_OK; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
static int |
| 146 |
TestfilehandlerCmd(clientData, interp, argc, argv) |
| 147 |
ClientData clientData; |
| 148 |
Tcl_Interp *interp; |
| 149 |
int argc; |
| 150 |
CONST char **argv; |
| 151 |
{ |
| 152 |
Pipe *pipePtr; |
| 153 |
int i, mask, timeout; |
| 154 |
static int initialized = 0; |
| 155 |
char buffer[4000]; |
| 156 |
TclFile file; |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
if (!initialized) { |
| 164 |
for (i = 0; i < MAX_PIPES; i++) { |
| 165 |
testPipes[i].readFile = NULL; |
| 166 |
} |
| 167 |
initialized = 1; |
| 168 |
} |
| 169 |
|
| 170 |
if (argc < 2) { |
| 171 |
Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0], |
| 172 |
" option ... \"", (char *) NULL); |
| 173 |
return TCL_ERROR; |
| 174 |
} |
| 175 |
pipePtr = NULL; |
| 176 |
if (argc >= 3) { |
| 177 |
if (Tcl_GetInt(interp, argv[2], &i) != TCL_OK) { |
| 178 |
return TCL_ERROR; |
| 179 |
} |
| 180 |
if (i >= MAX_PIPES) { |
| 181 |
Tcl_AppendResult(interp, "bad index ", argv[2], (char *) NULL); |
| 182 |
return TCL_ERROR; |
| 183 |
} |
| 184 |
pipePtr = &testPipes[i]; |
| 185 |
} |
| 186 |
|
| 187 |
if (strcmp(argv[1], "close") == 0) { |
| 188 |
for (i = 0; i < MAX_PIPES; i++) { |
| 189 |
if (testPipes[i].readFile != NULL) { |
| 190 |
TclpCloseFile(testPipes[i].readFile); |
| 191 |
testPipes[i].readFile = NULL; |
| 192 |
TclpCloseFile(testPipes[i].writeFile); |
| 193 |
testPipes[i].writeFile = NULL; |
| 194 |
} |
| 195 |
} |
| 196 |
} else if (strcmp(argv[1], "clear") == 0) { |
| 197 |
if (argc != 3) { |
| 198 |
Tcl_AppendResult(interp, "wrong # arguments: should be \"", |
| 199 |
argv[0], " clear index\"", (char *) NULL); |
| 200 |
return TCL_ERROR; |
| 201 |
} |
| 202 |
pipePtr->readCount = pipePtr->writeCount = 0; |
| 203 |
} else if (strcmp(argv[1], "counts") == 0) { |
| 204 |
char buf[TCL_INTEGER_SPACE * 2]; |
| 205 |
|
| 206 |
if (argc != 3) { |
| 207 |
Tcl_AppendResult(interp, "wrong # arguments: should be \"", |
| 208 |
argv[0], " counts index\"", (char *) NULL); |
| 209 |
return TCL_ERROR; |
| 210 |
} |
| 211 |
sprintf(buf, "%d %d", pipePtr->readCount, pipePtr->writeCount); |
| 212 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 213 |
} else if (strcmp(argv[1], "create") == 0) { |
| 214 |
if (argc != 5) { |
| 215 |
Tcl_AppendResult(interp, "wrong # arguments: should be \"", |
| 216 |
argv[0], " create index readMode writeMode\"", |
| 217 |
(char *) NULL); |
| 218 |
return TCL_ERROR; |
| 219 |
} |
| 220 |
if (pipePtr->readFile == NULL) { |
| 221 |
if (!TclpCreatePipe(&pipePtr->readFile, &pipePtr->writeFile)) { |
| 222 |
Tcl_AppendResult(interp, "couldn't open pipe: ", |
| 223 |
Tcl_PosixError(interp), (char *) NULL); |
| 224 |
return TCL_ERROR; |
| 225 |
} |
| 226 |
#ifdef O_NONBLOCK |
| 227 |
fcntl(GetFd(pipePtr->readFile), F_SETFL, O_NONBLOCK); |
| 228 |
fcntl(GetFd(pipePtr->writeFile), F_SETFL, O_NONBLOCK); |
| 229 |
#else |
| 230 |
Tcl_SetResult(interp, "can't make pipes non-blocking", |
| 231 |
TCL_STATIC); |
| 232 |
return TCL_ERROR; |
| 233 |
#endif |
| 234 |
} |
| 235 |
pipePtr->readCount = 0; |
| 236 |
pipePtr->writeCount = 0; |
| 237 |
|
| 238 |
if (strcmp(argv[3], "readable") == 0) { |
| 239 |
Tcl_CreateFileHandler(GetFd(pipePtr->readFile), TCL_READABLE, |
| 240 |
TestFileHandlerProc, (ClientData) pipePtr); |
| 241 |
} else if (strcmp(argv[3], "off") == 0) { |
| 242 |
Tcl_DeleteFileHandler(GetFd(pipePtr->readFile)); |
| 243 |
} else if (strcmp(argv[3], "disabled") == 0) { |
| 244 |
Tcl_CreateFileHandler(GetFd(pipePtr->readFile), 0, |
| 245 |
TestFileHandlerProc, (ClientData) pipePtr); |
| 246 |
} else { |
| 247 |
Tcl_AppendResult(interp, "bad read mode \"", argv[3], "\"", |
| 248 |
(char *) NULL); |
| 249 |
return TCL_ERROR; |
| 250 |
} |
| 251 |
if (strcmp(argv[4], "writable") == 0) { |
| 252 |
Tcl_CreateFileHandler(GetFd(pipePtr->writeFile), TCL_WRITABLE, |
| 253 |
TestFileHandlerProc, (ClientData) pipePtr); |
| 254 |
} else if (strcmp(argv[4], "off") == 0) { |
| 255 |
Tcl_DeleteFileHandler(GetFd(pipePtr->writeFile)); |
| 256 |
} else if (strcmp(argv[4], "disabled") == 0) { |
| 257 |
Tcl_CreateFileHandler(GetFd(pipePtr->writeFile), 0, |
| 258 |
TestFileHandlerProc, (ClientData) pipePtr); |
| 259 |
} else { |
| 260 |
Tcl_AppendResult(interp, "bad read mode \"", argv[4], "\"", |
| 261 |
(char *) NULL); |
| 262 |
return TCL_ERROR; |
| 263 |
} |
| 264 |
} else if (strcmp(argv[1], "empty") == 0) { |
| 265 |
if (argc != 3) { |
| 266 |
Tcl_AppendResult(interp, "wrong # arguments: should be \"", |
| 267 |
argv[0], " empty index\"", (char *) NULL); |
| 268 |
return TCL_ERROR; |
| 269 |
} |
| 270 |
|
| 271 |
while (read(GetFd(pipePtr->readFile), buffer, 4000) > 0) { |
| 272 |
|
| 273 |
} |
| 274 |
} else if (strcmp(argv[1], "fill") == 0) { |
| 275 |
if (argc != 3) { |
| 276 |
Tcl_AppendResult(interp, "wrong # arguments: should be \"", |
| 277 |
argv[0], " fill index\"", (char *) NULL); |
| 278 |
return TCL_ERROR; |
| 279 |
} |
| 280 |
|
| 281 |
memset((VOID *) buffer, 'a', 4000); |
| 282 |
while (write(GetFd(pipePtr->writeFile), buffer, 4000) > 0) { |
| 283 |
|
| 284 |
} |
| 285 |
} else if (strcmp(argv[1], "fillpartial") == 0) { |
| 286 |
char buf[TCL_INTEGER_SPACE]; |
| 287 |
|
| 288 |
if (argc != 3) { |
| 289 |
Tcl_AppendResult(interp, "wrong # arguments: should be \"", |
| 290 |
argv[0], " fillpartial index\"", (char *) NULL); |
| 291 |
return TCL_ERROR; |
| 292 |
} |
| 293 |
|
| 294 |
memset((VOID *) buffer, 'b', 10); |
| 295 |
TclFormatInt(buf, write(GetFd(pipePtr->writeFile), buffer, 10)); |
| 296 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 297 |
} else if (strcmp(argv[1], "oneevent") == 0) { |
| 298 |
Tcl_DoOneEvent(TCL_FILE_EVENTS|TCL_DONT_WAIT); |
| 299 |
} else if (strcmp(argv[1], "wait") == 0) { |
| 300 |
if (argc != 5) { |
| 301 |
Tcl_AppendResult(interp, "wrong # arguments: should be \"", |
| 302 |
argv[0], " wait index readable|writable timeout\"", |
| 303 |
(char *) NULL); |
| 304 |
return TCL_ERROR; |
| 305 |
} |
| 306 |
if (pipePtr->readFile == NULL) { |
| 307 |
Tcl_AppendResult(interp, "pipe ", argv[2], " doesn't exist", |
| 308 |
(char *) NULL); |
| 309 |
return TCL_ERROR; |
| 310 |
} |
| 311 |
if (strcmp(argv[3], "readable") == 0) { |
| 312 |
mask = TCL_READABLE; |
| 313 |
file = pipePtr->readFile; |
| 314 |
} else { |
| 315 |
mask = TCL_WRITABLE; |
| 316 |
file = pipePtr->writeFile; |
| 317 |
} |
| 318 |
if (Tcl_GetInt(interp, argv[4], &timeout) != TCL_OK) { |
| 319 |
return TCL_ERROR; |
| 320 |
} |
| 321 |
i = TclUnixWaitForFile(GetFd(file), mask, timeout); |
| 322 |
if (i & TCL_READABLE) { |
| 323 |
Tcl_AppendElement(interp, "readable"); |
| 324 |
} |
| 325 |
if (i & TCL_WRITABLE) { |
| 326 |
Tcl_AppendElement(interp, "writable"); |
| 327 |
} |
| 328 |
} else if (strcmp(argv[1], "windowevent") == 0) { |
| 329 |
Tcl_DoOneEvent(TCL_WINDOW_EVENTS|TCL_DONT_WAIT); |
| 330 |
} else { |
| 331 |
Tcl_AppendResult(interp, "bad option \"", argv[1], |
| 332 |
"\": must be close, clear, counts, create, empty, fill, ", |
| 333 |
"fillpartial, oneevent, wait, or windowevent", |
| 334 |
(char *) NULL); |
| 335 |
return TCL_ERROR; |
| 336 |
} |
| 337 |
return TCL_OK; |
| 338 |
} |
| 339 |
|
| 340 |
static void TestFileHandlerProc(clientData, mask) |
| 341 |
ClientData clientData; |
| 342 |
int mask; |
| 343 |
|
| 344 |
{ |
| 345 |
Pipe *pipePtr = (Pipe *) clientData; |
| 346 |
|
| 347 |
if (mask & TCL_READABLE) { |
| 348 |
pipePtr->readCount++; |
| 349 |
} |
| 350 |
if (mask & TCL_WRITABLE) { |
| 351 |
pipePtr->writeCount++; |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
static int |
| 373 |
TestfilewaitCmd(clientData, interp, argc, argv) |
| 374 |
ClientData clientData; |
| 375 |
Tcl_Interp *interp; |
| 376 |
int argc; |
| 377 |
CONST char **argv; |
| 378 |
{ |
| 379 |
int mask, result, timeout; |
| 380 |
Tcl_Channel channel; |
| 381 |
int fd; |
| 382 |
ClientData data; |
| 383 |
|
| 384 |
if (argc != 4) { |
| 385 |
Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0], |
| 386 |
" file readable|writable|both timeout\"", (char *) NULL); |
| 387 |
return TCL_ERROR; |
| 388 |
} |
| 389 |
channel = Tcl_GetChannel(interp, argv[1], NULL); |
| 390 |
if (channel == NULL) { |
| 391 |
return TCL_ERROR; |
| 392 |
} |
| 393 |
if (strcmp(argv[2], "readable") == 0) { |
| 394 |
mask = TCL_READABLE; |
| 395 |
} else if (strcmp(argv[2], "writable") == 0){ |
| 396 |
mask = TCL_WRITABLE; |
| 397 |
} else if (strcmp(argv[2], "both") == 0){ |
| 398 |
mask = TCL_WRITABLE|TCL_READABLE; |
| 399 |
} else { |
| 400 |
Tcl_AppendResult(interp, "bad argument \"", argv[2], |
| 401 |
"\": must be readable, writable, or both", (char *) NULL); |
| 402 |
return TCL_ERROR; |
| 403 |
} |
| 404 |
if (Tcl_GetChannelHandle(channel, |
| 405 |
(mask & TCL_READABLE) ? TCL_READABLE : TCL_WRITABLE, |
| 406 |
(ClientData*) &data) != TCL_OK) { |
| 407 |
Tcl_SetResult(interp, "couldn't get channel file", TCL_STATIC); |
| 408 |
return TCL_ERROR; |
| 409 |
} |
| 410 |
fd = (int) data; |
| 411 |
if (Tcl_GetInt(interp, argv[3], &timeout) != TCL_OK) { |
| 412 |
return TCL_ERROR; |
| 413 |
} |
| 414 |
result = TclUnixWaitForFile(fd, mask, timeout); |
| 415 |
if (result & TCL_READABLE) { |
| 416 |
Tcl_AppendElement(interp, "readable"); |
| 417 |
} |
| 418 |
if (result & TCL_WRITABLE) { |
| 419 |
Tcl_AppendElement(interp, "writable"); |
| 420 |
} |
| 421 |
return TCL_OK; |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
static int |
| 442 |
TestfindexecutableCmd(clientData, interp, argc, argv) |
| 443 |
ClientData clientData; |
| 444 |
Tcl_Interp *interp; |
| 445 |
int argc; |
| 446 |
CONST char **argv; |
| 447 |
{ |
| 448 |
char *oldName; |
| 449 |
char *oldNativeName; |
| 450 |
|
| 451 |
if (argc != 2) { |
| 452 |
Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0], |
| 453 |
" argv0\"", (char *) NULL); |
| 454 |
return TCL_ERROR; |
| 455 |
} |
| 456 |
|
| 457 |
oldName = tclExecutableName; |
| 458 |
oldNativeName = tclNativeExecutableName; |
| 459 |
|
| 460 |
tclExecutableName = NULL; |
| 461 |
tclNativeExecutableName = NULL; |
| 462 |
|
| 463 |
Tcl_FindExecutable(argv[1]); |
| 464 |
if (tclExecutableName != NULL) { |
| 465 |
Tcl_SetResult(interp, tclExecutableName, TCL_VOLATILE); |
| 466 |
ckfree(tclExecutableName); |
| 467 |
} |
| 468 |
if (tclNativeExecutableName != NULL) { |
| 469 |
ckfree(tclNativeExecutableName); |
| 470 |
} |
| 471 |
|
| 472 |
tclExecutableName = oldName; |
| 473 |
tclNativeExecutableName = oldNativeName; |
| 474 |
|
| 475 |
return TCL_OK; |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
static int |
| 496 |
TestgetopenfileCmd(clientData, interp, argc, argv) |
| 497 |
ClientData clientData; |
| 498 |
Tcl_Interp *interp; |
| 499 |
int argc; |
| 500 |
CONST char **argv; |
| 501 |
{ |
| 502 |
ClientData filePtr; |
| 503 |
|
| 504 |
if (argc != 3) { |
| 505 |
Tcl_AppendResult(interp, |
| 506 |
"wrong # args: should be \"", argv[0], |
| 507 |
" channelName forWriting\"", |
| 508 |
(char *) NULL); |
| 509 |
return TCL_ERROR; |
| 510 |
} |
| 511 |
if (Tcl_GetOpenFile(interp, argv[1], atoi(argv[2]), 1, &filePtr) |
| 512 |
== TCL_ERROR) { |
| 513 |
return TCL_ERROR; |
| 514 |
} |
| 515 |
if (filePtr == (ClientData) NULL) { |
| 516 |
Tcl_AppendResult(interp, |
| 517 |
"Tcl_GetOpenFile succeeded but FILE * NULL!", (char *) NULL); |
| 518 |
return TCL_ERROR; |
| 519 |
} |
| 520 |
return TCL_OK; |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
static int |
| 541 |
TestsetdefencdirCmd(clientData, interp, argc, argv) |
| 542 |
ClientData clientData; |
| 543 |
Tcl_Interp *interp; |
| 544 |
int argc; |
| 545 |
CONST char **argv; |
| 546 |
{ |
| 547 |
if (argc != 2) { |
| 548 |
Tcl_AppendResult(interp, |
| 549 |
"wrong # args: should be \"", argv[0], |
| 550 |
" defaultDir\"", |
| 551 |
(char *) NULL); |
| 552 |
return TCL_ERROR; |
| 553 |
} |
| 554 |
|
| 555 |
if (tclDefaultEncodingDir != NULL) { |
| 556 |
ckfree(tclDefaultEncodingDir); |
| 557 |
tclDefaultEncodingDir = NULL; |
| 558 |
} |
| 559 |
if (*argv[1] != '\0') { |
| 560 |
tclDefaultEncodingDir = (char *) |
| 561 |
ckalloc((unsigned) strlen(argv[1]) + 1); |
| 562 |
strcpy(tclDefaultEncodingDir, argv[1]); |
| 563 |
} |
| 564 |
return TCL_OK; |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
static int |
| 585 |
TestgetdefencdirCmd(clientData, interp, argc, argv) |
| 586 |
ClientData clientData; |
| 587 |
Tcl_Interp *interp; |
| 588 |
int argc; |
| 589 |
CONST char **argv; |
| 590 |
{ |
| 591 |
if (argc != 1) { |
| 592 |
Tcl_AppendResult(interp, |
| 593 |
"wrong # args: should be \"", argv[0], |
| 594 |
(char *) NULL); |
| 595 |
return TCL_ERROR; |
| 596 |
} |
| 597 |
|
| 598 |
if (tclDefaultEncodingDir != NULL) { |
| 599 |
Tcl_AppendResult(interp, tclDefaultEncodingDir, (char *) NULL); |
| 600 |
} |
| 601 |
return TCL_OK; |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
static int |
| 622 |
TestalarmCmd(clientData, interp, argc, argv) |
| 623 |
ClientData clientData; |
| 624 |
Tcl_Interp *interp; |
| 625 |
int argc; |
| 626 |
CONST char **argv; |
| 627 |
{ |
| 628 |
#ifdef SA_RESTART |
| 629 |
unsigned int sec; |
| 630 |
struct sigaction action; |
| 631 |
|
| 632 |
if (argc > 1) { |
| 633 |
Tcl_GetInt(interp, argv[1], (int *)&sec); |
| 634 |
} else { |
| 635 |
sec = 1; |
| 636 |
} |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
action.sa_handler = AlarmHandler; |
| 643 |
memset((void *)&action.sa_mask, 0, sizeof(sigset_t)); |
| 644 |
action.sa_flags = SA_RESTART; |
| 645 |
|
| 646 |
if (sigaction(SIGALRM, &action, NULL) < 0) { |
| 647 |
Tcl_AppendResult(interp, "sigaction: ", Tcl_PosixError(interp), NULL); |
| 648 |
return TCL_ERROR; |
| 649 |
} |
| 650 |
(void)alarm(sec); |
| 651 |
return TCL_OK; |
| 652 |
#else |
| 653 |
Tcl_AppendResult(interp, "warning: sigaction SA_RESTART not support on this platform", NULL); |
| 654 |
return TCL_ERROR; |
| 655 |
#endif |
| 656 |
} |
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
static void |
| 675 |
AlarmHandler() |
| 676 |
{ |
| 677 |
gotsig = "1"; |
| 678 |
} |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
static int |
| 696 |
TestgotsigCmd(clientData, interp, argc, argv) |
| 697 |
ClientData clientData; |
| 698 |
Tcl_Interp *interp; |
| 699 |
int argc; |
| 700 |
CONST char **argv; |
| 701 |
{ |
| 702 |
Tcl_AppendResult(interp, gotsig, (char *) NULL); |
| 703 |
gotsig = "0"; |
| 704 |
return TCL_OK; |
| 705 |
} |