| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "tclInt.h" |
| 16 |
#include "tclPort.h" |
| 17 |
|
| 18 |
static int NativeMatchType(CONST char* nativeName, Tcl_GlobTypeData *types); |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
char * |
| 46 |
TclpFindExecutable(argv0) |
| 47 |
CONST char *argv0; |
| 48 |
|
| 49 |
{ |
| 50 |
CONST char *name, *p; |
| 51 |
Tcl_StatBuf statBuf; |
| 52 |
int length; |
| 53 |
Tcl_DString buffer, nameString; |
| 54 |
|
| 55 |
if (argv0 == NULL) { |
| 56 |
return NULL; |
| 57 |
} |
| 58 |
if (tclNativeExecutableName != NULL) { |
| 59 |
return tclNativeExecutableName; |
| 60 |
} |
| 61 |
|
| 62 |
Tcl_DStringInit(&buffer); |
| 63 |
|
| 64 |
name = argv0; |
| 65 |
for (p = name; *p != '\0'; p++) { |
| 66 |
if (*p == '/') { |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
goto gotName; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
p = getenv("PATH"); |
| 77 |
if (p == NULL) { |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
p = ":/bin:/usr/bin"; |
| 84 |
} else if (*p == '\0') { |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
p = "./"; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
while (1) { |
| 99 |
while (isspace(UCHAR(*p))) { |
| 100 |
p++; |
| 101 |
} |
| 102 |
name = p; |
| 103 |
while ((*p != ':') && (*p != 0)) { |
| 104 |
p++; |
| 105 |
} |
| 106 |
Tcl_DStringSetLength(&buffer, 0); |
| 107 |
if (p != name) { |
| 108 |
Tcl_DStringAppend(&buffer, name, p - name); |
| 109 |
if (p[-1] != '/') { |
| 110 |
Tcl_DStringAppend(&buffer, "/", 1); |
| 111 |
} |
| 112 |
} |
| 113 |
name = Tcl_DStringAppend(&buffer, argv0, -1); |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
if ((access(name, X_OK) == 0) |
| 122 |
&& (TclOSstat(name, &statBuf) == 0) |
| 123 |
&& S_ISREG(statBuf.st_mode)) { |
| 124 |
goto gotName; |
| 125 |
} |
| 126 |
if (*p == '\0') { |
| 127 |
break; |
| 128 |
} else if (*(p+1) == 0) { |
| 129 |
p = "./"; |
| 130 |
} else { |
| 131 |
p++; |
| 132 |
} |
| 133 |
} |
| 134 |
goto done; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
gotName: |
| 141 |
#ifdef DJGPP |
| 142 |
if (name[1] == ':') { |
| 143 |
#else |
| 144 |
if (name[0] == '/') { |
| 145 |
#endif |
| 146 |
Tcl_ExternalToUtfDString(NULL, name, -1, &nameString); |
| 147 |
tclNativeExecutableName = (char *) |
| 148 |
ckalloc((unsigned) (Tcl_DStringLength(&nameString) + 1)); |
| 149 |
strcpy(tclNativeExecutableName, Tcl_DStringValue(&nameString)); |
| 150 |
Tcl_DStringFree(&nameString); |
| 151 |
goto done; |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
if ((name[0] == '.') && (name[1] == '/')) { |
| 161 |
name += 2; |
| 162 |
} |
| 163 |
|
| 164 |
Tcl_ExternalToUtfDString(NULL, name, -1, &nameString); |
| 165 |
|
| 166 |
Tcl_DStringFree(&buffer); |
| 167 |
TclpGetCwd(NULL, &buffer); |
| 168 |
|
| 169 |
length = Tcl_DStringLength(&buffer) + Tcl_DStringLength(&nameString) + 2; |
| 170 |
tclNativeExecutableName = (char *) ckalloc((unsigned) length); |
| 171 |
strcpy(tclNativeExecutableName, Tcl_DStringValue(&buffer)); |
| 172 |
tclNativeExecutableName[Tcl_DStringLength(&buffer)] = '/'; |
| 173 |
strcpy(tclNativeExecutableName + Tcl_DStringLength(&buffer) + 1, |
| 174 |
Tcl_DStringValue(&nameString)); |
| 175 |
Tcl_DStringFree(&nameString); |
| 176 |
|
| 177 |
done: |
| 178 |
Tcl_DStringFree(&buffer); |
| 179 |
return tclNativeExecutableName; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
int |
| 201 |
TclpMatchInDirectory(interp, resultPtr, pathPtr, pattern, types) |
| 202 |
Tcl_Interp *interp; |
| 203 |
Tcl_Obj *resultPtr; |
| 204 |
Tcl_Obj *pathPtr; |
| 205 |
CONST char *pattern; |
| 206 |
Tcl_GlobTypeData *types; |
| 207 |
|
| 208 |
|
| 209 |
{ |
| 210 |
CONST char *native; |
| 211 |
Tcl_Obj *fileNamePtr; |
| 212 |
|
| 213 |
fileNamePtr = Tcl_FSGetTranslatedPath(interp, pathPtr); |
| 214 |
if (fileNamePtr == NULL) { |
| 215 |
return TCL_ERROR; |
| 216 |
} |
| 217 |
|
| 218 |
if (pattern == NULL || (*pattern == '\0')) { |
| 219 |
|
| 220 |
native = (CONST char*) Tcl_FSGetNativePath(pathPtr); |
| 221 |
if (NativeMatchType(native, types)) { |
| 222 |
Tcl_ListObjAppendElement(interp, resultPtr, pathPtr); |
| 223 |
} |
| 224 |
Tcl_DecrRefCount(fileNamePtr); |
| 225 |
return TCL_OK; |
| 226 |
} else { |
| 227 |
DIR *d; |
| 228 |
Tcl_DirEntry *entryPtr; |
| 229 |
CONST char *dirName; |
| 230 |
int dirLength; |
| 231 |
int matchHidden; |
| 232 |
int nativeDirLen; |
| 233 |
Tcl_StatBuf statBuf; |
| 234 |
Tcl_DString ds; |
| 235 |
Tcl_DString dsOrig; |
| 236 |
|
| 237 |
Tcl_DStringInit(&dsOrig); |
| 238 |
dirName = Tcl_GetStringFromObj(fileNamePtr, &dirLength); |
| 239 |
Tcl_DStringAppend(&dsOrig, dirName, dirLength); |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
if (dirLength == 0) { |
| 250 |
dirName = "."; |
| 251 |
} else { |
| 252 |
dirName = Tcl_DStringValue(&dsOrig); |
| 253 |
|
| 254 |
if (dirName[dirLength-1] != '/') { |
| 255 |
dirName = Tcl_DStringAppend(&dsOrig, "/", 1); |
| 256 |
dirLength++; |
| 257 |
} |
| 258 |
} |
| 259 |
Tcl_DecrRefCount(fileNamePtr); |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
native = Tcl_UtfToExternalDString(NULL, dirName, -1, &ds); |
| 266 |
|
| 267 |
if ((TclOSstat(native, &statBuf) != 0) |
| 268 |
|| !S_ISDIR(statBuf.st_mode)) { |
| 269 |
Tcl_DStringFree(&dsOrig); |
| 270 |
Tcl_DStringFree(&ds); |
| 271 |
return TCL_OK; |
| 272 |
} |
| 273 |
|
| 274 |
d = opendir(native); |
| 275 |
if (d == NULL) { |
| 276 |
Tcl_DStringFree(&ds); |
| 277 |
Tcl_ResetResult(interp); |
| 278 |
Tcl_AppendResult(interp, "couldn't read directory \"", |
| 279 |
Tcl_DStringValue(&dsOrig), "\": ", |
| 280 |
Tcl_PosixError(interp), (char *) NULL); |
| 281 |
Tcl_DStringFree(&dsOrig); |
| 282 |
return TCL_ERROR; |
| 283 |
} |
| 284 |
|
| 285 |
nativeDirLen = Tcl_DStringLength(&ds); |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
matchHidden = ((types && (types->perm & TCL_GLOB_PERM_HIDDEN)) || |
| 291 |
((pattern[0] == '.') |
| 292 |
|| ((pattern[0] == '\\') && (pattern[1] == '.')))); |
| 293 |
|
| 294 |
while ((entryPtr = TclOSreaddir(d)) != NULL) { |
| 295 |
Tcl_DString utfDs; |
| 296 |
CONST char *utfname; |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
if (*entryPtr->d_name == '.') { |
| 303 |
if (!matchHidden) continue; |
| 304 |
} else { |
| 305 |
if (matchHidden) continue; |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
utfname = Tcl_ExternalToUtfDString(NULL, entryPtr->d_name, |
| 314 |
-1, &utfDs); |
| 315 |
if (Tcl_StringCaseMatch(utfname, pattern, 0)) { |
| 316 |
int typeOk = 1; |
| 317 |
|
| 318 |
if (types != NULL) { |
| 319 |
Tcl_DStringSetLength(&ds, nativeDirLen); |
| 320 |
native = Tcl_DStringAppend(&ds, entryPtr->d_name, -1); |
| 321 |
typeOk = NativeMatchType(native, types); |
| 322 |
} |
| 323 |
if (typeOk) { |
| 324 |
Tcl_ListObjAppendElement(interp, resultPtr, |
| 325 |
TclNewFSPathObj(pathPtr, utfname, |
| 326 |
Tcl_DStringLength(&utfDs))); |
| 327 |
} |
| 328 |
} |
| 329 |
Tcl_DStringFree(&utfDs); |
| 330 |
} |
| 331 |
|
| 332 |
closedir(d); |
| 333 |
Tcl_DStringFree(&ds); |
| 334 |
Tcl_DStringFree(&dsOrig); |
| 335 |
return TCL_OK; |
| 336 |
} |
| 337 |
} |
| 338 |
static int |
| 339 |
NativeMatchType( |
| 340 |
CONST char* nativeEntry, |
| 341 |
Tcl_GlobTypeData *types) |
| 342 |
{ |
| 343 |
Tcl_StatBuf buf; |
| 344 |
if (types == NULL) { |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
if (TclOSlstat(nativeEntry, &buf) != 0) { |
| 352 |
return 0; |
| 353 |
} |
| 354 |
} else { |
| 355 |
if (types->perm != 0) { |
| 356 |
if (TclOSstat(nativeEntry, &buf) != 0) { |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
return 0; |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
if (((types->perm & TCL_GLOB_PERM_RONLY) && |
| 376 |
(buf.st_mode & (S_IWOTH|S_IWGRP|S_IWUSR))) || |
| 377 |
((types->perm & TCL_GLOB_PERM_R) && |
| 378 |
(access(nativeEntry, R_OK) != 0)) || |
| 379 |
((types->perm & TCL_GLOB_PERM_W) && |
| 380 |
(access(nativeEntry, W_OK) != 0)) || |
| 381 |
((types->perm & TCL_GLOB_PERM_X) && |
| 382 |
(access(nativeEntry, X_OK) != 0)) |
| 383 |
) { |
| 384 |
return 0; |
| 385 |
} |
| 386 |
} |
| 387 |
if (types->type != 0) { |
| 388 |
if (types->perm == 0) { |
| 389 |
|
| 390 |
if (TclOSstat(nativeEntry, &buf) != 0) { |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
if (types->type & TCL_GLOB_TYPE_LINK) { |
| 398 |
if (TclOSlstat(nativeEntry, &buf) == 0) { |
| 399 |
if (S_ISLNK(buf.st_mode)) { |
| 400 |
return 1; |
| 401 |
} |
| 402 |
} |
| 403 |
} |
| 404 |
return 0; |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
if ( |
| 411 |
((types->type & TCL_GLOB_TYPE_BLOCK) && |
| 412 |
S_ISBLK(buf.st_mode)) || |
| 413 |
((types->type & TCL_GLOB_TYPE_CHAR) && |
| 414 |
S_ISCHR(buf.st_mode)) || |
| 415 |
((types->type & TCL_GLOB_TYPE_DIR) && |
| 416 |
S_ISDIR(buf.st_mode)) || |
| 417 |
((types->type & TCL_GLOB_TYPE_PIPE) && |
| 418 |
S_ISFIFO(buf.st_mode)) || |
| 419 |
((types->type & TCL_GLOB_TYPE_FILE) && |
| 420 |
S_ISREG(buf.st_mode)) |
| 421 |
#ifdef S_ISSOCK |
| 422 |
|| ((types->type & TCL_GLOB_TYPE_SOCK) && |
| 423 |
S_ISSOCK(buf.st_mode)) |
| 424 |
#endif |
| 425 |
) { |
| 426 |
|
| 427 |
} else { |
| 428 |
#ifdef S_ISLNK |
| 429 |
if (types->type & TCL_GLOB_TYPE_LINK) { |
| 430 |
if (TclOSlstat(nativeEntry, &buf) == 0) { |
| 431 |
if (S_ISLNK(buf.st_mode)) { |
| 432 |
return 1; |
| 433 |
} |
| 434 |
} |
| 435 |
} |
| 436 |
#endif |
| 437 |
return 0; |
| 438 |
} |
| 439 |
} |
| 440 |
} |
| 441 |
return 1; |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
char * |
| 466 |
TclpGetUserHome(name, bufferPtr) |
| 467 |
CONST char *name; |
| 468 |
Tcl_DString *bufferPtr; |
| 469 |
|
| 470 |
{ |
| 471 |
struct passwd *pwPtr; |
| 472 |
Tcl_DString ds; |
| 473 |
CONST char *native; |
| 474 |
|
| 475 |
native = Tcl_UtfToExternalDString(NULL, name, -1, &ds); |
| 476 |
pwPtr = getpwnam(native); |
| 477 |
Tcl_DStringFree(&ds); |
| 478 |
|
| 479 |
if (pwPtr == NULL) { |
| 480 |
endpwent(); |
| 481 |
return NULL; |
| 482 |
} |
| 483 |
Tcl_ExternalToUtfDString(NULL, pwPtr->pw_dir, -1, bufferPtr); |
| 484 |
endpwent(); |
| 485 |
return Tcl_DStringValue(bufferPtr); |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
int |
| 505 |
TclpObjAccess(pathPtr, mode) |
| 506 |
Tcl_Obj *pathPtr; |
| 507 |
int mode; |
| 508 |
{ |
| 509 |
CONST char *path = Tcl_FSGetNativePath(pathPtr); |
| 510 |
if (path == NULL) { |
| 511 |
return -1; |
| 512 |
} else { |
| 513 |
return access(path, mode); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
int |
| 534 |
TclpObjChdir(pathPtr) |
| 535 |
Tcl_Obj *pathPtr; |
| 536 |
{ |
| 537 |
CONST char *path = Tcl_FSGetNativePath(pathPtr); |
| 538 |
if (path == NULL) { |
| 539 |
return -1; |
| 540 |
} else { |
| 541 |
return chdir(path); |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
int |
| 562 |
TclpObjLstat(pathPtr, bufPtr) |
| 563 |
Tcl_Obj *pathPtr; |
| 564 |
Tcl_StatBuf *bufPtr; |
| 565 |
{ |
| 566 |
return TclOSlstat(Tcl_FSGetNativePath(pathPtr), bufPtr); |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
Tcl_Obj* |
| 591 |
TclpObjGetCwd(interp) |
| 592 |
Tcl_Interp *interp; |
| 593 |
{ |
| 594 |
Tcl_DString ds; |
| 595 |
if (TclpGetCwd(interp, &ds) != NULL) { |
| 596 |
Tcl_Obj *cwdPtr = Tcl_NewStringObj(Tcl_DStringValue(&ds), -1); |
| 597 |
Tcl_IncrRefCount(cwdPtr); |
| 598 |
Tcl_DStringFree(&ds); |
| 599 |
return cwdPtr; |
| 600 |
} else { |
| 601 |
return NULL; |
| 602 |
} |
| 603 |
} |
| 604 |
|
| 605 |
|
| 606 |
CONST char * |
| 607 |
TclpGetCwd(interp, bufferPtr) |
| 608 |
Tcl_Interp *interp; |
| 609 |
Tcl_DString *bufferPtr; |
| 610 |
|
| 611 |
{ |
| 612 |
char buffer[MAXPATHLEN+1]; |
| 613 |
|
| 614 |
#ifdef USEGETWD |
| 615 |
if (getwd(buffer) == NULL) { |
| 616 |
#else |
| 617 |
if (getcwd(buffer, MAXPATHLEN + 1) == NULL) { |
| 618 |
#endif |
| 619 |
if (interp != NULL) { |
| 620 |
Tcl_AppendResult(interp, |
| 621 |
"error getting working directory name: ", |
| 622 |
Tcl_PosixError(interp), (char *) NULL); |
| 623 |
} |
| 624 |
return NULL; |
| 625 |
} |
| 626 |
return Tcl_ExternalToUtfDString(NULL, buffer, -1, bufferPtr); |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
char * |
| 650 |
TclpReadlink(path, linkPtr) |
| 651 |
CONST char *path; |
| 652 |
Tcl_DString *linkPtr; |
| 653 |
|
| 654 |
{ |
| 655 |
#ifndef DJGPP |
| 656 |
char link[MAXPATHLEN]; |
| 657 |
int length; |
| 658 |
CONST char *native; |
| 659 |
Tcl_DString ds; |
| 660 |
|
| 661 |
native = Tcl_UtfToExternalDString(NULL, path, -1, &ds); |
| 662 |
length = readlink(native, link, sizeof(link)); |
| 663 |
Tcl_DStringFree(&ds); |
| 664 |
|
| 665 |
if (length < 0) { |
| 666 |
return NULL; |
| 667 |
} |
| 668 |
|
| 669 |
Tcl_ExternalToUtfDString(NULL, link, length, linkPtr); |
| 670 |
return Tcl_DStringValue(linkPtr); |
| 671 |
#else |
| 672 |
return NULL; |
| 673 |
#endif |
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
int |
| 693 |
TclpObjStat(pathPtr, bufPtr) |
| 694 |
Tcl_Obj *pathPtr; |
| 695 |
Tcl_StatBuf *bufPtr; |
| 696 |
{ |
| 697 |
CONST char *path = Tcl_FSGetNativePath(pathPtr); |
| 698 |
if (path == NULL) { |
| 699 |
return -1; |
| 700 |
} else { |
| 701 |
return TclOSstat(path, bufPtr); |
| 702 |
} |
| 703 |
} |
| 704 |
|
| 705 |
|
| 706 |
#ifdef S_IFLNK |
| 707 |
|
| 708 |
Tcl_Obj* |
| 709 |
TclpObjLink(pathPtr, toPtr, linkAction) |
| 710 |
Tcl_Obj *pathPtr; |
| 711 |
Tcl_Obj *toPtr; |
| 712 |
int linkAction; |
| 713 |
{ |
| 714 |
if (toPtr != NULL) { |
| 715 |
CONST char *src = Tcl_FSGetNativePath(pathPtr); |
| 716 |
CONST char *target = Tcl_FSGetNativePath(toPtr); |
| 717 |
|
| 718 |
if (src == NULL || target == NULL) { |
| 719 |
return NULL; |
| 720 |
} |
| 721 |
if (access(src, F_OK) != -1) { |
| 722 |
|
| 723 |
errno = EEXIST; |
| 724 |
return NULL; |
| 725 |
} |
| 726 |
if (access(target, F_OK) == -1) { |
| 727 |
|
| 728 |
errno = ENOENT; |
| 729 |
return NULL; |
| 730 |
} |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
if (linkAction & TCL_CREATE_SYMBOLIC_LINK) { |
| 736 |
if (symlink(target, src) != 0) return NULL; |
| 737 |
} else if (linkAction & TCL_CREATE_HARD_LINK) { |
| 738 |
if (link(target, src) != 0) return NULL; |
| 739 |
} else { |
| 740 |
errno = ENODEV; |
| 741 |
return NULL; |
| 742 |
} |
| 743 |
return toPtr; |
| 744 |
} else { |
| 745 |
Tcl_Obj* linkPtr = NULL; |
| 746 |
|
| 747 |
char link[MAXPATHLEN]; |
| 748 |
int length; |
| 749 |
Tcl_DString ds; |
| 750 |
Tcl_Obj *transPtr; |
| 751 |
|
| 752 |
transPtr = Tcl_FSGetTranslatedPath(NULL, pathPtr); |
| 753 |
if (transPtr == NULL) { |
| 754 |
return NULL; |
| 755 |
} |
| 756 |
Tcl_DecrRefCount(transPtr); |
| 757 |
|
| 758 |
length = readlink(Tcl_FSGetNativePath(pathPtr), link, sizeof(link)); |
| 759 |
if (length < 0) { |
| 760 |
return NULL; |
| 761 |
} |
| 762 |
|
| 763 |
Tcl_ExternalToUtfDString(NULL, link, length, &ds); |
| 764 |
linkPtr = Tcl_NewStringObj(Tcl_DStringValue(&ds), |
| 765 |
Tcl_DStringLength(&ds)); |
| 766 |
Tcl_DStringFree(&ds); |
| 767 |
if (linkPtr != NULL) { |
| 768 |
Tcl_IncrRefCount(linkPtr); |
| 769 |
} |
| 770 |
return linkPtr; |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
#endif |
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
Tcl_Obj* |
| 796 |
TclpFilesystemPathType(pathObjPtr) |
| 797 |
Tcl_Obj* pathObjPtr; |
| 798 |
{ |
| 799 |
|
| 800 |
return NULL; |
| 801 |
} |
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
int |
| 819 |
TclpUtime(pathPtr, tval) |
| 820 |
Tcl_Obj *pathPtr; |
| 821 |
struct utimbuf *tval; |
| 822 |
{ |
| 823 |
return utime(Tcl_FSGetNativePath(pathPtr),tval); |
| 824 |
} |