| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "tclInt.h" |
| 24 |
#include "tclPort.h" |
| 25 |
#ifdef MAC_TCL |
| 26 |
#include "tclMacInt.h" |
| 27 |
#endif |
| 28 |
#ifdef __WIN32__ |
| 29 |
|
| 30 |
#include "tclWinInt.h" |
| 31 |
#endif |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
typedef struct FilesystemRecord { |
| 43 |
ClientData clientData; |
| 44 |
|
| 45 |
Tcl_Filesystem *fsPtr; |
| 46 |
|
| 47 |
int fileRefCount; |
| 48 |
|
| 49 |
struct FilesystemRecord *nextPtr; |
| 50 |
|
| 51 |
|
| 52 |
struct FilesystemRecord *prevPtr; |
| 53 |
|
| 54 |
|
| 55 |
} FilesystemRecord; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
int TclFSCwdPointerEquals _ANSI_ARGS_((Tcl_Obj* objPtr)); |
| 66 |
int TclFSMakePathFromNormalized _ANSI_ARGS_((Tcl_Interp *interp, |
| 67 |
Tcl_Obj *objPtr, ClientData clientData)); |
| 68 |
int TclFSNormalizeToUniquePath _ANSI_ARGS_((Tcl_Interp *interp, |
| 69 |
Tcl_Obj *pathPtr, int startAt, ClientData *clientDataPtr)); |
| 70 |
Tcl_Obj* TclFSMakePathRelative _ANSI_ARGS_((Tcl_Interp *interp, |
| 71 |
Tcl_Obj *objPtr, Tcl_Obj *cwdPtr)); |
| 72 |
Tcl_Obj* TclFSInternalToNormalized _ANSI_ARGS_(( |
| 73 |
Tcl_Filesystem *fromFilesystem, ClientData clientData, |
| 74 |
FilesystemRecord **fsRecPtrPtr)); |
| 75 |
int TclFSEnsureEpochOk _ANSI_ARGS_((Tcl_Obj* pathObjPtr, |
| 76 |
Tcl_Filesystem **fsPtrPtr)); |
| 77 |
void TclFSSetPathDetails _ANSI_ARGS_((Tcl_Obj *pathObjPtr, |
| 78 |
FilesystemRecord *fsRecPtr, ClientData clientData)); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
extern Tcl_Filesystem tclNativeFilesystem; |
| 84 |
extern int theFilesystemEpoch; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
Tcl_PathType FSGetPathType _ANSI_ARGS_((Tcl_Obj *pathObjPtr, |
| 90 |
Tcl_Filesystem **filesystemPtrPtr, |
| 91 |
int *driveNameLengthPtr)); |
| 92 |
Tcl_PathType GetPathType _ANSI_ARGS_((Tcl_Obj *pathObjPtr, |
| 93 |
Tcl_Filesystem **filesystemPtrPtr, |
| 94 |
int *driveNameLengthPtr, Tcl_Obj **driveNameRef)); |
| 95 |
Tcl_FSPathInFilesystemProc NativePathInFilesystem; |
| 96 |
static Tcl_Obj* TclFSNormalizeAbsolutePath |
| 97 |
_ANSI_ARGS_((Tcl_Interp* interp, Tcl_Obj *pathPtr, |
| 98 |
ClientData *clientDataPtr)); |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
static FilesystemRecord* FsGetFirstFilesystem(void); |
| 104 |
static void FsThrExitProc(ClientData cd); |
| 105 |
static Tcl_Obj* FsListMounts _ANSI_ARGS_((Tcl_Obj *pathPtr, |
| 106 |
CONST char *pattern)); |
| 107 |
static Tcl_Obj* FsAddMountsToGlobResult _ANSI_ARGS_((Tcl_Obj *result, |
| 108 |
Tcl_Obj *pathPtr, CONST char *pattern, Tcl_GlobTypeData *types)); |
| 109 |
|
| 110 |
#ifdef TCL_THREADS |
| 111 |
static void FsRecacheFilesystemList(void); |
| 112 |
#endif |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
extern CONST char * tclpFileAttrStrings[]; |
| 122 |
extern CONST TclFileAttrProcs tclpFileAttrProcs[]; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
int |
| 131 |
Tcl_Stat(path, oldStyleBuf) |
| 132 |
CONST char *path; |
| 133 |
struct stat *oldStyleBuf; |
| 134 |
{ |
| 135 |
int ret; |
| 136 |
Tcl_StatBuf buf; |
| 137 |
Tcl_Obj *pathPtr = Tcl_NewStringObj(path,-1); |
| 138 |
|
| 139 |
Tcl_IncrRefCount(pathPtr); |
| 140 |
ret = Tcl_FSStat(pathPtr, &buf); |
| 141 |
Tcl_DecrRefCount(pathPtr); |
| 142 |
if (ret != -1) { |
| 143 |
#ifndef TCL_WIDE_INT_IS_LONG |
| 144 |
# define OUT_OF_RANGE(x) \ |
| 145 |
(((Tcl_WideInt)(x)) < Tcl_LongAsWide(LONG_MIN) || \ |
| 146 |
((Tcl_WideInt)(x)) > Tcl_LongAsWide(LONG_MAX)) |
| 147 |
# define OUT_OF_URANGE(x) \ |
| 148 |
(((Tcl_WideUInt)(x)) > (Tcl_WideUInt)ULONG_MAX) |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
if (OUT_OF_URANGE(buf.st_ino) || OUT_OF_RANGE(buf.st_size) |
| 157 |
#ifdef HAVE_ST_BLOCKS |
| 158 |
|| OUT_OF_RANGE(buf.st_blocks) |
| 159 |
#endif |
| 160 |
) { |
| 161 |
#ifdef EFBIG |
| 162 |
errno = EFBIG; |
| 163 |
#else |
| 164 |
# ifdef EOVERFLOW |
| 165 |
errno = EOVERFLOW; |
| 166 |
# else |
| 167 |
# error "What status should be returned for file size out of range?" |
| 168 |
# endif |
| 169 |
#endif |
| 170 |
return -1; |
| 171 |
} |
| 172 |
|
| 173 |
# undef OUT_OF_RANGE |
| 174 |
# undef OUT_OF_URANGE |
| 175 |
#endif |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
oldStyleBuf->st_mode = buf.st_mode; |
| 186 |
oldStyleBuf->st_ino = (ino_t) buf.st_ino; |
| 187 |
oldStyleBuf->st_dev = buf.st_dev; |
| 188 |
oldStyleBuf->st_rdev = buf.st_rdev; |
| 189 |
oldStyleBuf->st_nlink = buf.st_nlink; |
| 190 |
oldStyleBuf->st_uid = buf.st_uid; |
| 191 |
oldStyleBuf->st_gid = buf.st_gid; |
| 192 |
oldStyleBuf->st_size = (off_t) buf.st_size; |
| 193 |
oldStyleBuf->st_atime = buf.st_atime; |
| 194 |
oldStyleBuf->st_mtime = buf.st_mtime; |
| 195 |
oldStyleBuf->st_ctime = buf.st_ctime; |
| 196 |
#ifdef HAVE_ST_BLOCKS |
| 197 |
oldStyleBuf->st_blksize = buf.st_blksize; |
| 198 |
oldStyleBuf->st_blocks = (blkcnt_t) buf.st_blocks; |
| 199 |
#endif |
| 200 |
} |
| 201 |
return ret; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
int |
| 206 |
Tcl_Access(path, mode) |
| 207 |
CONST char *path; |
| 208 |
int mode; |
| 209 |
{ |
| 210 |
int ret; |
| 211 |
Tcl_Obj *pathPtr = Tcl_NewStringObj(path,-1); |
| 212 |
Tcl_IncrRefCount(pathPtr); |
| 213 |
ret = Tcl_FSAccess(pathPtr,mode); |
| 214 |
Tcl_DecrRefCount(pathPtr); |
| 215 |
return ret; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
Tcl_Channel |
| 220 |
Tcl_OpenFileChannel(interp, path, modeString, permissions) |
| 221 |
Tcl_Interp *interp; |
| 222 |
|
| 223 |
CONST char *path; |
| 224 |
CONST char *modeString; |
| 225 |
|
| 226 |
int permissions; |
| 227 |
|
| 228 |
|
| 229 |
{ |
| 230 |
Tcl_Channel ret; |
| 231 |
Tcl_Obj *pathPtr = Tcl_NewStringObj(path,-1); |
| 232 |
Tcl_IncrRefCount(pathPtr); |
| 233 |
ret = Tcl_FSOpenFileChannel(interp, pathPtr, modeString, permissions); |
| 234 |
Tcl_DecrRefCount(pathPtr); |
| 235 |
return ret; |
| 236 |
|
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
int |
| 241 |
Tcl_Chdir(dirName) |
| 242 |
CONST char *dirName; |
| 243 |
{ |
| 244 |
int ret; |
| 245 |
Tcl_Obj *pathPtr = Tcl_NewStringObj(dirName,-1); |
| 246 |
Tcl_IncrRefCount(pathPtr); |
| 247 |
ret = Tcl_FSChdir(pathPtr); |
| 248 |
Tcl_DecrRefCount(pathPtr); |
| 249 |
return ret; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
char * |
| 254 |
Tcl_GetCwd(interp, cwdPtr) |
| 255 |
Tcl_Interp *interp; |
| 256 |
Tcl_DString *cwdPtr; |
| 257 |
{ |
| 258 |
Tcl_Obj *cwd; |
| 259 |
cwd = Tcl_FSGetCwd(interp); |
| 260 |
if (cwd == NULL) { |
| 261 |
return NULL; |
| 262 |
} else { |
| 263 |
Tcl_DStringInit(cwdPtr); |
| 264 |
Tcl_DStringAppend(cwdPtr, Tcl_GetString(cwd), -1); |
| 265 |
Tcl_DecrRefCount(cwd); |
| 266 |
return Tcl_DStringValue(cwdPtr); |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
int |
| 272 |
Tcl_EvalFile(interp, fileName) |
| 273 |
Tcl_Interp *interp; |
| 274 |
CONST char *fileName; |
| 275 |
|
| 276 |
{ |
| 277 |
int ret; |
| 278 |
Tcl_Obj *pathPtr = Tcl_NewStringObj(fileName,-1); |
| 279 |
Tcl_IncrRefCount(pathPtr); |
| 280 |
ret = Tcl_FSEvalFile(interp, pathPtr); |
| 281 |
Tcl_DecrRefCount(pathPtr); |
| 282 |
return ret; |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
#define USE_OBSOLETE_FS_HOOKS |
| 299 |
|
| 300 |
|
| 301 |
#ifdef USE_OBSOLETE_FS_HOOKS |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
typedef struct StatProc { |
| 310 |
TclStatProc_ *proc; |
| 311 |
struct StatProc *nextPtr; |
| 312 |
} StatProc; |
| 313 |
|
| 314 |
typedef struct AccessProc { |
| 315 |
TclAccessProc_ *proc; |
| 316 |
struct AccessProc *nextPtr; |
| 317 |
} AccessProc; |
| 318 |
|
| 319 |
typedef struct OpenFileChannelProc { |
| 320 |
TclOpenFileChannelProc_ *proc; |
| 321 |
|
| 322 |
struct OpenFileChannelProc *nextPtr; |
| 323 |
|
| 324 |
|
| 325 |
} OpenFileChannelProc; |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
static StatProc *statProcList = NULL; |
| 343 |
static AccessProc *accessProcList = NULL; |
| 344 |
static OpenFileChannelProc *openFileChannelProcList = NULL; |
| 345 |
|
| 346 |
TCL_DECLARE_MUTEX(obsoleteFsHookMutex) |
| 347 |
|
| 348 |
#endif |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
static Tcl_FSFilesystemSeparatorProc NativeFilesystemSeparator; |
| 364 |
static Tcl_FSFreeInternalRepProc NativeFreeInternalRep; |
| 365 |
Tcl_FSDupInternalRepProc NativeDupInternalRep; |
| 366 |
static Tcl_FSCreateInternalRepProc NativeCreateNativeRep; |
| 367 |
static Tcl_FSFileAttrStringsProc NativeFileAttrStrings; |
| 368 |
static Tcl_FSFileAttrsGetProc NativeFileAttrsGet; |
| 369 |
static Tcl_FSFileAttrsSetProc NativeFileAttrsSet; |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
Tcl_FSFilesystemPathTypeProc TclpFilesystemPathType; |
| 382 |
Tcl_FSInternalToNormalizedProc TclpNativeToNormalized; |
| 383 |
Tcl_FSStatProc TclpObjStat; |
| 384 |
Tcl_FSAccessProc TclpObjAccess; |
| 385 |
Tcl_FSMatchInDirectoryProc TclpMatchInDirectory; |
| 386 |
Tcl_FSGetCwdProc TclpObjGetCwd; |
| 387 |
Tcl_FSChdirProc TclpObjChdir; |
| 388 |
Tcl_FSLstatProc TclpObjLstat; |
| 389 |
Tcl_FSCopyFileProc TclpObjCopyFile; |
| 390 |
Tcl_FSDeleteFileProc TclpObjDeleteFile; |
| 391 |
Tcl_FSRenameFileProc TclpObjRenameFile; |
| 392 |
Tcl_FSCreateDirectoryProc TclpObjCreateDirectory; |
| 393 |
Tcl_FSCopyDirectoryProc TclpObjCopyDirectory; |
| 394 |
Tcl_FSRemoveDirectoryProc TclpObjRemoveDirectory; |
| 395 |
Tcl_FSUnloadFileProc TclpUnloadFile; |
| 396 |
Tcl_FSLinkProc TclpObjLink; |
| 397 |
Tcl_FSListVolumesProc TclpObjListVolumes; |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
Tcl_Filesystem tclNativeFilesystem = { |
| 408 |
"native", |
| 409 |
sizeof(Tcl_Filesystem), |
| 410 |
TCL_FILESYSTEM_VERSION_1, |
| 411 |
&NativePathInFilesystem, |
| 412 |
&NativeDupInternalRep, |
| 413 |
&NativeFreeInternalRep, |
| 414 |
&TclpNativeToNormalized, |
| 415 |
&NativeCreateNativeRep, |
| 416 |
&TclpObjNormalizePath, |
| 417 |
&TclpFilesystemPathType, |
| 418 |
&NativeFilesystemSeparator, |
| 419 |
&TclpObjStat, |
| 420 |
&TclpObjAccess, |
| 421 |
&TclpOpenFileChannel, |
| 422 |
&TclpMatchInDirectory, |
| 423 |
&TclpUtime, |
| 424 |
#ifndef S_IFLNK |
| 425 |
NULL, |
| 426 |
#else |
| 427 |
&TclpObjLink, |
| 428 |
#endif |
| 429 |
&TclpObjListVolumes, |
| 430 |
&NativeFileAttrStrings, |
| 431 |
&NativeFileAttrsGet, |
| 432 |
&NativeFileAttrsSet, |
| 433 |
&TclpObjCreateDirectory, |
| 434 |
&TclpObjRemoveDirectory, |
| 435 |
&TclpObjDeleteFile, |
| 436 |
&TclpObjCopyFile, |
| 437 |
&TclpObjRenameFile, |
| 438 |
&TclpObjCopyDirectory, |
| 439 |
&TclpObjLstat, |
| 440 |
&TclpDlopen, |
| 441 |
&TclpObjGetCwd, |
| 442 |
&TclpObjChdir |
| 443 |
}; |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
static FilesystemRecord nativeFilesystemRecord = { |
| 455 |
NULL, |
| 456 |
&tclNativeFilesystem, |
| 457 |
1, |
| 458 |
NULL |
| 459 |
}; |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
int theFilesystemEpoch = 0; |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
static FilesystemRecord *filesystemList = &nativeFilesystemRecord; |
| 476 |
|
| 477 |
TCL_DECLARE_MUTEX(filesystemMutex) |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
static Tcl_Obj* cwdPathPtr = NULL; |
| 483 |
static int cwdPathEpoch = 0; |
| 484 |
TCL_DECLARE_MUTEX(cwdMutex) |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
typedef struct ThreadSpecificData { |
| 495 |
int initialized; |
| 496 |
int cwdPathEpoch; |
| 497 |
int filesystemEpoch; |
| 498 |
Tcl_Obj *cwdPathPtr; |
| 499 |
FilesystemRecord *filesystemList; |
| 500 |
} ThreadSpecificData; |
| 501 |
|
| 502 |
Tcl_ThreadDataKey dataKey; |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
static Tcl_FSUnloadFileProc FSUnloadTempFile; |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
typedef struct FsDivertLoad { |
| 519 |
Tcl_LoadHandle loadHandle; |
| 520 |
Tcl_FSUnloadFileProc *unloadProcPtr; |
| 521 |
Tcl_Obj *divertedFile; |
| 522 |
Tcl_Filesystem *divertedFilesystem; |
| 523 |
ClientData divertedFileNativeRep; |
| 524 |
} FsDivertLoad; |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
static void |
| 529 |
FsThrExitProc(cd) |
| 530 |
ClientData cd; |
| 531 |
{ |
| 532 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData*)cd; |
| 533 |
FilesystemRecord *fsRecPtr = NULL, *tmpFsRecPtr = NULL; |
| 534 |
|
| 535 |
|
| 536 |
if (tsdPtr->cwdPathPtr != NULL) { |
| 537 |
Tcl_DecrRefCount(tsdPtr->cwdPathPtr); |
| 538 |
} |
| 539 |
|
| 540 |
fsRecPtr = tsdPtr->filesystemList; |
| 541 |
while (fsRecPtr != NULL) { |
| 542 |
tmpFsRecPtr = fsRecPtr->nextPtr; |
| 543 |
if (--fsRecPtr->fileRefCount <= 0) { |
| 544 |
ckfree((char *)fsRecPtr); |
| 545 |
} |
| 546 |
fsRecPtr = tmpFsRecPtr; |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
int |
| 551 |
TclFSCwdPointerEquals(objPtr) |
| 552 |
Tcl_Obj* objPtr; |
| 553 |
{ |
| 554 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 555 |
|
| 556 |
Tcl_MutexLock(&cwdMutex); |
| 557 |
if (tsdPtr->cwdPathPtr == NULL) { |
| 558 |
if (cwdPathPtr == NULL) { |
| 559 |
tsdPtr->cwdPathPtr = NULL; |
| 560 |
} else { |
| 561 |
tsdPtr->cwdPathPtr = Tcl_DuplicateObj(cwdPathPtr); |
| 562 |
Tcl_IncrRefCount(tsdPtr->cwdPathPtr); |
| 563 |
} |
| 564 |
tsdPtr->cwdPathEpoch = cwdPathEpoch; |
| 565 |
} else if (tsdPtr->cwdPathEpoch != cwdPathEpoch) { |
| 566 |
Tcl_DecrRefCount(tsdPtr->cwdPathPtr); |
| 567 |
if (cwdPathPtr == NULL) { |
| 568 |
tsdPtr->cwdPathPtr = NULL; |
| 569 |
} else { |
| 570 |
tsdPtr->cwdPathPtr = Tcl_DuplicateObj(cwdPathPtr); |
| 571 |
Tcl_IncrRefCount(tsdPtr->cwdPathPtr); |
| 572 |
} |
| 573 |
} |
| 574 |
Tcl_MutexUnlock(&cwdMutex); |
| 575 |
|
| 576 |
if (tsdPtr->initialized == 0) { |
| 577 |
Tcl_CreateThreadExitHandler(FsThrExitProc, (ClientData)tsdPtr); |
| 578 |
tsdPtr->initialized = 1; |
| 579 |
} |
| 580 |
return (tsdPtr->cwdPathPtr == objPtr); |
| 581 |
} |
| 582 |
#ifdef TCL_THREADS |
| 583 |
|
| 584 |
static void |
| 585 |
FsRecacheFilesystemList(void) |
| 586 |
{ |
| 587 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 588 |
FilesystemRecord *fsRecPtr, *tmpFsRecPtr = NULL; |
| 589 |
|
| 590 |
|
| 591 |
fsRecPtr = tsdPtr->filesystemList; |
| 592 |
while (fsRecPtr != NULL) { |
| 593 |
tmpFsRecPtr = fsRecPtr->nextPtr; |
| 594 |
if (--fsRecPtr->fileRefCount <= 0) { |
| 595 |
ckfree((char *)fsRecPtr); |
| 596 |
} |
| 597 |
fsRecPtr = tmpFsRecPtr; |
| 598 |
} |
| 599 |
tsdPtr->filesystemList = NULL; |
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
fsRecPtr = filesystemList; |
| 609 |
while (fsRecPtr != NULL) { |
| 610 |
tmpFsRecPtr = fsRecPtr; |
| 611 |
fsRecPtr = fsRecPtr->nextPtr; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
fsRecPtr = tmpFsRecPtr; |
| 616 |
while (fsRecPtr != NULL) { |
| 617 |
tmpFsRecPtr = (FilesystemRecord *)ckalloc(sizeof(FilesystemRecord)); |
| 618 |
*tmpFsRecPtr = *fsRecPtr; |
| 619 |
tmpFsRecPtr->nextPtr = tsdPtr->filesystemList; |
| 620 |
tmpFsRecPtr->prevPtr = NULL; |
| 621 |
if (tsdPtr->filesystemList) { |
| 622 |
tsdPtr->filesystemList->prevPtr = tmpFsRecPtr; |
| 623 |
} |
| 624 |
tsdPtr->filesystemList = tmpFsRecPtr; |
| 625 |
fsRecPtr = fsRecPtr->prevPtr; |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
if (tsdPtr->initialized == 0) { |
| 630 |
Tcl_CreateThreadExitHandler(FsThrExitProc, (ClientData)tsdPtr); |
| 631 |
tsdPtr->initialized = 1; |
| 632 |
} |
| 633 |
} |
| 634 |
#endif |
| 635 |
|
| 636 |
static FilesystemRecord * |
| 637 |
FsGetFirstFilesystem(void) { |
| 638 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 639 |
FilesystemRecord *fsRecPtr; |
| 640 |
#ifndef TCL_THREADS |
| 641 |
tsdPtr->filesystemEpoch = theFilesystemEpoch; |
| 642 |
fsRecPtr = filesystemList; |
| 643 |
#else |
| 644 |
Tcl_MutexLock(&filesystemMutex); |
| 645 |
if (tsdPtr->filesystemList == NULL |
| 646 |
|| (tsdPtr->filesystemEpoch != theFilesystemEpoch)) { |
| 647 |
FsRecacheFilesystemList(); |
| 648 |
tsdPtr->filesystemEpoch = theFilesystemEpoch; |
| 649 |
} |
| 650 |
Tcl_MutexUnlock(&filesystemMutex); |
| 651 |
fsRecPtr = tsdPtr->filesystemList; |
| 652 |
#endif |
| 653 |
return fsRecPtr; |
| 654 |
} |
| 655 |
|
| 656 |
static void |
| 657 |
FsUpdateCwd(cwdObj) |
| 658 |
Tcl_Obj *cwdObj; |
| 659 |
{ |
| 660 |
int len; |
| 661 |
char *str = NULL; |
| 662 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 663 |
|
| 664 |
if (cwdObj != NULL) { |
| 665 |
str = Tcl_GetStringFromObj(cwdObj, &len); |
| 666 |
} |
| 667 |
|
| 668 |
Tcl_MutexLock(&cwdMutex); |
| 669 |
if (cwdPathPtr != NULL) { |
| 670 |
Tcl_DecrRefCount(cwdPathPtr); |
| 671 |
} |
| 672 |
if (cwdObj == NULL) { |
| 673 |
cwdPathPtr = NULL; |
| 674 |
} else { |
| 675 |
|
| 676 |
cwdPathPtr = Tcl_NewStringObj(str, len); |
| 677 |
Tcl_IncrRefCount(cwdPathPtr); |
| 678 |
} |
| 679 |
cwdPathEpoch++; |
| 680 |
tsdPtr->cwdPathEpoch = cwdPathEpoch; |
| 681 |
Tcl_MutexUnlock(&cwdMutex); |
| 682 |
|
| 683 |
if (tsdPtr->cwdPathPtr) { |
| 684 |
Tcl_DecrRefCount(tsdPtr->cwdPathPtr); |
| 685 |
} |
| 686 |
if (cwdObj == NULL) { |
| 687 |
tsdPtr->cwdPathPtr = NULL; |
| 688 |
} else { |
| 689 |
tsdPtr->cwdPathPtr = Tcl_NewStringObj(str, len); |
| 690 |
Tcl_IncrRefCount(tsdPtr->cwdPathPtr); |
| 691 |
} |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
void |
| 715 |
TclFinalizeFilesystem() |
| 716 |
{ |
| 717 |
FilesystemRecord *fsRecPtr, *tmpFsRecPtr; |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
if (cwdPathPtr != NULL) { |
| 725 |
Tcl_DecrRefCount(cwdPathPtr); |
| 726 |
cwdPathPtr = NULL; |
| 727 |
cwdPathEpoch = 0; |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
fsRecPtr = filesystemList; |
| 736 |
while (fsRecPtr != NULL) { |
| 737 |
tmpFsRecPtr = filesystemList->nextPtr; |
| 738 |
if (fsRecPtr->fileRefCount <= 0) { |
| 739 |
|
| 740 |
if (fsRecPtr != &nativeFilesystemRecord) { |
| 741 |
ckfree((char *)fsRecPtr); |
| 742 |
} |
| 743 |
} |
| 744 |
fsRecPtr = tmpFsRecPtr; |
| 745 |
} |
| 746 |
filesystemList = NULL; |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
statProcList = NULL; |
| 754 |
accessProcList = NULL; |
| 755 |
openFileChannelProcList = NULL; |
| 756 |
#ifdef __WIN32__ |
| 757 |
TclWinEncodingsCleanup(); |
| 758 |
#endif |
| 759 |
} |
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
void |
| 778 |
TclResetFilesystem() |
| 779 |
{ |
| 780 |
filesystemList = &nativeFilesystemRecord; |
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
#ifdef __WIN32__ |
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
TclWinResetInterfaces(); |
| 795 |
#endif |
| 796 |
} |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
int |
| 830 |
Tcl_FSRegister(clientData, fsPtr) |
| 831 |
ClientData clientData; |
| 832 |
Tcl_Filesystem *fsPtr; |
| 833 |
{ |
| 834 |
FilesystemRecord *newFilesystemPtr; |
| 835 |
|
| 836 |
if (fsPtr == NULL) { |
| 837 |
return TCL_ERROR; |
| 838 |
} |
| 839 |
|
| 840 |
newFilesystemPtr = (FilesystemRecord *) ckalloc(sizeof(FilesystemRecord)); |
| 841 |
|
| 842 |
newFilesystemPtr->clientData = clientData; |
| 843 |
newFilesystemPtr->fsPtr = fsPtr; |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
newFilesystemPtr->fileRefCount = 1; |
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
Tcl_MutexLock(&filesystemMutex); |
| 864 |
|
| 865 |
newFilesystemPtr->nextPtr = filesystemList; |
| 866 |
newFilesystemPtr->prevPtr = NULL; |
| 867 |
if (filesystemList) { |
| 868 |
filesystemList->prevPtr = newFilesystemPtr; |
| 869 |
} |
| 870 |
filesystemList = newFilesystemPtr; |
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
theFilesystemEpoch++; |
| 877 |
Tcl_MutexUnlock(&filesystemMutex); |
| 878 |
|
| 879 |
return TCL_OK; |
| 880 |
} |
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
int |
| 908 |
Tcl_FSUnregister(fsPtr) |
| 909 |
Tcl_Filesystem *fsPtr; |
| 910 |
{ |
| 911 |
int retVal = TCL_ERROR; |
| 912 |
FilesystemRecord *fsRecPtr; |
| 913 |
|
| 914 |
Tcl_MutexLock(&filesystemMutex); |
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
fsRecPtr = filesystemList; |
| 923 |
while ((retVal == TCL_ERROR) && (fsRecPtr != &nativeFilesystemRecord)) { |
| 924 |
if (fsRecPtr->fsPtr == fsPtr) { |
| 925 |
if (fsRecPtr->prevPtr) { |
| 926 |
fsRecPtr->prevPtr->nextPtr = fsRecPtr->nextPtr; |
| 927 |
} else { |
| 928 |
filesystemList = fsRecPtr->nextPtr; |
| 929 |
} |
| 930 |
if (fsRecPtr->nextPtr) { |
| 931 |
fsRecPtr->nextPtr->prevPtr = fsRecPtr->prevPtr; |
| 932 |
} |
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
theFilesystemEpoch++; |
| 942 |
|
| 943 |
fsRecPtr->fileRefCount--; |
| 944 |
if (fsRecPtr->fileRefCount <= 0) { |
| 945 |
ckfree((char *)fsRecPtr); |
| 946 |
} |
| 947 |
|
| 948 |
retVal = TCL_OK; |
| 949 |
} else { |
| 950 |
fsRecPtr = fsRecPtr->nextPtr; |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
Tcl_MutexUnlock(&filesystemMutex); |
| 955 |
return (retVal); |
| 956 |
} |
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
int |
| 1002 |
Tcl_FSMatchInDirectory(interp, result, pathPtr, pattern, types) |
| 1003 |
Tcl_Interp *interp; |
| 1004 |
Tcl_Obj *result; |
| 1005 |
Tcl_Obj *pathPtr; |
| 1006 |
CONST char *pattern; |
| 1007 |
Tcl_GlobTypeData *types; |
| 1008 |
|
| 1009 |
|
| 1010 |
{ |
| 1011 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 1012 |
if (fsPtr != NULL) { |
| 1013 |
Tcl_FSMatchInDirectoryProc *proc = fsPtr->matchInDirectoryProc; |
| 1014 |
if (proc != NULL) { |
| 1015 |
int ret = (*proc)(interp, result, pathPtr, pattern, types); |
| 1016 |
if (ret == TCL_OK && pattern != NULL) { |
| 1017 |
result = FsAddMountsToGlobResult(result, pathPtr, |
| 1018 |
pattern, types); |
| 1019 |
} |
| 1020 |
return ret; |
| 1021 |
} |
| 1022 |
} else { |
| 1023 |
Tcl_Obj* cwd; |
| 1024 |
int ret = -1; |
| 1025 |
if (pathPtr != NULL) { |
| 1026 |
int len; |
| 1027 |
Tcl_GetStringFromObj(pathPtr,&len); |
| 1028 |
if (len != 0) { |
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
Tcl_SetErrno(ENOENT); |
| 1034 |
return -1; |
| 1035 |
} |
| 1036 |
} |
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
cwd = Tcl_FSGetCwd(NULL); |
| 1048 |
if (cwd == NULL) { |
| 1049 |
if (interp != NULL) { |
| 1050 |
Tcl_SetResult(interp, "glob couldn't determine " |
| 1051 |
"the current working directory", TCL_STATIC); |
| 1052 |
} |
| 1053 |
return TCL_ERROR; |
| 1054 |
} |
| 1055 |
fsPtr = Tcl_FSGetFileSystemForPath(cwd); |
| 1056 |
if (fsPtr != NULL) { |
| 1057 |
Tcl_FSMatchInDirectoryProc *proc = fsPtr->matchInDirectoryProc; |
| 1058 |
if (proc != NULL) { |
| 1059 |
Tcl_Obj* tmpResultPtr = Tcl_NewListObj(0, NULL); |
| 1060 |
Tcl_IncrRefCount(tmpResultPtr); |
| 1061 |
ret = (*proc)(interp, tmpResultPtr, cwd, pattern, types); |
| 1062 |
if (ret == TCL_OK) { |
| 1063 |
int resLength; |
| 1064 |
|
| 1065 |
tmpResultPtr = FsAddMountsToGlobResult(tmpResultPtr, cwd, |
| 1066 |
pattern, types); |
| 1067 |
|
| 1068 |
ret = Tcl_ListObjLength(interp, tmpResultPtr, &resLength); |
| 1069 |
if (ret == TCL_OK) { |
| 1070 |
int i; |
| 1071 |
|
| 1072 |
for (i = 0; i < resLength; i++) { |
| 1073 |
Tcl_Obj *elt; |
| 1074 |
|
| 1075 |
Tcl_ListObjIndex(interp, tmpResultPtr, i, &elt); |
| 1076 |
Tcl_ListObjAppendElement(interp, result, |
| 1077 |
TclFSMakePathRelative(interp, elt, cwd)); |
| 1078 |
} |
| 1079 |
} |
| 1080 |
} |
| 1081 |
Tcl_DecrRefCount(tmpResultPtr); |
| 1082 |
} |
| 1083 |
} |
| 1084 |
Tcl_DecrRefCount(cwd); |
| 1085 |
return ret; |
| 1086 |
} |
| 1087 |
Tcl_SetErrno(ENOENT); |
| 1088 |
return -1; |
| 1089 |
} |
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
static Tcl_Obj* |
| 1112 |
FsAddMountsToGlobResult(result, pathPtr, pattern, types) |
| 1113 |
Tcl_Obj *result; |
| 1114 |
Tcl_Obj *pathPtr; |
| 1115 |
CONST char *pattern; |
| 1116 |
Tcl_GlobTypeData *types; |
| 1117 |
{ |
| 1118 |
int mLength, gLength, i; |
| 1119 |
int dir = (types == NULL || (types->type & TCL_GLOB_TYPE_DIR)); |
| 1120 |
Tcl_Obj *mounts = FsListMounts(pathPtr, pattern); |
| 1121 |
|
| 1122 |
if (mounts == NULL) return result; |
| 1123 |
|
| 1124 |
if (Tcl_ListObjLength(NULL, mounts, &mLength) != TCL_OK || mLength == 0) { |
| 1125 |
goto endOfMounts; |
| 1126 |
} |
| 1127 |
if (Tcl_ListObjLength(NULL, result, &gLength) != TCL_OK) { |
| 1128 |
goto endOfMounts; |
| 1129 |
} |
| 1130 |
for (i = 0; i < mLength; i++) { |
| 1131 |
Tcl_Obj *mElt; |
| 1132 |
int j; |
| 1133 |
int found = 0; |
| 1134 |
|
| 1135 |
Tcl_ListObjIndex(NULL, mounts, i, &mElt); |
| 1136 |
|
| 1137 |
for (j = 0; j < gLength; j++) { |
| 1138 |
Tcl_Obj *gElt; |
| 1139 |
Tcl_ListObjIndex(NULL, result, j, &gElt); |
| 1140 |
if (Tcl_FSEqualPaths(mElt, gElt)) { |
| 1141 |
found = 1; |
| 1142 |
if (!dir) { |
| 1143 |
|
| 1144 |
if (Tcl_IsShared(result)) { |
| 1145 |
Tcl_Obj *newList; |
| 1146 |
newList = Tcl_DuplicateObj(result); |
| 1147 |
Tcl_DecrRefCount(result); |
| 1148 |
result = newList; |
| 1149 |
} |
| 1150 |
Tcl_ListObjReplace(NULL, result, j, 1, 0, NULL); |
| 1151 |
gLength--; |
| 1152 |
} |
| 1153 |
|
| 1154 |
break; |
| 1155 |
} |
| 1156 |
} |
| 1157 |
if (!found && dir) { |
| 1158 |
if (Tcl_IsShared(result)) { |
| 1159 |
Tcl_Obj *newList; |
| 1160 |
newList = Tcl_DuplicateObj(result); |
| 1161 |
Tcl_DecrRefCount(result); |
| 1162 |
result = newList; |
| 1163 |
} |
| 1164 |
Tcl_ListObjAppendElement(NULL, result, mElt); |
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
} |
| 1171 |
} |
| 1172 |
endOfMounts: |
| 1173 |
Tcl_DecrRefCount(mounts); |
| 1174 |
return result; |
| 1175 |
} |
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
void |
| 1228 |
Tcl_FSMountsChanged(fsPtr) |
| 1229 |
Tcl_Filesystem *fsPtr; |
| 1230 |
{ |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
(void)fsPtr; |
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
Tcl_MutexLock(&filesystemMutex); |
| 1242 |
theFilesystemEpoch++; |
| 1243 |
Tcl_MutexUnlock(&filesystemMutex); |
| 1244 |
} |
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
ClientData |
| 1266 |
Tcl_FSData(fsPtr) |
| 1267 |
Tcl_Filesystem *fsPtr; |
| 1268 |
{ |
| 1269 |
ClientData retVal = NULL; |
| 1270 |
FilesystemRecord *fsRecPtr = FsGetFirstFilesystem(); |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
while ((retVal == NULL) && (fsRecPtr != NULL)) { |
| 1279 |
if (fsRecPtr->fsPtr == fsPtr) { |
| 1280 |
retVal = fsRecPtr->clientData; |
| 1281 |
} |
| 1282 |
fsRecPtr = fsRecPtr->nextPtr; |
| 1283 |
} |
| 1284 |
|
| 1285 |
return retVal; |
| 1286 |
} |
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
Tcl_Obj* |
| 1323 |
TclFSNormalizeAbsolutePath(interp, pathPtr, clientDataPtr) |
| 1324 |
Tcl_Interp* interp; |
| 1325 |
Tcl_Obj *pathPtr; |
| 1326 |
ClientData *clientDataPtr; |
| 1327 |
{ |
| 1328 |
int splen = 0, nplen, eltLen, i; |
| 1329 |
char *eltName; |
| 1330 |
Tcl_Obj *retVal; |
| 1331 |
Tcl_Obj *split; |
| 1332 |
Tcl_Obj *elt; |
| 1333 |
|
| 1334 |
|
| 1335 |
split = Tcl_FSSplitPath(pathPtr, &splen); |
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
nplen = 0; |
| 1343 |
for (i = 0; i < splen; i++) { |
| 1344 |
Tcl_ListObjIndex(NULL, split, nplen, &elt); |
| 1345 |
eltName = Tcl_GetStringFromObj(elt, &eltLen); |
| 1346 |
|
| 1347 |
if ((eltLen == 1) && (eltName[0] == '.')) { |
| 1348 |
Tcl_ListObjReplace(NULL, split, nplen, 1, 0, NULL); |
| 1349 |
} else if ((eltLen == 2) |
| 1350 |
&& (eltName[0] == '.') && (eltName[1] == '.')) { |
| 1351 |
if (nplen > 1) { |
| 1352 |
nplen--; |
| 1353 |
Tcl_ListObjReplace(NULL, split, nplen, 2, 0, NULL); |
| 1354 |
} else { |
| 1355 |
Tcl_ListObjReplace(NULL, split, nplen, 1, 0, NULL); |
| 1356 |
} |
| 1357 |
} else { |
| 1358 |
nplen++; |
| 1359 |
} |
| 1360 |
} |
| 1361 |
if (nplen > 0) { |
| 1362 |
ClientData clientData = NULL; |
| 1363 |
|
| 1364 |
retVal = Tcl_FSJoinPath(split, nplen); |
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
Tcl_IncrRefCount(retVal); |
| 1377 |
TclFSNormalizeToUniquePath(interp, retVal, 0, &clientData); |
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
TclFSMakePathFromNormalized(interp, retVal, clientData); |
| 1384 |
if (clientDataPtr != NULL) { |
| 1385 |
*clientDataPtr = clientData; |
| 1386 |
} |
| 1387 |
} else { |
| 1388 |
|
| 1389 |
retVal = Tcl_NewStringObj("",0); |
| 1390 |
Tcl_IncrRefCount(retVal); |
| 1391 |
} |
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
Tcl_IncrRefCount(split); |
| 1402 |
Tcl_DecrRefCount(split); |
| 1403 |
|
| 1404 |
|
| 1405 |
return retVal; |
| 1406 |
} |
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
int |
| 1442 |
TclFSNormalizeToUniquePath(interp, pathPtr, startAt, clientDataPtr) |
| 1443 |
Tcl_Interp *interp; |
| 1444 |
Tcl_Obj *pathPtr; |
| 1445 |
int startAt; |
| 1446 |
ClientData *clientDataPtr; |
| 1447 |
{ |
| 1448 |
FilesystemRecord *fsRecPtr, *firstFsRecPtr; |
| 1449 |
|
| 1450 |
(void)clientDataPtr; |
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
firstFsRecPtr = FsGetFirstFilesystem(); |
| 1460 |
|
| 1461 |
fsRecPtr = firstFsRecPtr; |
| 1462 |
while (fsRecPtr != NULL) { |
| 1463 |
if (fsRecPtr == &nativeFilesystemRecord) { |
| 1464 |
Tcl_FSNormalizePathProc *proc = fsRecPtr->fsPtr->normalizePathProc; |
| 1465 |
if (proc != NULL) { |
| 1466 |
startAt = (*proc)(interp, pathPtr, startAt); |
| 1467 |
} |
| 1468 |
break; |
| 1469 |
} |
| 1470 |
fsRecPtr = fsRecPtr->nextPtr; |
| 1471 |
} |
| 1472 |
|
| 1473 |
fsRecPtr = firstFsRecPtr; |
| 1474 |
while (fsRecPtr != NULL) { |
| 1475 |
|
| 1476 |
if (fsRecPtr != &nativeFilesystemRecord) { |
| 1477 |
Tcl_FSNormalizePathProc *proc = fsRecPtr->fsPtr->normalizePathProc; |
| 1478 |
if (proc != NULL) { |
| 1479 |
startAt = (*proc)(interp, pathPtr, startAt); |
| 1480 |
} |
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
} |
| 1489 |
fsRecPtr = fsRecPtr->nextPtr; |
| 1490 |
} |
| 1491 |
|
| 1492 |
return startAt; |
| 1493 |
} |
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
int |
| 1522 |
TclGetOpenMode(interp, string, seekFlagPtr) |
| 1523 |
Tcl_Interp *interp; |
| 1524 |
|
| 1525 |
CONST char *string; |
| 1526 |
|
| 1527 |
int *seekFlagPtr; |
| 1528 |
|
| 1529 |
|
| 1530 |
{ |
| 1531 |
int mode, modeArgc, c, i, gotRW; |
| 1532 |
CONST char **modeArgv, *flag; |
| 1533 |
#define RW_MODES (O_RDONLY|O_WRONLY|O_RDWR) |
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
*seekFlagPtr = 0; |
| 1542 |
mode = 0; |
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
if (!(string[0] & 0x80) |
| 1550 |
&& islower(UCHAR(string[0]))) { |
| 1551 |
switch (string[0]) { |
| 1552 |
case 'r': |
| 1553 |
mode = O_RDONLY; |
| 1554 |
break; |
| 1555 |
case 'w': |
| 1556 |
mode = O_WRONLY|O_CREAT|O_TRUNC; |
| 1557 |
break; |
| 1558 |
case 'a': |
| 1559 |
mode = O_WRONLY|O_CREAT; |
| 1560 |
*seekFlagPtr = 1; |
| 1561 |
break; |
| 1562 |
default: |
| 1563 |
error: |
| 1564 |
if (interp != (Tcl_Interp *) NULL) { |
| 1565 |
Tcl_AppendResult(interp, |
| 1566 |
"illegal access mode \"", string, "\"", |
| 1567 |
(char *) NULL); |
| 1568 |
} |
| 1569 |
return -1; |
| 1570 |
} |
| 1571 |
if (string[1] == '+') { |
| 1572 |
mode &= ~(O_RDONLY|O_WRONLY); |
| 1573 |
mode |= O_RDWR; |
| 1574 |
if (string[2] != 0) { |
| 1575 |
goto error; |
| 1576 |
} |
| 1577 |
} else if (string[1] != 0) { |
| 1578 |
goto error; |
| 1579 |
} |
| 1580 |
return mode; |
| 1581 |
} |
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
if (Tcl_SplitList(interp, string, &modeArgc, &modeArgv) != TCL_OK) { |
| 1592 |
if (interp != (Tcl_Interp *) NULL) { |
| 1593 |
Tcl_AddErrorInfo(interp, |
| 1594 |
"\n while processing open access modes \""); |
| 1595 |
Tcl_AddErrorInfo(interp, string); |
| 1596 |
Tcl_AddErrorInfo(interp, "\""); |
| 1597 |
} |
| 1598 |
return -1; |
| 1599 |
} |
| 1600 |
|
| 1601 |
gotRW = 0; |
| 1602 |
for (i = 0; i < modeArgc; i++) { |
| 1603 |
flag = modeArgv[i]; |
| 1604 |
c = flag[0]; |
| 1605 |
if ((c == 'R') && (strcmp(flag, "RDONLY") == 0)) { |
| 1606 |
mode = (mode & ~RW_MODES) | O_RDONLY; |
| 1607 |
gotRW = 1; |
| 1608 |
} else if ((c == 'W') && (strcmp(flag, "WRONLY") == 0)) { |
| 1609 |
mode = (mode & ~RW_MODES) | O_WRONLY; |
| 1610 |
gotRW = 1; |
| 1611 |
} else if ((c == 'R') && (strcmp(flag, "RDWR") == 0)) { |
| 1612 |
mode = (mode & ~RW_MODES) | O_RDWR; |
| 1613 |
gotRW = 1; |
| 1614 |
} else if ((c == 'A') && (strcmp(flag, "APPEND") == 0)) { |
| 1615 |
mode |= O_APPEND; |
| 1616 |
*seekFlagPtr = 1; |
| 1617 |
} else if ((c == 'C') && (strcmp(flag, "CREAT") == 0)) { |
| 1618 |
mode |= O_CREAT; |
| 1619 |
} else if ((c == 'E') && (strcmp(flag, "EXCL") == 0)) { |
| 1620 |
mode |= O_EXCL; |
| 1621 |
} else if ((c == 'N') && (strcmp(flag, "NOCTTY") == 0)) { |
| 1622 |
#ifdef O_NOCTTY |
| 1623 |
mode |= O_NOCTTY; |
| 1624 |
#else |
| 1625 |
if (interp != (Tcl_Interp *) NULL) { |
| 1626 |
Tcl_AppendResult(interp, "access mode \"", flag, |
| 1627 |
"\" not supported by this system", (char *) NULL); |
| 1628 |
} |
| 1629 |
ckfree((char *) modeArgv); |
| 1630 |
return -1; |
| 1631 |
#endif |
| 1632 |
} else if ((c == 'N') && (strcmp(flag, "NONBLOCK") == 0)) { |
| 1633 |
#if defined(O_NDELAY) || defined(O_NONBLOCK) |
| 1634 |
# ifdef O_NONBLOCK |
| 1635 |
mode |= O_NONBLOCK; |
| 1636 |
# else |
| 1637 |
mode |= O_NDELAY; |
| 1638 |
# endif |
| 1639 |
#else |
| 1640 |
if (interp != (Tcl_Interp *) NULL) { |
| 1641 |
Tcl_AppendResult(interp, "access mode \"", flag, |
| 1642 |
"\" not supported by this system", (char *) NULL); |
| 1643 |
} |
| 1644 |
ckfree((char *) modeArgv); |
| 1645 |
return -1; |
| 1646 |
#endif |
| 1647 |
} else if ((c == 'T') && (strcmp(flag, "TRUNC") == 0)) { |
| 1648 |
mode |= O_TRUNC; |
| 1649 |
} else { |
| 1650 |
if (interp != (Tcl_Interp *) NULL) { |
| 1651 |
Tcl_AppendResult(interp, "invalid access mode \"", flag, |
| 1652 |
"\": must be RDONLY, WRONLY, RDWR, APPEND, CREAT", |
| 1653 |
" EXCL, NOCTTY, NONBLOCK, or TRUNC", (char *) NULL); |
| 1654 |
} |
| 1655 |
ckfree((char *) modeArgv); |
| 1656 |
return -1; |
| 1657 |
} |
| 1658 |
} |
| 1659 |
ckfree((char *) modeArgv); |
| 1660 |
if (!gotRW) { |
| 1661 |
if (interp != (Tcl_Interp *) NULL) { |
| 1662 |
Tcl_AppendResult(interp, "access mode must include either", |
| 1663 |
" RDONLY, WRONLY, or RDWR", (char *) NULL); |
| 1664 |
} |
| 1665 |
return -1; |
| 1666 |
} |
| 1667 |
return mode; |
| 1668 |
} |
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
int |
| 1692 |
Tcl_FSEvalFile(interp, pathPtr) |
| 1693 |
Tcl_Interp *interp; |
| 1694 |
Tcl_Obj *pathPtr; |
| 1695 |
|
| 1696 |
{ |
| 1697 |
int result, length; |
| 1698 |
Tcl_StatBuf statBuf; |
| 1699 |
Tcl_Obj *oldScriptFile; |
| 1700 |
Interp *iPtr; |
| 1701 |
char *string; |
| 1702 |
Tcl_Channel chan; |
| 1703 |
Tcl_Obj *objPtr; |
| 1704 |
|
| 1705 |
if (Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL) { |
| 1706 |
return TCL_ERROR; |
| 1707 |
} |
| 1708 |
|
| 1709 |
result = TCL_ERROR; |
| 1710 |
objPtr = Tcl_NewObj(); |
| 1711 |
|
| 1712 |
if (Tcl_FSStat(pathPtr, &statBuf) == -1) { |
| 1713 |
Tcl_SetErrno(errno); |
| 1714 |
Tcl_AppendResult(interp, "couldn't read file \"", |
| 1715 |
Tcl_GetString(pathPtr), |
| 1716 |
"\": ", Tcl_PosixError(interp), (char *) NULL); |
| 1717 |
goto end; |
| 1718 |
} |
| 1719 |
chan = Tcl_FSOpenFileChannel(interp, pathPtr, "r", 0644); |
| 1720 |
if (chan == (Tcl_Channel) NULL) { |
| 1721 |
Tcl_ResetResult(interp); |
| 1722 |
Tcl_AppendResult(interp, "couldn't read file \"", |
| 1723 |
Tcl_GetString(pathPtr), |
| 1724 |
"\": ", Tcl_PosixError(interp), (char *) NULL); |
| 1725 |
goto end; |
| 1726 |
} |
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
Tcl_SetChannelOption(interp, chan, "-eofchar", "\32"); |
| 1733 |
if (Tcl_ReadChars(chan, objPtr, -1, 0) < 0) { |
| 1734 |
Tcl_Close(interp, chan); |
| 1735 |
Tcl_AppendResult(interp, "couldn't read file \"", |
| 1736 |
Tcl_GetString(pathPtr), |
| 1737 |
"\": ", Tcl_PosixError(interp), (char *) NULL); |
| 1738 |
goto end; |
| 1739 |
} |
| 1740 |
if (Tcl_Close(interp, chan) != TCL_OK) { |
| 1741 |
goto end; |
| 1742 |
} |
| 1743 |
|
| 1744 |
iPtr = (Interp *) interp; |
| 1745 |
oldScriptFile = iPtr->scriptFile; |
| 1746 |
iPtr->scriptFile = pathPtr; |
| 1747 |
Tcl_IncrRefCount(iPtr->scriptFile); |
| 1748 |
string = Tcl_GetStringFromObj(objPtr, &length); |
| 1749 |
result = Tcl_EvalEx(interp, string, length, 0); |
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
if (iPtr->scriptFile != NULL) { |
| 1756 |
Tcl_DecrRefCount(iPtr->scriptFile); |
| 1757 |
} |
| 1758 |
iPtr->scriptFile = oldScriptFile; |
| 1759 |
|
| 1760 |
if (result == TCL_RETURN) { |
| 1761 |
result = TclUpdateReturnInfo(iPtr); |
| 1762 |
} else if (result == TCL_ERROR) { |
| 1763 |
char msg[200 + TCL_INTEGER_SPACE]; |
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
sprintf(msg, "\n (file \"%.150s\" line %d)", Tcl_GetString(pathPtr), |
| 1770 |
interp->errorLine); |
| 1771 |
Tcl_AddErrorInfo(interp, msg); |
| 1772 |
} |
| 1773 |
|
| 1774 |
end: |
| 1775 |
Tcl_DecrRefCount(objPtr); |
| 1776 |
return result; |
| 1777 |
} |
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
int |
| 1799 |
Tcl_GetErrno() |
| 1800 |
{ |
| 1801 |
return errno; |
| 1802 |
} |
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
void |
| 1821 |
Tcl_SetErrno(err) |
| 1822 |
int err; |
| 1823 |
{ |
| 1824 |
errno = err; |
| 1825 |
} |
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
CONST char * |
| 1848 |
Tcl_PosixError(interp) |
| 1849 |
Tcl_Interp *interp; |
| 1850 |
|
| 1851 |
{ |
| 1852 |
CONST char *id, *msg; |
| 1853 |
|
| 1854 |
msg = Tcl_ErrnoMsg(errno); |
| 1855 |
id = Tcl_ErrnoId(); |
| 1856 |
Tcl_SetErrorCode(interp, "POSIX", id, msg, (char *) NULL); |
| 1857 |
return msg; |
| 1858 |
} |
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
int |
| 1880 |
Tcl_FSStat(pathPtr, buf) |
| 1881 |
Tcl_Obj *pathPtr; |
| 1882 |
Tcl_StatBuf *buf; |
| 1883 |
{ |
| 1884 |
Tcl_Filesystem *fsPtr; |
| 1885 |
#ifdef USE_OBSOLETE_FS_HOOKS |
| 1886 |
struct stat oldStyleStatBuffer; |
| 1887 |
int retVal = -1; |
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
Tcl_MutexLock(&obsoleteFsHookMutex); |
| 1895 |
|
| 1896 |
if (statProcList != NULL) { |
| 1897 |
StatProc *statProcPtr; |
| 1898 |
char *path; |
| 1899 |
Tcl_Obj *transPtr = Tcl_FSGetTranslatedPath(NULL, pathPtr); |
| 1900 |
if (transPtr == NULL) { |
| 1901 |
path = NULL; |
| 1902 |
} else { |
| 1903 |
path = Tcl_GetString(transPtr); |
| 1904 |
} |
| 1905 |
|
| 1906 |
statProcPtr = statProcList; |
| 1907 |
while ((retVal == -1) && (statProcPtr != NULL)) { |
| 1908 |
retVal = (*statProcPtr->proc)(path, &oldStyleStatBuffer); |
| 1909 |
statProcPtr = statProcPtr->nextPtr; |
| 1910 |
} |
| 1911 |
if (transPtr != NULL) { |
| 1912 |
Tcl_DecrRefCount(transPtr); |
| 1913 |
} |
| 1914 |
} |
| 1915 |
|
| 1916 |
Tcl_MutexUnlock(&obsoleteFsHookMutex); |
| 1917 |
if (retVal != -1) { |
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
buf->st_mode = oldStyleStatBuffer.st_mode; |
| 1923 |
buf->st_ino = oldStyleStatBuffer.st_ino; |
| 1924 |
buf->st_dev = oldStyleStatBuffer.st_dev; |
| 1925 |
buf->st_rdev = oldStyleStatBuffer.st_rdev; |
| 1926 |
buf->st_nlink = oldStyleStatBuffer.st_nlink; |
| 1927 |
buf->st_uid = oldStyleStatBuffer.st_uid; |
| 1928 |
buf->st_gid = oldStyleStatBuffer.st_gid; |
| 1929 |
buf->st_size = Tcl_LongAsWide(oldStyleStatBuffer.st_size); |
| 1930 |
buf->st_atime = oldStyleStatBuffer.st_atime; |
| 1931 |
buf->st_mtime = oldStyleStatBuffer.st_mtime; |
| 1932 |
buf->st_ctime = oldStyleStatBuffer.st_ctime; |
| 1933 |
#ifdef HAVE_ST_BLOCKS |
| 1934 |
buf->st_blksize = oldStyleStatBuffer.st_blksize; |
| 1935 |
buf->st_blocks = Tcl_LongAsWide(oldStyleStatBuffer.st_blocks); |
| 1936 |
#endif |
| 1937 |
return retVal; |
| 1938 |
} |
| 1939 |
#endif |
| 1940 |
fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 1941 |
if (fsPtr != NULL) { |
| 1942 |
Tcl_FSStatProc *proc = fsPtr->statProc; |
| 1943 |
if (proc != NULL) { |
| 1944 |
return (*proc)(pathPtr, buf); |
| 1945 |
} |
| 1946 |
} |
| 1947 |
Tcl_SetErrno(ENOENT); |
| 1948 |
return -1; |
| 1949 |
} |
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
int |
| 1972 |
Tcl_FSLstat(pathPtr, buf) |
| 1973 |
Tcl_Obj *pathPtr; |
| 1974 |
Tcl_StatBuf *buf; |
| 1975 |
{ |
| 1976 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 1977 |
if (fsPtr != NULL) { |
| 1978 |
Tcl_FSLstatProc *proc = fsPtr->lstatProc; |
| 1979 |
if (proc != NULL) { |
| 1980 |
return (*proc)(pathPtr, buf); |
| 1981 |
} else { |
| 1982 |
Tcl_FSStatProc *sproc = fsPtr->statProc; |
| 1983 |
if (sproc != NULL) { |
| 1984 |
return (*sproc)(pathPtr, buf); |
| 1985 |
} |
| 1986 |
} |
| 1987 |
} |
| 1988 |
Tcl_SetErrno(ENOENT); |
| 1989 |
return -1; |
| 1990 |
} |
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
int |
| 2011 |
Tcl_FSAccess(pathPtr, mode) |
| 2012 |
Tcl_Obj *pathPtr; |
| 2013 |
int mode; |
| 2014 |
{ |
| 2015 |
Tcl_Filesystem *fsPtr; |
| 2016 |
#ifdef USE_OBSOLETE_FS_HOOKS |
| 2017 |
int retVal = -1; |
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
Tcl_MutexLock(&obsoleteFsHookMutex); |
| 2025 |
|
| 2026 |
if (accessProcList != NULL) { |
| 2027 |
AccessProc *accessProcPtr; |
| 2028 |
char *path; |
| 2029 |
Tcl_Obj *transPtr = Tcl_FSGetTranslatedPath(NULL, pathPtr); |
| 2030 |
if (transPtr == NULL) { |
| 2031 |
path = NULL; |
| 2032 |
} else { |
| 2033 |
path = Tcl_GetString(transPtr); |
| 2034 |
} |
| 2035 |
|
| 2036 |
accessProcPtr = accessProcList; |
| 2037 |
while ((retVal == -1) && (accessProcPtr != NULL)) { |
| 2038 |
retVal = (*accessProcPtr->proc)(path, mode); |
| 2039 |
accessProcPtr = accessProcPtr->nextPtr; |
| 2040 |
} |
| 2041 |
if (transPtr != NULL) { |
| 2042 |
Tcl_DecrRefCount(transPtr); |
| 2043 |
} |
| 2044 |
} |
| 2045 |
|
| 2046 |
Tcl_MutexUnlock(&obsoleteFsHookMutex); |
| 2047 |
if (retVal != -1) { |
| 2048 |
return retVal; |
| 2049 |
} |
| 2050 |
#endif |
| 2051 |
fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 2052 |
if (fsPtr != NULL) { |
| 2053 |
Tcl_FSAccessProc *proc = fsPtr->accessProc; |
| 2054 |
if (proc != NULL) { |
| 2055 |
return (*proc)(pathPtr, mode); |
| 2056 |
} |
| 2057 |
} |
| 2058 |
|
| 2059 |
Tcl_SetErrno(ENOENT); |
| 2060 |
return -1; |
| 2061 |
} |
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
Tcl_Channel |
| 2082 |
Tcl_FSOpenFileChannel(interp, pathPtr, modeString, permissions) |
| 2083 |
Tcl_Interp *interp; |
| 2084 |
|
| 2085 |
Tcl_Obj *pathPtr; |
| 2086 |
CONST char *modeString; |
| 2087 |
|
| 2088 |
int permissions; |
| 2089 |
|
| 2090 |
|
| 2091 |
{ |
| 2092 |
Tcl_Filesystem *fsPtr; |
| 2093 |
#ifdef USE_OBSOLETE_FS_HOOKS |
| 2094 |
Tcl_Channel retVal = NULL; |
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
Tcl_MutexLock(&obsoleteFsHookMutex); |
| 2103 |
if (openFileChannelProcList != NULL) { |
| 2104 |
OpenFileChannelProc *openFileChannelProcPtr; |
| 2105 |
char *path; |
| 2106 |
Tcl_Obj *transPtr = Tcl_FSGetTranslatedPath(interp, pathPtr); |
| 2107 |
|
| 2108 |
if (transPtr == NULL) { |
| 2109 |
path = NULL; |
| 2110 |
} else { |
| 2111 |
path = Tcl_GetString(transPtr); |
| 2112 |
} |
| 2113 |
|
| 2114 |
openFileChannelProcPtr = openFileChannelProcList; |
| 2115 |
|
| 2116 |
while ((retVal == NULL) && (openFileChannelProcPtr != NULL)) { |
| 2117 |
retVal = (*openFileChannelProcPtr->proc)(interp, path, |
| 2118 |
modeString, permissions); |
| 2119 |
openFileChannelProcPtr = openFileChannelProcPtr->nextPtr; |
| 2120 |
} |
| 2121 |
if (transPtr != NULL) { |
| 2122 |
Tcl_DecrRefCount(transPtr); |
| 2123 |
} |
| 2124 |
} |
| 2125 |
Tcl_MutexUnlock(&obsoleteFsHookMutex); |
| 2126 |
if (retVal != NULL) { |
| 2127 |
return retVal; |
| 2128 |
} |
| 2129 |
#endif |
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
if (Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL) { |
| 2136 |
return NULL; |
| 2137 |
} |
| 2138 |
|
| 2139 |
fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 2140 |
if (fsPtr != NULL) { |
| 2141 |
Tcl_FSOpenFileChannelProc *proc = fsPtr->openFileChannelProc; |
| 2142 |
if (proc != NULL) { |
| 2143 |
int mode, seekFlag; |
| 2144 |
mode = TclGetOpenMode(interp, modeString, &seekFlag); |
| 2145 |
if (mode == -1) { |
| 2146 |
return NULL; |
| 2147 |
} |
| 2148 |
retVal = (*proc)(interp, pathPtr, mode, permissions); |
| 2149 |
if (retVal != NULL) { |
| 2150 |
if (seekFlag) { |
| 2151 |
if (Tcl_Seek(retVal, (Tcl_WideInt)0, |
| 2152 |
SEEK_END) < (Tcl_WideInt)0) { |
| 2153 |
if (interp != (Tcl_Interp *) NULL) { |
| 2154 |
Tcl_AppendResult(interp, |
| 2155 |
"could not seek to end of file while opening \"", |
| 2156 |
Tcl_GetString(pathPtr), "\": ", |
| 2157 |
Tcl_PosixError(interp), (char *) NULL); |
| 2158 |
} |
| 2159 |
Tcl_Close(NULL, retVal); |
| 2160 |
return NULL; |
| 2161 |
} |
| 2162 |
} |
| 2163 |
} |
| 2164 |
return retVal; |
| 2165 |
} |
| 2166 |
} |
| 2167 |
|
| 2168 |
Tcl_SetErrno(ENOENT); |
| 2169 |
if (interp != NULL) { |
| 2170 |
Tcl_AppendResult(interp, "couldn't open \"", |
| 2171 |
Tcl_GetString(pathPtr), "\": ", |
| 2172 |
Tcl_PosixError(interp), (char *) NULL); |
| 2173 |
} |
| 2174 |
return NULL; |
| 2175 |
} |
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
int |
| 2196 |
Tcl_FSUtime (pathPtr, tval) |
| 2197 |
Tcl_Obj *pathPtr; |
| 2198 |
struct utimbuf *tval; |
| 2199 |
|
| 2200 |
{ |
| 2201 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 2202 |
if (fsPtr != NULL) { |
| 2203 |
Tcl_FSUtimeProc *proc = fsPtr->utimeProc; |
| 2204 |
if (proc != NULL) { |
| 2205 |
return (*proc)(pathPtr, tval); |
| 2206 |
} |
| 2207 |
} |
| 2208 |
return -1; |
| 2209 |
} |
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
|
| 2229 |
|
| 2230 |
|
| 2231 |
static CONST char** |
| 2232 |
NativeFileAttrStrings(pathPtr, objPtrRef) |
| 2233 |
Tcl_Obj *pathPtr; |
| 2234 |
Tcl_Obj** objPtrRef; |
| 2235 |
{ |
| 2236 |
return tclpFileAttrStrings; |
| 2237 |
} |
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
|
| 2256 |
|
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
static int |
| 2264 |
NativeFileAttrsGet(interp, index, pathPtr, objPtrRef) |
| 2265 |
Tcl_Interp *interp; |
| 2266 |
int index; |
| 2267 |
Tcl_Obj *pathPtr; |
| 2268 |
Tcl_Obj **objPtrRef; |
| 2269 |
{ |
| 2270 |
return (*tclpFileAttrProcs[index].getProc)(interp, index, |
| 2271 |
pathPtr, objPtrRef); |
| 2272 |
} |
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
static int |
| 2295 |
NativeFileAttrsSet(interp, index, pathPtr, objPtr) |
| 2296 |
Tcl_Interp *interp; |
| 2297 |
int index; |
| 2298 |
Tcl_Obj *pathPtr; |
| 2299 |
Tcl_Obj *objPtr; |
| 2300 |
{ |
| 2301 |
return (*tclpFileAttrProcs[index].setProc)(interp, index, |
| 2302 |
pathPtr, objPtr); |
| 2303 |
} |
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
|
| 2329 |
|
| 2330 |
CONST char ** |
| 2331 |
Tcl_FSFileAttrStrings(pathPtr, objPtrRef) |
| 2332 |
Tcl_Obj* pathPtr; |
| 2333 |
Tcl_Obj** objPtrRef; |
| 2334 |
{ |
| 2335 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 2336 |
if (fsPtr != NULL) { |
| 2337 |
Tcl_FSFileAttrStringsProc *proc = fsPtr->fileAttrStringsProc; |
| 2338 |
if (proc != NULL) { |
| 2339 |
return (*proc)(pathPtr, objPtrRef); |
| 2340 |
} |
| 2341 |
} |
| 2342 |
Tcl_SetErrno(ENOENT); |
| 2343 |
return NULL; |
| 2344 |
} |
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
int |
| 2370 |
Tcl_FSFileAttrsGet(interp, index, pathPtr, objPtrRef) |
| 2371 |
Tcl_Interp *interp; |
| 2372 |
int index; |
| 2373 |
Tcl_Obj *pathPtr; |
| 2374 |
Tcl_Obj **objPtrRef; |
| 2375 |
{ |
| 2376 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 2377 |
if (fsPtr != NULL) { |
| 2378 |
Tcl_FSFileAttrsGetProc *proc = fsPtr->fileAttrsGetProc; |
| 2379 |
if (proc != NULL) { |
| 2380 |
return (*proc)(interp, index, pathPtr, objPtrRef); |
| 2381 |
} |
| 2382 |
} |
| 2383 |
Tcl_SetErrno(ENOENT); |
| 2384 |
return -1; |
| 2385 |
} |
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
int |
| 2406 |
Tcl_FSFileAttrsSet(interp, index, pathPtr, objPtr) |
| 2407 |
Tcl_Interp *interp; |
| 2408 |
int index; |
| 2409 |
Tcl_Obj *pathPtr; |
| 2410 |
Tcl_Obj *objPtr; |
| 2411 |
{ |
| 2412 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 2413 |
if (fsPtr != NULL) { |
| 2414 |
Tcl_FSFileAttrsSetProc *proc = fsPtr->fileAttrsSetProc; |
| 2415 |
if (proc != NULL) { |
| 2416 |
return (*proc)(interp, index, pathPtr, objPtr); |
| 2417 |
} |
| 2418 |
} |
| 2419 |
Tcl_SetErrno(ENOENT); |
| 2420 |
return -1; |
| 2421 |
} |
| 2422 |
|
| 2423 |
|
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
|
| 2464 |
Tcl_Obj* |
| 2465 |
Tcl_FSGetCwd(interp) |
| 2466 |
Tcl_Interp *interp; |
| 2467 |
{ |
| 2468 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 2469 |
|
| 2470 |
if (TclFSCwdPointerEquals(NULL)) { |
| 2471 |
FilesystemRecord *fsRecPtr; |
| 2472 |
Tcl_Obj *retVal = NULL; |
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
fsRecPtr = FsGetFirstFilesystem(); |
| 2482 |
while ((retVal == NULL) && (fsRecPtr != NULL)) { |
| 2483 |
Tcl_FSGetCwdProc *proc = fsRecPtr->fsPtr->getCwdProc; |
| 2484 |
if (proc != NULL) { |
| 2485 |
retVal = (*proc)(interp); |
| 2486 |
} |
| 2487 |
fsRecPtr = fsRecPtr->nextPtr; |
| 2488 |
} |
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
if (retVal != NULL) { |
| 2498 |
Tcl_Obj *norm = TclFSNormalizeAbsolutePath(interp, retVal, NULL); |
| 2499 |
if (norm != NULL) { |
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
FsUpdateCwd(norm); |
| 2513 |
} |
| 2514 |
Tcl_DecrRefCount(retVal); |
| 2515 |
} |
| 2516 |
} else { |
| 2517 |
|
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(tsdPtr->cwdPathPtr); |
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
if (fsPtr != NULL) { |
| 2535 |
Tcl_FSGetCwdProc *proc = fsPtr->getCwdProc; |
| 2536 |
if (proc != NULL) { |
| 2537 |
Tcl_Obj *retVal = (*proc)(interp); |
| 2538 |
if (retVal != NULL) { |
| 2539 |
Tcl_Obj *norm = TclFSNormalizeAbsolutePath(interp, retVal, NULL); |
| 2540 |
|
| 2541 |
|
| 2542 |
|
| 2543 |
|
| 2544 |
|
| 2545 |
if (norm == NULL) { |
| 2546 |
|
| 2547 |
} else if (Tcl_FSEqualPaths(tsdPtr->cwdPathPtr, norm)) { |
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
Tcl_DecrRefCount(norm); |
| 2556 |
} else { |
| 2557 |
FsUpdateCwd(norm); |
| 2558 |
} |
| 2559 |
Tcl_DecrRefCount(retVal); |
| 2560 |
} else { |
| 2561 |
|
| 2562 |
FsUpdateCwd(NULL); |
| 2563 |
} |
| 2564 |
} |
| 2565 |
} |
| 2566 |
} |
| 2567 |
|
| 2568 |
if (tsdPtr->cwdPathPtr != NULL) { |
| 2569 |
Tcl_IncrRefCount(tsdPtr->cwdPathPtr); |
| 2570 |
} |
| 2571 |
|
| 2572 |
return tsdPtr->cwdPathPtr; |
| 2573 |
} |
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
int |
| 2597 |
Tcl_FSChdir(pathPtr) |
| 2598 |
Tcl_Obj *pathPtr; |
| 2599 |
{ |
| 2600 |
Tcl_Filesystem *fsPtr; |
| 2601 |
int retVal = -1; |
| 2602 |
|
| 2603 |
if (Tcl_FSGetNormalizedPath(NULL, pathPtr) == NULL) { |
| 2604 |
return TCL_ERROR; |
| 2605 |
} |
| 2606 |
|
| 2607 |
fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 2608 |
if (fsPtr != NULL) { |
| 2609 |
Tcl_FSChdirProc *proc = fsPtr->chdirProc; |
| 2610 |
if (proc != NULL) { |
| 2611 |
retVal = (*proc)(pathPtr); |
| 2612 |
} else { |
| 2613 |
|
| 2614 |
Tcl_StatBuf buf; |
| 2615 |
|
| 2616 |
|
| 2617 |
if ((Tcl_FSStat(pathPtr, &buf) == 0) |
| 2618 |
&& (S_ISDIR(buf.st_mode)) |
| 2619 |
&& (Tcl_FSAccess(pathPtr, R_OK) == 0)) { |
| 2620 |
|
| 2621 |
retVal = 0; |
| 2622 |
} |
| 2623 |
} |
| 2624 |
} |
| 2625 |
|
| 2626 |
if (retVal != -1) { |
| 2627 |
|
| 2628 |
|
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
|
| 2635 |
if (retVal == TCL_OK) { |
| 2636 |
|
| 2637 |
|
| 2638 |
|
| 2639 |
|
| 2640 |
|
| 2641 |
|
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
Tcl_Obj *normDirName = Tcl_FSGetNormalizedPath(NULL, pathPtr); |
| 2646 |
if (normDirName == NULL) { |
| 2647 |
return TCL_ERROR; |
| 2648 |
} |
| 2649 |
FsUpdateCwd(normDirName); |
| 2650 |
} |
| 2651 |
} else { |
| 2652 |
Tcl_SetErrno(ENOENT); |
| 2653 |
} |
| 2654 |
|
| 2655 |
return (retVal); |
| 2656 |
} |
| 2657 |
|
| 2658 |
|
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
|
| 2665 |
|
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
|
| 2679 |
|
| 2680 |
|
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
|
| 2687 |
int |
| 2688 |
Tcl_FSLoadFile(interp, pathPtr, sym1, sym2, proc1Ptr, proc2Ptr, |
| 2689 |
handlePtr, unloadProcPtr) |
| 2690 |
Tcl_Interp *interp; |
| 2691 |
Tcl_Obj *pathPtr; |
| 2692 |
|
| 2693 |
CONST char *sym1, *sym2; |
| 2694 |
|
| 2695 |
Tcl_PackageInitProc **proc1Ptr, **proc2Ptr; |
| 2696 |
|
| 2697 |
|
| 2698 |
Tcl_LoadHandle *handlePtr; |
| 2699 |
|
| 2700 |
|
| 2701 |
Tcl_FSUnloadFileProc **unloadProcPtr; |
| 2702 |
|
| 2703 |
|
| 2704 |
|
| 2705 |
{ |
| 2706 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 2707 |
if (fsPtr != NULL) { |
| 2708 |
Tcl_FSLoadFileProc *proc = fsPtr->loadFileProc; |
| 2709 |
if (proc != NULL) { |
| 2710 |
int retVal = (*proc)(interp, pathPtr, handlePtr, unloadProcPtr); |
| 2711 |
if (retVal != TCL_OK) { |
| 2712 |
return retVal; |
| 2713 |
} |
| 2714 |
if (*handlePtr == NULL) { |
| 2715 |
return TCL_ERROR; |
| 2716 |
} |
| 2717 |
if (sym1 != NULL) { |
| 2718 |
*proc1Ptr = TclpFindSymbol(interp, *handlePtr, sym1); |
| 2719 |
} |
| 2720 |
if (sym2 != NULL) { |
| 2721 |
*proc2Ptr = TclpFindSymbol(interp, *handlePtr, sym2); |
| 2722 |
} |
| 2723 |
return retVal; |
| 2724 |
} else { |
| 2725 |
Tcl_Filesystem *copyFsPtr; |
| 2726 |
Tcl_Obj *copyToPtr; |
| 2727 |
|
| 2728 |
|
| 2729 |
if (Tcl_FSAccess(pathPtr, R_OK) != 0) { |
| 2730 |
Tcl_AppendResult(interp, "couldn't load library \"", |
| 2731 |
Tcl_GetString(pathPtr), "\": ", |
| 2732 |
Tcl_PosixError(interp), (char *) NULL); |
| 2733 |
return TCL_ERROR; |
| 2734 |
} |
| 2735 |
|
| 2736 |
|
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
copyToPtr = TclpTempFileName(); |
| 2741 |
if (copyToPtr == NULL) { |
| 2742 |
return -1; |
| 2743 |
} |
| 2744 |
Tcl_IncrRefCount(copyToPtr); |
| 2745 |
|
| 2746 |
copyFsPtr = Tcl_FSGetFileSystemForPath(copyToPtr); |
| 2747 |
if ((copyFsPtr == NULL) || (copyFsPtr == fsPtr)) { |
| 2748 |
|
| 2749 |
|
| 2750 |
|
| 2751 |
|
| 2752 |
|
| 2753 |
|
| 2754 |
Tcl_FSDeleteFile(copyToPtr); |
| 2755 |
Tcl_DecrRefCount(copyToPtr); |
| 2756 |
return -1; |
| 2757 |
} |
| 2758 |
|
| 2759 |
if (TclCrossFilesystemCopy(interp, pathPtr, |
| 2760 |
copyToPtr) == TCL_OK) { |
| 2761 |
Tcl_LoadHandle newLoadHandle = NULL; |
| 2762 |
Tcl_FSUnloadFileProc *newUnloadProcPtr = NULL; |
| 2763 |
FsDivertLoad *tvdlPtr; |
| 2764 |
int retVal; |
| 2765 |
|
| 2766 |
#if !defined(__WIN32__) && !defined(MAC_TCL) |
| 2767 |
|
| 2768 |
|
| 2769 |
|
| 2770 |
|
| 2771 |
|
| 2772 |
|
| 2773 |
|
| 2774 |
|
| 2775 |
|
| 2776 |
Tcl_Obj* perm = Tcl_NewStringObj("0700",-1); |
| 2777 |
Tcl_IncrRefCount(perm); |
| 2778 |
Tcl_FSFileAttrsSet(NULL, 2, copyToPtr, perm); |
| 2779 |
Tcl_DecrRefCount(perm); |
| 2780 |
#endif |
| 2781 |
|
| 2782 |
|
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
Tcl_ResetResult(interp); |
| 2788 |
|
| 2789 |
retVal = Tcl_FSLoadFile(interp, copyToPtr, sym1, sym2, |
| 2790 |
proc1Ptr, proc2Ptr, |
| 2791 |
&newLoadHandle, |
| 2792 |
&newUnloadProcPtr); |
| 2793 |
if (retVal != TCL_OK) { |
| 2794 |
|
| 2795 |
Tcl_FSDeleteFile(copyToPtr); |
| 2796 |
Tcl_DecrRefCount(copyToPtr); |
| 2797 |
return retVal; |
| 2798 |
} |
| 2799 |
|
| 2800 |
|
| 2801 |
|
| 2802 |
|
| 2803 |
|
| 2804 |
if (Tcl_FSDeleteFile(copyToPtr) == TCL_OK) { |
| 2805 |
Tcl_DecrRefCount(copyToPtr); |
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
|
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
|
| 2814 |
(*handlePtr) = newLoadHandle; |
| 2815 |
(*unloadProcPtr) = newUnloadProcPtr; |
| 2816 |
return TCL_OK; |
| 2817 |
} |
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
|
| 2822 |
|
| 2823 |
tvdlPtr = (FsDivertLoad*) ckalloc(sizeof(FsDivertLoad)); |
| 2824 |
|
| 2825 |
|
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
tvdlPtr->loadHandle = newLoadHandle; |
| 2831 |
tvdlPtr->unloadProcPtr = newUnloadProcPtr; |
| 2832 |
|
| 2833 |
if (copyFsPtr != &tclNativeFilesystem) { |
| 2834 |
|
| 2835 |
tvdlPtr->divertedFile = copyToPtr; |
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
tvdlPtr->divertedFilesystem = copyFsPtr; |
| 2844 |
tvdlPtr->divertedFileNativeRep = NULL; |
| 2845 |
} else { |
| 2846 |
|
| 2847 |
tvdlPtr->divertedFileNativeRep = |
| 2848 |
NativeDupInternalRep(Tcl_FSGetInternalRep(copyToPtr, |
| 2849 |
copyFsPtr)); |
| 2850 |
|
| 2851 |
|
| 2852 |
|
| 2853 |
|
| 2854 |
|
| 2855 |
tvdlPtr->divertedFile = NULL; |
| 2856 |
tvdlPtr->divertedFilesystem = NULL; |
| 2857 |
Tcl_DecrRefCount(copyToPtr); |
| 2858 |
} |
| 2859 |
|
| 2860 |
copyToPtr = NULL; |
| 2861 |
(*handlePtr) = (Tcl_LoadHandle) tvdlPtr; |
| 2862 |
(*unloadProcPtr) = &FSUnloadTempFile; |
| 2863 |
return retVal; |
| 2864 |
} else { |
| 2865 |
|
| 2866 |
Tcl_FSDeleteFile(copyToPtr); |
| 2867 |
Tcl_DecrRefCount(copyToPtr); |
| 2868 |
return TCL_ERROR; |
| 2869 |
} |
| 2870 |
} |
| 2871 |
} |
| 2872 |
Tcl_SetErrno(ENOENT); |
| 2873 |
return -1; |
| 2874 |
} |
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
int |
| 2880 |
TclpLoadFile(interp, pathPtr, sym1, sym2, proc1Ptr, proc2Ptr, |
| 2881 |
clientDataPtr, unloadProcPtr) |
| 2882 |
Tcl_Interp *interp; |
| 2883 |
Tcl_Obj *pathPtr; |
| 2884 |
|
| 2885 |
CONST char *sym1, *sym2; |
| 2886 |
|
| 2887 |
Tcl_PackageInitProc **proc1Ptr, **proc2Ptr; |
| 2888 |
|
| 2889 |
|
| 2890 |
ClientData *clientDataPtr; |
| 2891 |
|
| 2892 |
|
| 2893 |
Tcl_FSUnloadFileProc **unloadProcPtr; |
| 2894 |
|
| 2895 |
|
| 2896 |
|
| 2897 |
{ |
| 2898 |
Tcl_LoadHandle handle = NULL; |
| 2899 |
int res; |
| 2900 |
|
| 2901 |
res = TclpDlopen(interp, pathPtr, &handle, unloadProcPtr); |
| 2902 |
|
| 2903 |
if (res != TCL_OK) { |
| 2904 |
return res; |
| 2905 |
} |
| 2906 |
|
| 2907 |
if (handle == NULL) { |
| 2908 |
return TCL_ERROR; |
| 2909 |
} |
| 2910 |
|
| 2911 |
*clientDataPtr = (ClientData)handle; |
| 2912 |
|
| 2913 |
*proc1Ptr = TclpFindSymbol(interp, handle, sym1); |
| 2914 |
*proc2Ptr = TclpFindSymbol(interp, handle, sym2); |
| 2915 |
return TCL_OK; |
| 2916 |
} |
| 2917 |
|
| 2918 |
|
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
|
| 2923 |
|
| 2924 |
|
| 2925 |
|
| 2926 |
|
| 2927 |
|
| 2928 |
|
| 2929 |
|
| 2930 |
|
| 2931 |
|
| 2932 |
|
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
static void |
| 2938 |
FSUnloadTempFile(loadHandle) |
| 2939 |
Tcl_LoadHandle loadHandle; |
| 2940 |
|
| 2941 |
|
| 2942 |
|
| 2943 |
{ |
| 2944 |
FsDivertLoad *tvdlPtr = (FsDivertLoad*)loadHandle; |
| 2945 |
|
| 2946 |
|
| 2947 |
|
| 2948 |
|
| 2949 |
if (tvdlPtr == NULL) { return; } |
| 2950 |
|
| 2951 |
|
| 2952 |
|
| 2953 |
|
| 2954 |
|
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
if (tvdlPtr->unloadProcPtr != NULL) { |
| 2959 |
(*tvdlPtr->unloadProcPtr)(tvdlPtr->loadHandle); |
| 2960 |
} |
| 2961 |
|
| 2962 |
if (tvdlPtr->divertedFilesystem == NULL) { |
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
|
| 2967 |
|
| 2968 |
TclpDeleteFile(tvdlPtr->divertedFileNativeRep); |
| 2969 |
NativeFreeInternalRep(tvdlPtr->divertedFileNativeRep); |
| 2970 |
} else { |
| 2971 |
|
| 2972 |
|
| 2973 |
|
| 2974 |
|
| 2975 |
if (tvdlPtr->divertedFilesystem->deleteFileProc(tvdlPtr->divertedFile) |
| 2976 |
!= TCL_OK) { |
| 2977 |
|
| 2978 |
|
| 2979 |
|
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
|
| 2984 |
|
| 2985 |
|
| 2986 |
|
| 2987 |
|
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
|
| 2993 |
} |
| 2994 |
|
| 2995 |
|
| 2996 |
|
| 2997 |
|
| 2998 |
|
| 2999 |
|
| 3000 |
Tcl_DecrRefCount(tvdlPtr->divertedFile); |
| 3001 |
} |
| 3002 |
|
| 3003 |
ckfree((char*)tvdlPtr); |
| 3004 |
} |
| 3005 |
|
| 3006 |
|
| 3007 |
|
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
|
| 3012 |
|
| 3013 |
|
| 3014 |
|
| 3015 |
|
| 3016 |
|
| 3017 |
|
| 3018 |
|
| 3019 |
|
| 3020 |
|
| 3021 |
|
| 3022 |
|
| 3023 |
|
| 3024 |
|
| 3025 |
|
| 3026 |
|
| 3027 |
|
| 3028 |
|
| 3029 |
|
| 3030 |
|
| 3031 |
|
| 3032 |
|
| 3033 |
|
| 3034 |
|
| 3035 |
|
| 3036 |
|
| 3037 |
|
| 3038 |
|
| 3039 |
|
| 3040 |
|
| 3041 |
|
| 3042 |
Tcl_Obj * |
| 3043 |
Tcl_FSLink(pathPtr, toPtr, linkAction) |
| 3044 |
Tcl_Obj *pathPtr; |
| 3045 |
Tcl_Obj *toPtr; |
| 3046 |
int linkAction; |
| 3047 |
{ |
| 3048 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 3049 |
if (fsPtr != NULL) { |
| 3050 |
Tcl_FSLinkProc *proc = fsPtr->linkProc; |
| 3051 |
if (proc != NULL) { |
| 3052 |
return (*proc)(pathPtr, toPtr, linkAction); |
| 3053 |
} |
| 3054 |
} |
| 3055 |
|
| 3056 |
|
| 3057 |
|
| 3058 |
|
| 3059 |
|
| 3060 |
|
| 3061 |
|
| 3062 |
#ifndef S_IFLNK |
| 3063 |
errno = EINVAL; |
| 3064 |
#else |
| 3065 |
Tcl_SetErrno(ENOENT); |
| 3066 |
#endif |
| 3067 |
return NULL; |
| 3068 |
} |
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
|
| 3073 |
|
| 3074 |
|
| 3075 |
|
| 3076 |
|
| 3077 |
|
| 3078 |
|
| 3079 |
|
| 3080 |
|
| 3081 |
|
| 3082 |
|
| 3083 |
|
| 3084 |
|
| 3085 |
|
| 3086 |
|
| 3087 |
|
| 3088 |
|
| 3089 |
|
| 3090 |
|
| 3091 |
|
| 3092 |
|
| 3093 |
|
| 3094 |
|
| 3095 |
|
| 3096 |
Tcl_Obj* |
| 3097 |
Tcl_FSListVolumes(void) |
| 3098 |
{ |
| 3099 |
FilesystemRecord *fsRecPtr; |
| 3100 |
Tcl_Obj *resultPtr = Tcl_NewObj(); |
| 3101 |
|
| 3102 |
|
| 3103 |
|
| 3104 |
|
| 3105 |
|
| 3106 |
|
| 3107 |
|
| 3108 |
|
| 3109 |
fsRecPtr = FsGetFirstFilesystem(); |
| 3110 |
while (fsRecPtr != NULL) { |
| 3111 |
Tcl_FSListVolumesProc *proc = fsRecPtr->fsPtr->listVolumesProc; |
| 3112 |
if (proc != NULL) { |
| 3113 |
Tcl_Obj *thisFsVolumes = (*proc)(); |
| 3114 |
if (thisFsVolumes != NULL) { |
| 3115 |
Tcl_ListObjAppendList(NULL, resultPtr, thisFsVolumes); |
| 3116 |
Tcl_DecrRefCount(thisFsVolumes); |
| 3117 |
} |
| 3118 |
} |
| 3119 |
fsRecPtr = fsRecPtr->nextPtr; |
| 3120 |
} |
| 3121 |
|
| 3122 |
return resultPtr; |
| 3123 |
} |
| 3124 |
|
| 3125 |
|
| 3126 |
|
| 3127 |
|
| 3128 |
|
| 3129 |
|
| 3130 |
|
| 3131 |
|
| 3132 |
|
| 3133 |
|
| 3134 |
|
| 3135 |
|
| 3136 |
|
| 3137 |
|
| 3138 |
|
| 3139 |
|
| 3140 |
|
| 3141 |
|
| 3142 |
|
| 3143 |
|
| 3144 |
static Tcl_Obj* |
| 3145 |
FsListMounts(pathPtr, pattern) |
| 3146 |
Tcl_Obj *pathPtr; |
| 3147 |
CONST char *pattern; |
| 3148 |
{ |
| 3149 |
FilesystemRecord *fsRecPtr; |
| 3150 |
Tcl_GlobTypeData mountsOnly = { TCL_GLOB_TYPE_MOUNT, 0, NULL, NULL }; |
| 3151 |
Tcl_Obj *resultPtr = NULL; |
| 3152 |
|
| 3153 |
|
| 3154 |
|
| 3155 |
|
| 3156 |
|
| 3157 |
|
| 3158 |
|
| 3159 |
|
| 3160 |
fsRecPtr = FsGetFirstFilesystem(); |
| 3161 |
while (fsRecPtr != NULL) { |
| 3162 |
if (fsRecPtr != &nativeFilesystemRecord) { |
| 3163 |
Tcl_FSMatchInDirectoryProc *proc = |
| 3164 |
fsRecPtr->fsPtr->matchInDirectoryProc; |
| 3165 |
if (proc != NULL) { |
| 3166 |
if (resultPtr == NULL) { |
| 3167 |
resultPtr = Tcl_NewObj(); |
| 3168 |
} |
| 3169 |
(*proc)(NULL, resultPtr, pathPtr, pattern, &mountsOnly); |
| 3170 |
} |
| 3171 |
} |
| 3172 |
fsRecPtr = fsRecPtr->nextPtr; |
| 3173 |
} |
| 3174 |
|
| 3175 |
return resultPtr; |
| 3176 |
} |
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
|
| 3181 |
|
| 3182 |
|
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
|
| 3192 |
|
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
|
| 3197 |
|
| 3198 |
Tcl_Obj* |
| 3199 |
Tcl_FSSplitPath(pathPtr, lenPtr) |
| 3200 |
Tcl_Obj *pathPtr; |
| 3201 |
int *lenPtr; |
| 3202 |
{ |
| 3203 |
Tcl_Obj *result = NULL; |
| 3204 |
Tcl_Filesystem *fsPtr; |
| 3205 |
char separator = '/'; |
| 3206 |
int driveNameLength; |
| 3207 |
char *p; |
| 3208 |
|
| 3209 |
|
| 3210 |
|
| 3211 |
|
| 3212 |
|
| 3213 |
if (FSGetPathType(pathPtr, &fsPtr, &driveNameLength) |
| 3214 |
== TCL_PATH_ABSOLUTE) { |
| 3215 |
if (fsPtr == &tclNativeFilesystem) { |
| 3216 |
return TclpNativeSplitPath(pathPtr, lenPtr); |
| 3217 |
} |
| 3218 |
} else { |
| 3219 |
return TclpNativeSplitPath(pathPtr, lenPtr); |
| 3220 |
} |
| 3221 |
|
| 3222 |
|
| 3223 |
if (fsPtr->filesystemSeparatorProc != NULL) { |
| 3224 |
Tcl_Obj *sep = (*fsPtr->filesystemSeparatorProc)(pathPtr); |
| 3225 |
if (sep != NULL) { |
| 3226 |
separator = Tcl_GetString(sep)[0]; |
| 3227 |
} |
| 3228 |
} |
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
|
| 3233 |
|
| 3234 |
|
| 3235 |
|
| 3236 |
result = Tcl_NewObj(); |
| 3237 |
p = Tcl_GetString(pathPtr); |
| 3238 |
Tcl_ListObjAppendElement(NULL, result, |
| 3239 |
Tcl_NewStringObj(p, driveNameLength)); |
| 3240 |
p+= driveNameLength; |
| 3241 |
|
| 3242 |
|
| 3243 |
for (;;) { |
| 3244 |
char *elementStart = p; |
| 3245 |
int length; |
| 3246 |
while ((*p != '\0') && (*p != separator)) { |
| 3247 |
p++; |
| 3248 |
} |
| 3249 |
length = p - elementStart; |
| 3250 |
if (length > 0) { |
| 3251 |
Tcl_Obj *nextElt; |
| 3252 |
if (elementStart[0] == '~') { |
| 3253 |
nextElt = Tcl_NewStringObj("./",2); |
| 3254 |
Tcl_AppendToObj(nextElt, elementStart, length); |
| 3255 |
} else { |
| 3256 |
nextElt = Tcl_NewStringObj(elementStart, length); |
| 3257 |
} |
| 3258 |
Tcl_ListObjAppendElement(NULL, result, nextElt); |
| 3259 |
} |
| 3260 |
if (*p++ == '\0') { |
| 3261 |
break; |
| 3262 |
} |
| 3263 |
} |
| 3264 |
|
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
if (lenPtr != NULL) { |
| 3270 |
Tcl_ListObjLength(NULL, result, lenPtr); |
| 3271 |
} |
| 3272 |
return result; |
| 3273 |
} |
| 3274 |
|
| 3275 |
|
| 3276 |
Tcl_Obj* |
| 3277 |
TclFSInternalToNormalized(fromFilesystem, clientData, fsRecPtrPtr) |
| 3278 |
Tcl_Filesystem *fromFilesystem; |
| 3279 |
ClientData clientData; |
| 3280 |
FilesystemRecord **fsRecPtrPtr; |
| 3281 |
{ |
| 3282 |
FilesystemRecord *fsRecPtr = FsGetFirstFilesystem(); |
| 3283 |
|
| 3284 |
while (fsRecPtr != NULL) { |
| 3285 |
if (fsRecPtr->fsPtr == fromFilesystem) { |
| 3286 |
*fsRecPtrPtr = fsRecPtr; |
| 3287 |
break; |
| 3288 |
} |
| 3289 |
fsRecPtr = fsRecPtr->nextPtr; |
| 3290 |
} |
| 3291 |
|
| 3292 |
if ((fsRecPtr != NULL) |
| 3293 |
&& (fromFilesystem->internalToNormalizedProc != NULL)) { |
| 3294 |
return (*fromFilesystem->internalToNormalizedProc)(clientData); |
| 3295 |
} else { |
| 3296 |
return NULL; |
| 3297 |
} |
| 3298 |
} |
| 3299 |
|
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
|
| 3306 |
|
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
|
| 3315 |
|
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
Tcl_PathType |
| 3320 |
GetPathType(pathObjPtr, filesystemPtrPtr, driveNameLengthPtr, driveNameRef) |
| 3321 |
Tcl_Obj *pathObjPtr; |
| 3322 |
Tcl_Filesystem **filesystemPtrPtr; |
| 3323 |
int *driveNameLengthPtr; |
| 3324 |
Tcl_Obj **driveNameRef; |
| 3325 |
{ |
| 3326 |
FilesystemRecord *fsRecPtr; |
| 3327 |
int pathLen; |
| 3328 |
char *path; |
| 3329 |
Tcl_PathType type = TCL_PATH_RELATIVE; |
| 3330 |
|
| 3331 |
path = Tcl_GetStringFromObj(pathObjPtr, &pathLen); |
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
|
| 3338 |
|
| 3339 |
|
| 3340 |
fsRecPtr = FsGetFirstFilesystem(); |
| 3341 |
while (fsRecPtr != NULL) { |
| 3342 |
Tcl_FSListVolumesProc *proc = fsRecPtr->fsPtr->listVolumesProc; |
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
|
| 3361 |
|
| 3362 |
if ((fsRecPtr->fsPtr != &tclNativeFilesystem) && (proc != NULL)) { |
| 3363 |
int numVolumes; |
| 3364 |
Tcl_Obj *thisFsVolumes = (*proc)(); |
| 3365 |
if (thisFsVolumes != NULL) { |
| 3366 |
if (Tcl_ListObjLength(NULL, thisFsVolumes, |
| 3367 |
&numVolumes) != TCL_OK) { |
| 3368 |
|
| 3369 |
|
| 3370 |
|
| 3371 |
|
| 3372 |
|
| 3373 |
|
| 3374 |
|
| 3375 |
|
| 3376 |
|
| 3377 |
numVolumes = -1; |
| 3378 |
} |
| 3379 |
while (numVolumes > 0) { |
| 3380 |
Tcl_Obj *vol; |
| 3381 |
int len; |
| 3382 |
char *strVol; |
| 3383 |
|
| 3384 |
numVolumes--; |
| 3385 |
Tcl_ListObjIndex(NULL, thisFsVolumes, numVolumes, &vol); |
| 3386 |
strVol = Tcl_GetStringFromObj(vol,&len); |
| 3387 |
if (pathLen < len) { |
| 3388 |
continue; |
| 3389 |
} |
| 3390 |
if (strncmp(strVol, path, (size_t) len) == 0) { |
| 3391 |
type = TCL_PATH_ABSOLUTE; |
| 3392 |
if (filesystemPtrPtr != NULL) { |
| 3393 |
*filesystemPtrPtr = fsRecPtr->fsPtr; |
| 3394 |
} |
| 3395 |
if (driveNameLengthPtr != NULL) { |
| 3396 |
*driveNameLengthPtr = len; |
| 3397 |
} |
| 3398 |
if (driveNameRef != NULL) { |
| 3399 |
*driveNameRef = vol; |
| 3400 |
Tcl_IncrRefCount(vol); |
| 3401 |
} |
| 3402 |
break; |
| 3403 |
} |
| 3404 |
} |
| 3405 |
Tcl_DecrRefCount(thisFsVolumes); |
| 3406 |
if (type == TCL_PATH_ABSOLUTE) { |
| 3407 |
|
| 3408 |
break; |
| 3409 |
} |
| 3410 |
} |
| 3411 |
} |
| 3412 |
fsRecPtr = fsRecPtr->nextPtr; |
| 3413 |
} |
| 3414 |
|
| 3415 |
if (type != TCL_PATH_ABSOLUTE) { |
| 3416 |
type = TclpGetNativePathType(pathObjPtr, driveNameLengthPtr, |
| 3417 |
driveNameRef); |
| 3418 |
if ((type == TCL_PATH_ABSOLUTE) && (filesystemPtrPtr != NULL)) { |
| 3419 |
*filesystemPtrPtr = &tclNativeFilesystem; |
| 3420 |
} |
| 3421 |
} |
| 3422 |
return type; |
| 3423 |
} |
| 3424 |
|
| 3425 |
|
| 3426 |
|
| 3427 |
|
| 3428 |
|
| 3429 |
|
| 3430 |
|
| 3431 |
|
| 3432 |
|
| 3433 |
|
| 3434 |
|
| 3435 |
|
| 3436 |
|
| 3437 |
|
| 3438 |
|
| 3439 |
|
| 3440 |
|
| 3441 |
|
| 3442 |
|
| 3443 |
int |
| 3444 |
Tcl_FSRenameFile(srcPathPtr, destPathPtr) |
| 3445 |
Tcl_Obj* srcPathPtr; |
| 3446 |
|
| 3447 |
Tcl_Obj *destPathPtr; |
| 3448 |
|
| 3449 |
{ |
| 3450 |
int retVal = -1; |
| 3451 |
Tcl_Filesystem *fsPtr, *fsPtr2; |
| 3452 |
fsPtr = Tcl_FSGetFileSystemForPath(srcPathPtr); |
| 3453 |
fsPtr2 = Tcl_FSGetFileSystemForPath(destPathPtr); |
| 3454 |
|
| 3455 |
if (fsPtr == fsPtr2 && fsPtr != NULL) { |
| 3456 |
Tcl_FSRenameFileProc *proc = fsPtr->renameFileProc; |
| 3457 |
if (proc != NULL) { |
| 3458 |
retVal = (*proc)(srcPathPtr, destPathPtr); |
| 3459 |
} |
| 3460 |
} |
| 3461 |
if (retVal == -1) { |
| 3462 |
Tcl_SetErrno(EXDEV); |
| 3463 |
} |
| 3464 |
return retVal; |
| 3465 |
} |
| 3466 |
|
| 3467 |
|
| 3468 |
|
| 3469 |
|
| 3470 |
|
| 3471 |
|
| 3472 |
|
| 3473 |
|
| 3474 |
|
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
|
| 3482 |
|
| 3483 |
|
| 3484 |
|
| 3485 |
|
| 3486 |
|
| 3487 |
|
| 3488 |
|
| 3489 |
int |
| 3490 |
Tcl_FSCopyFile(srcPathPtr, destPathPtr) |
| 3491 |
Tcl_Obj* srcPathPtr; |
| 3492 |
Tcl_Obj *destPathPtr; |
| 3493 |
{ |
| 3494 |
int retVal = -1; |
| 3495 |
Tcl_Filesystem *fsPtr, *fsPtr2; |
| 3496 |
fsPtr = Tcl_FSGetFileSystemForPath(srcPathPtr); |
| 3497 |
fsPtr2 = Tcl_FSGetFileSystemForPath(destPathPtr); |
| 3498 |
|
| 3499 |
if (fsPtr == fsPtr2 && fsPtr != NULL) { |
| 3500 |
Tcl_FSCopyFileProc *proc = fsPtr->copyFileProc; |
| 3501 |
if (proc != NULL) { |
| 3502 |
retVal = (*proc)(srcPathPtr, destPathPtr); |
| 3503 |
} |
| 3504 |
} |
| 3505 |
if (retVal == -1) { |
| 3506 |
Tcl_SetErrno(EXDEV); |
| 3507 |
} |
| 3508 |
return retVal; |
| 3509 |
} |
| 3510 |
|
| 3511 |
|
| 3512 |
|
| 3513 |
|
| 3514 |
|
| 3515 |
|
| 3516 |
|
| 3517 |
|
| 3518 |
|
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
|
| 3524 |
|
| 3525 |
|
| 3526 |
|
| 3527 |
|
| 3528 |
int |
| 3529 |
TclCrossFilesystemCopy(interp, source, target) |
| 3530 |
Tcl_Interp *interp; |
| 3531 |
Tcl_Obj *source; |
| 3532 |
Tcl_Obj *target; |
| 3533 |
{ |
| 3534 |
int result = TCL_ERROR; |
| 3535 |
int prot = 0666; |
| 3536 |
|
| 3537 |
Tcl_Channel out = Tcl_FSOpenFileChannel(interp, target, "w", prot); |
| 3538 |
if (out != NULL) { |
| 3539 |
|
| 3540 |
Tcl_Channel in = Tcl_FSOpenFileChannel(interp, source, |
| 3541 |
"r", prot); |
| 3542 |
if (in == NULL) { |
| 3543 |
|
| 3544 |
Tcl_Close(interp, out); |
| 3545 |
} else { |
| 3546 |
Tcl_StatBuf sourceStatBuf; |
| 3547 |
struct utimbuf tval; |
| 3548 |
|
| 3549 |
|
| 3550 |
|
| 3551 |
|
| 3552 |
|
| 3553 |
Tcl_SetChannelOption(interp, in, "-translation", "binary"); |
| 3554 |
Tcl_SetChannelOption(interp, out, "-translation", "binary"); |
| 3555 |
|
| 3556 |
if (TclCopyChannel(interp, in, out, -1, NULL) == TCL_OK) { |
| 3557 |
result = TCL_OK; |
| 3558 |
} |
| 3559 |
|
| 3560 |
|
| 3561 |
|
| 3562 |
|
| 3563 |
Tcl_Close(interp, in); |
| 3564 |
Tcl_Close(interp, out); |
| 3565 |
|
| 3566 |
|
| 3567 |
if (Tcl_FSLstat(source, &sourceStatBuf) == 0) { |
| 3568 |
tval.actime = sourceStatBuf.st_atime; |
| 3569 |
tval.modtime = sourceStatBuf.st_mtime; |
| 3570 |
Tcl_FSUtime(target, &tval); |
| 3571 |
} |
| 3572 |
} |
| 3573 |
} |
| 3574 |
return result; |
| 3575 |
} |
| 3576 |
|
| 3577 |
|
| 3578 |
|
| 3579 |
|
| 3580 |
|
| 3581 |
|
| 3582 |
|
| 3583 |
|
| 3584 |
|
| 3585 |
|
| 3586 |
|
| 3587 |
|
| 3588 |
|
| 3589 |
|
| 3590 |
|
| 3591 |
|
| 3592 |
|
| 3593 |
|
| 3594 |
int |
| 3595 |
Tcl_FSDeleteFile(pathPtr) |
| 3596 |
Tcl_Obj *pathPtr; |
| 3597 |
{ |
| 3598 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 3599 |
if (fsPtr != NULL) { |
| 3600 |
Tcl_FSDeleteFileProc *proc = fsPtr->deleteFileProc; |
| 3601 |
if (proc != NULL) { |
| 3602 |
return (*proc)(pathPtr); |
| 3603 |
} |
| 3604 |
} |
| 3605 |
Tcl_SetErrno(ENOENT); |
| 3606 |
return -1; |
| 3607 |
} |
| 3608 |
|
| 3609 |
|
| 3610 |
|
| 3611 |
|
| 3612 |
|
| 3613 |
|
| 3614 |
|
| 3615 |
|
| 3616 |
|
| 3617 |
|
| 3618 |
|
| 3619 |
|
| 3620 |
|
| 3621 |
|
| 3622 |
|
| 3623 |
|
| 3624 |
|
| 3625 |
|
| 3626 |
int |
| 3627 |
Tcl_FSCreateDirectory(pathPtr) |
| 3628 |
Tcl_Obj *pathPtr; |
| 3629 |
{ |
| 3630 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 3631 |
if (fsPtr != NULL) { |
| 3632 |
Tcl_FSCreateDirectoryProc *proc = fsPtr->createDirectoryProc; |
| 3633 |
if (proc != NULL) { |
| 3634 |
return (*proc)(pathPtr); |
| 3635 |
} |
| 3636 |
} |
| 3637 |
Tcl_SetErrno(ENOENT); |
| 3638 |
return -1; |
| 3639 |
} |
| 3640 |
|
| 3641 |
|
| 3642 |
|
| 3643 |
|
| 3644 |
|
| 3645 |
|
| 3646 |
|
| 3647 |
|
| 3648 |
|
| 3649 |
|
| 3650 |
|
| 3651 |
|
| 3652 |
|
| 3653 |
|
| 3654 |
|
| 3655 |
|
| 3656 |
|
| 3657 |
|
| 3658 |
|
| 3659 |
int |
| 3660 |
Tcl_FSCopyDirectory(srcPathPtr, destPathPtr, errorPtr) |
| 3661 |
Tcl_Obj* srcPathPtr; |
| 3662 |
|
| 3663 |
Tcl_Obj *destPathPtr; |
| 3664 |
Tcl_Obj **errorPtr; |
| 3665 |
|
| 3666 |
|
| 3667 |
{ |
| 3668 |
int retVal = -1; |
| 3669 |
Tcl_Filesystem *fsPtr, *fsPtr2; |
| 3670 |
fsPtr = Tcl_FSGetFileSystemForPath(srcPathPtr); |
| 3671 |
fsPtr2 = Tcl_FSGetFileSystemForPath(destPathPtr); |
| 3672 |
|
| 3673 |
if (fsPtr == fsPtr2 && fsPtr != NULL) { |
| 3674 |
Tcl_FSCopyDirectoryProc *proc = fsPtr->copyDirectoryProc; |
| 3675 |
if (proc != NULL) { |
| 3676 |
retVal = (*proc)(srcPathPtr, destPathPtr, errorPtr); |
| 3677 |
} |
| 3678 |
} |
| 3679 |
if (retVal == -1) { |
| 3680 |
Tcl_SetErrno(EXDEV); |
| 3681 |
} |
| 3682 |
return retVal; |
| 3683 |
} |
| 3684 |
|
| 3685 |
|
| 3686 |
|
| 3687 |
|
| 3688 |
|
| 3689 |
|
| 3690 |
|
| 3691 |
|
| 3692 |
|
| 3693 |
|
| 3694 |
|
| 3695 |
|
| 3696 |
|
| 3697 |
|
| 3698 |
|
| 3699 |
|
| 3700 |
|
| 3701 |
|
| 3702 |
int |
| 3703 |
Tcl_FSRemoveDirectory(pathPtr, recursive, errorPtr) |
| 3704 |
Tcl_Obj *pathPtr; |
| 3705 |
|
| 3706 |
int recursive; |
| 3707 |
|
| 3708 |
|
| 3709 |
Tcl_Obj **errorPtr; |
| 3710 |
|
| 3711 |
|
| 3712 |
{ |
| 3713 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathPtr); |
| 3714 |
if (fsPtr != NULL) { |
| 3715 |
Tcl_FSRemoveDirectoryProc *proc = fsPtr->removeDirectoryProc; |
| 3716 |
if (proc != NULL) { |
| 3717 |
if (recursive) { |
| 3718 |
|
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
Tcl_Obj *cwdPtr = Tcl_FSGetCwd(NULL); |
| 3723 |
if (cwdPtr != NULL) { |
| 3724 |
char *cwdStr, *normPathStr; |
| 3725 |
int cwdLen, normLen; |
| 3726 |
Tcl_Obj *normPath = Tcl_FSGetNormalizedPath(NULL, pathPtr); |
| 3727 |
if (normPath != NULL) { |
| 3728 |
normPathStr = Tcl_GetStringFromObj(normPath, &normLen); |
| 3729 |
cwdStr = Tcl_GetStringFromObj(cwdPtr, &cwdLen); |
| 3730 |
if ((cwdLen >= normLen) && (strncmp(normPathStr, |
| 3731 |
cwdStr, (size_t) normLen) == 0)) { |
| 3732 |
|
| 3733 |
|
| 3734 |
|
| 3735 |
|
| 3736 |
Tcl_Obj *dirPtr = TclFileDirname(NULL, pathPtr); |
| 3737 |
Tcl_FSChdir(dirPtr); |
| 3738 |
Tcl_DecrRefCount(dirPtr); |
| 3739 |
} |
| 3740 |
} |
| 3741 |
Tcl_DecrRefCount(cwdPtr); |
| 3742 |
} |
| 3743 |
} |
| 3744 |
return (*proc)(pathPtr, recursive, errorPtr); |
| 3745 |
} |
| 3746 |
} |
| 3747 |
Tcl_SetErrno(ENOENT); |
| 3748 |
return -1; |
| 3749 |
} |
| 3750 |
|
| 3751 |
|
| 3752 |
|
| 3753 |
|
| 3754 |
|
| 3755 |
|
| 3756 |
|
| 3757 |
|
| 3758 |
|
| 3759 |
|
| 3760 |
|
| 3761 |
|
| 3762 |
|
| 3763 |
|
| 3764 |
|
| 3765 |
|
| 3766 |
|
| 3767 |
|
| 3768 |
|
| 3769 |
|
| 3770 |
Tcl_Filesystem* |
| 3771 |
Tcl_FSGetFileSystemForPath(pathObjPtr) |
| 3772 |
Tcl_Obj* pathObjPtr; |
| 3773 |
{ |
| 3774 |
FilesystemRecord *fsRecPtr; |
| 3775 |
Tcl_Filesystem* retVal = NULL; |
| 3776 |
|
| 3777 |
|
| 3778 |
|
| 3779 |
|
| 3780 |
|
| 3781 |
|
| 3782 |
|
| 3783 |
|
| 3784 |
if (pathObjPtr->refCount == 0) { |
| 3785 |
panic("Tcl_FSGetFileSystemForPath called with object with refCount == 0"); |
| 3786 |
return NULL; |
| 3787 |
} |
| 3788 |
|
| 3789 |
|
| 3790 |
|
| 3791 |
|
| 3792 |
|
| 3793 |
if (TclFSEnsureEpochOk(pathObjPtr, &retVal) != TCL_OK) { |
| 3794 |
return NULL; |
| 3795 |
} |
| 3796 |
|
| 3797 |
|
| 3798 |
|
| 3799 |
|
| 3800 |
|
| 3801 |
|
| 3802 |
|
| 3803 |
fsRecPtr = FsGetFirstFilesystem(); |
| 3804 |
while ((retVal == NULL) && (fsRecPtr != NULL)) { |
| 3805 |
Tcl_FSPathInFilesystemProc *proc = fsRecPtr->fsPtr->pathInFilesystemProc; |
| 3806 |
if (proc != NULL) { |
| 3807 |
ClientData clientData = NULL; |
| 3808 |
int ret = (*proc)(pathObjPtr, &clientData); |
| 3809 |
if (ret != -1) { |
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
TclFSSetPathDetails(pathObjPtr, fsRecPtr, clientData); |
| 3815 |
retVal = fsRecPtr->fsPtr; |
| 3816 |
} |
| 3817 |
} |
| 3818 |
fsRecPtr = fsRecPtr->nextPtr; |
| 3819 |
} |
| 3820 |
|
| 3821 |
return retVal; |
| 3822 |
} |
| 3823 |
|
| 3824 |
|
| 3825 |
|
| 3826 |
|
| 3827 |
|
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
|
| 3832 |
|
| 3833 |
|
| 3834 |
|
| 3835 |
|
| 3836 |
|
| 3837 |
|
| 3838 |
|
| 3839 |
|
| 3840 |
|
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
|
| 3845 |
|
| 3846 |
|
| 3847 |
|
| 3848 |
|
| 3849 |
|
| 3850 |
|
| 3851 |
|
| 3852 |
|
| 3853 |
|
| 3854 |
|
| 3855 |
|
| 3856 |
CONST char * |
| 3857 |
Tcl_FSGetNativePath(pathObjPtr) |
| 3858 |
Tcl_Obj *pathObjPtr; |
| 3859 |
{ |
| 3860 |
return (CONST char *)Tcl_FSGetInternalRep(pathObjPtr, &tclNativeFilesystem); |
| 3861 |
} |
| 3862 |
|
| 3863 |
|
| 3864 |
|
| 3865 |
|
| 3866 |
|
| 3867 |
|
| 3868 |
|
| 3869 |
|
| 3870 |
|
| 3871 |
|
| 3872 |
|
| 3873 |
|
| 3874 |
|
| 3875 |
|
| 3876 |
|
| 3877 |
|
| 3878 |
static ClientData |
| 3879 |
NativeCreateNativeRep(pathObjPtr) |
| 3880 |
Tcl_Obj* pathObjPtr; |
| 3881 |
{ |
| 3882 |
char *nativePathPtr; |
| 3883 |
Tcl_DString ds; |
| 3884 |
Tcl_Obj* validPathObjPtr; |
| 3885 |
int len; |
| 3886 |
char *str; |
| 3887 |
|
| 3888 |
|
| 3889 |
validPathObjPtr = Tcl_FSGetNormalizedPath(NULL, pathObjPtr); |
| 3890 |
|
| 3891 |
str = Tcl_GetStringFromObj(validPathObjPtr, &len); |
| 3892 |
#ifdef __WIN32__ |
| 3893 |
Tcl_WinUtfToTChar(str, len, &ds); |
| 3894 |
if (tclWinProcs->useWide) { |
| 3895 |
len = Tcl_DStringLength(&ds) + sizeof(WCHAR); |
| 3896 |
} else { |
| 3897 |
len = Tcl_DStringLength(&ds) + sizeof(char); |
| 3898 |
} |
| 3899 |
#else |
| 3900 |
Tcl_UtfToExternalDString(NULL, str, len, &ds); |
| 3901 |
len = Tcl_DStringLength(&ds) + sizeof(char); |
| 3902 |
#endif |
| 3903 |
nativePathPtr = ckalloc((unsigned) len); |
| 3904 |
memcpy((VOID*)nativePathPtr, (VOID*)Tcl_DStringValue(&ds), (size_t) len); |
| 3905 |
|
| 3906 |
Tcl_DStringFree(&ds); |
| 3907 |
return (ClientData)nativePathPtr; |
| 3908 |
} |
| 3909 |
|
| 3910 |
|
| 3911 |
|
| 3912 |
|
| 3913 |
|
| 3914 |
|
| 3915 |
|
| 3916 |
|
| 3917 |
|
| 3918 |
|
| 3919 |
|
| 3920 |
|
| 3921 |
|
| 3922 |
|
| 3923 |
|
| 3924 |
|
| 3925 |
|
| 3926 |
Tcl_Obj* |
| 3927 |
TclpNativeToNormalized(clientData) |
| 3928 |
ClientData clientData; |
| 3929 |
{ |
| 3930 |
Tcl_DString ds; |
| 3931 |
Tcl_Obj *objPtr; |
| 3932 |
CONST char *copy; |
| 3933 |
int len; |
| 3934 |
|
| 3935 |
#ifdef __WIN32__ |
| 3936 |
Tcl_WinTCharToUtf((CONST char*)clientData, -1, &ds); |
| 3937 |
#else |
| 3938 |
Tcl_ExternalToUtfDString(NULL, (CONST char*)clientData, -1, &ds); |
| 3939 |
#endif |
| 3940 |
|
| 3941 |
copy = Tcl_DStringValue(&ds); |
| 3942 |
len = Tcl_DStringLength(&ds); |
| 3943 |
|
| 3944 |
#ifdef __WIN32__ |
| 3945 |
|
| 3946 |
|
| 3947 |
|
| 3948 |
|
| 3949 |
|
| 3950 |
if (*copy == '\\') { |
| 3951 |
if (0 == strncmp(copy,"\\??\\",4)) { |
| 3952 |
copy += 4; |
| 3953 |
len -= 4; |
| 3954 |
} else if (0 == strncmp(copy,"\\\\?\\",4)) { |
| 3955 |
copy += 4; |
| 3956 |
len -= 4; |
| 3957 |
} |
| 3958 |
} |
| 3959 |
#endif |
| 3960 |
|
| 3961 |
objPtr = Tcl_NewStringObj(copy,len); |
| 3962 |
Tcl_DStringFree(&ds); |
| 3963 |
|
| 3964 |
return objPtr; |
| 3965 |
} |
| 3966 |
|
| 3967 |
|
| 3968 |
|
| 3969 |
|
| 3970 |
|
| 3971 |
|
| 3972 |
|
| 3973 |
|
| 3974 |
|
| 3975 |
|
| 3976 |
|
| 3977 |
|
| 3978 |
|
| 3979 |
|
| 3980 |
|
| 3981 |
|
| 3982 |
|
| 3983 |
|
| 3984 |
ClientData |
| 3985 |
NativeDupInternalRep(clientData) |
| 3986 |
ClientData clientData; |
| 3987 |
{ |
| 3988 |
ClientData copy; |
| 3989 |
size_t len; |
| 3990 |
|
| 3991 |
if (clientData == NULL) { |
| 3992 |
return NULL; |
| 3993 |
} |
| 3994 |
|
| 3995 |
#ifdef __WIN32__ |
| 3996 |
if (tclWinProcs->useWide) { |
| 3997 |
|
| 3998 |
len = sizeof(WCHAR) + (wcslen((CONST WCHAR*)clientData) * sizeof(WCHAR)); |
| 3999 |
} else { |
| 4000 |
|
| 4001 |
len = sizeof(char) + (strlen((CONST char*)clientData) * sizeof(char)); |
| 4002 |
} |
| 4003 |
#else |
| 4004 |
|
| 4005 |
len = sizeof(char) + (strlen((CONST char*)clientData) * sizeof(char)); |
| 4006 |
#endif |
| 4007 |
|
| 4008 |
copy = (ClientData) ckalloc(len); |
| 4009 |
memcpy((VOID*)copy, (VOID*)clientData, len); |
| 4010 |
return copy; |
| 4011 |
} |
| 4012 |
|
| 4013 |
|
| 4014 |
|
| 4015 |
|
| 4016 |
|
| 4017 |
|
| 4018 |
|
| 4019 |
|
| 4020 |
|
| 4021 |
|
| 4022 |
|
| 4023 |
|
| 4024 |
|
| 4025 |
|
| 4026 |
|
| 4027 |
|
| 4028 |
static void |
| 4029 |
NativeFreeInternalRep(clientData) |
| 4030 |
ClientData clientData; |
| 4031 |
{ |
| 4032 |
ckfree((char*)clientData); |
| 4033 |
} |
| 4034 |
|
| 4035 |
|
| 4036 |
|
| 4037 |
|
| 4038 |
|
| 4039 |
|
| 4040 |
|
| 4041 |
|
| 4042 |
|
| 4043 |
|
| 4044 |
|
| 4045 |
|
| 4046 |
|
| 4047 |
|
| 4048 |
|
| 4049 |
|
| 4050 |
|
| 4051 |
|
| 4052 |
|
| 4053 |
Tcl_Obj* |
| 4054 |
Tcl_FSFileSystemInfo(pathObjPtr) |
| 4055 |
Tcl_Obj* pathObjPtr; |
| 4056 |
{ |
| 4057 |
Tcl_Obj *resPtr; |
| 4058 |
Tcl_FSFilesystemPathTypeProc *proc; |
| 4059 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathObjPtr); |
| 4060 |
|
| 4061 |
if (fsPtr == NULL) { |
| 4062 |
return NULL; |
| 4063 |
} |
| 4064 |
|
| 4065 |
resPtr = Tcl_NewListObj(0,NULL); |
| 4066 |
|
| 4067 |
Tcl_ListObjAppendElement(NULL, resPtr, |
| 4068 |
Tcl_NewStringObj(fsPtr->typeName,-1)); |
| 4069 |
|
| 4070 |
proc = fsPtr->filesystemPathTypeProc; |
| 4071 |
if (proc != NULL) { |
| 4072 |
Tcl_Obj *typePtr = (*proc)(pathObjPtr); |
| 4073 |
if (typePtr != NULL) { |
| 4074 |
Tcl_ListObjAppendElement(NULL, resPtr, typePtr); |
| 4075 |
} |
| 4076 |
} |
| 4077 |
|
| 4078 |
return resPtr; |
| 4079 |
} |
| 4080 |
|
| 4081 |
|
| 4082 |
|
| 4083 |
|
| 4084 |
|
| 4085 |
|
| 4086 |
|
| 4087 |
|
| 4088 |
|
| 4089 |
|
| 4090 |
|
| 4091 |
|
| 4092 |
|
| 4093 |
|
| 4094 |
|
| 4095 |
|
| 4096 |
|
| 4097 |
|
| 4098 |
|
| 4099 |
Tcl_Obj* |
| 4100 |
Tcl_FSPathSeparator(pathObjPtr) |
| 4101 |
Tcl_Obj* pathObjPtr; |
| 4102 |
{ |
| 4103 |
Tcl_Filesystem *fsPtr = Tcl_FSGetFileSystemForPath(pathObjPtr); |
| 4104 |
|
| 4105 |
if (fsPtr == NULL) { |
| 4106 |
return NULL; |
| 4107 |
} |
| 4108 |
if (fsPtr->filesystemSeparatorProc != NULL) { |
| 4109 |
return (*fsPtr->filesystemSeparatorProc)(pathObjPtr); |
| 4110 |
} |
| 4111 |
|
| 4112 |
return NULL; |
| 4113 |
} |
| 4114 |
|
| 4115 |
|
| 4116 |
|
| 4117 |
|
| 4118 |
|
| 4119 |
|
| 4120 |
|
| 4121 |
|
| 4122 |
|
| 4123 |
|
| 4124 |
|
| 4125 |
|
| 4126 |
|
| 4127 |
|
| 4128 |
|
| 4129 |
|
| 4130 |
|
| 4131 |
static Tcl_Obj* |
| 4132 |
NativeFilesystemSeparator(pathObjPtr) |
| 4133 |
Tcl_Obj* pathObjPtr; |
| 4134 |
{ |
| 4135 |
char *separator = NULL; |
| 4136 |
switch (tclPlatform) { |
| 4137 |
case TCL_PLATFORM_UNIX: |
| 4138 |
separator = "/"; |
| 4139 |
break; |
| 4140 |
case TCL_PLATFORM_WINDOWS: |
| 4141 |
separator = "\\"; |
| 4142 |
break; |
| 4143 |
case TCL_PLATFORM_MAC: |
| 4144 |
separator = ":"; |
| 4145 |
break; |
| 4146 |
} |
| 4147 |
return Tcl_NewStringObj(separator,1); |
| 4148 |
} |
| 4149 |
|
| 4150 |
|
| 4151 |
#ifdef USE_OBSOLETE_FS_HOOKS |
| 4152 |
|
| 4153 |
|
| 4154 |
|
| 4155 |
|
| 4156 |
|
| 4157 |
|
| 4158 |
|
| 4159 |
|
| 4160 |
|
| 4161 |
|
| 4162 |
|
| 4163 |
|
| 4164 |
|
| 4165 |
|
| 4166 |
|
| 4167 |
|
| 4168 |
|
| 4169 |
|
| 4170 |
|
| 4171 |
|
| 4172 |
|
| 4173 |
|
| 4174 |
|
| 4175 |
int |
| 4176 |
TclStatInsertProc (proc) |
| 4177 |
TclStatProc_ *proc; |
| 4178 |
{ |
| 4179 |
int retVal = TCL_ERROR; |
| 4180 |
|
| 4181 |
if (proc != NULL) { |
| 4182 |
StatProc *newStatProcPtr; |
| 4183 |
|
| 4184 |
newStatProcPtr = (StatProc *)ckalloc(sizeof(StatProc)); |
| 4185 |
|
| 4186 |
if (newStatProcPtr != NULL) { |
| 4187 |
newStatProcPtr->proc = proc; |
| 4188 |
Tcl_MutexLock(&obsoleteFsHookMutex); |
| 4189 |
newStatProcPtr->nextPtr = statProcList; |
| 4190 |
statProcList = newStatProcPtr; |
| 4191 |
Tcl_MutexUnlock(&obsoleteFsHookMutex); |
| 4192 |
|
| 4193 |
retVal = TCL_OK; |
| 4194 |
} |
| 4195 |
} |
| 4196 |
|
| 4197 |
return retVal; |
| 4198 |
} |
| 4199 |
|
| 4200 |
|
| 4201 |
|
| 4202 |
|
| 4203 |
|
| 4204 |
|
| 4205 |
|
| 4206 |
|
| 4207 |
|
| 4208 |
|
| 4209 |
|
| 4210 |
|
| 4211 |
|
| 4212 |
|
| 4213 |
|
| 4214 |
|
| 4215 |
|
| 4216 |
|
| 4217 |
|
| 4218 |
|
| 4219 |
int |
| 4220 |
TclStatDeleteProc (proc) |
| 4221 |
TclStatProc_ *proc; |
| 4222 |
{ |
| 4223 |
int retVal = TCL_ERROR; |
| 4224 |
StatProc *tmpStatProcPtr; |
| 4225 |
StatProc *prevStatProcPtr = NULL; |
| 4226 |
|
| 4227 |
Tcl_MutexLock(&obsoleteFsHookMutex); |
| 4228 |
tmpStatProcPtr = statProcList; |
| 4229 |
|
| 4230 |
|
| 4231 |
|
| 4232 |
|
| 4233 |
|
| 4234 |
|
| 4235 |
while ((retVal == TCL_ERROR) && (tmpStatProcPtr != NULL)) { |
| 4236 |
if (tmpStatProcPtr->proc == proc) { |
| 4237 |
if (prevStatProcPtr == NULL) { |
| 4238 |
statProcList = tmpStatProcPtr->nextPtr; |
| 4239 |
} else { |
| 4240 |
prevStatProcPtr->nextPtr = tmpStatProcPtr->nextPtr; |
| 4241 |
} |
| 4242 |
|
| 4243 |
ckfree((char *)tmpStatProcPtr); |
| 4244 |
|
| 4245 |
retVal = TCL_OK; |
| 4246 |
} else { |
| 4247 |
prevStatProcPtr = tmpStatProcPtr; |
| 4248 |
tmpStatProcPtr = tmpStatProcPtr->nextPtr; |
| 4249 |
} |
| 4250 |
} |
| 4251 |
|
| 4252 |
Tcl_MutexUnlock(&obsoleteFsHookMutex); |
| 4253 |
|
| 4254 |
return retVal; |
| 4255 |
} |
| 4256 |
|
| 4257 |
|
| 4258 |
|
| 4259 |
|
| 4260 |
|
| 4261 |
|
| 4262 |
|
| 4263 |
|
| 4264 |
|
| 4265 |
|
| 4266 |
|
| 4267 |
|
| 4268 |
|
| 4269 |
|
| 4270 |
|
| 4271 |
|
| 4272 |
|
| 4273 |
|
| 4274 |
|
| 4275 |
|
| 4276 |
|
| 4277 |
|
| 4278 |
|
| 4279 |
|
| 4280 |
int |
| 4281 |
TclAccessInsertProc(proc) |
| 4282 |
TclAccessProc_ *proc; |
| 4283 |
{ |
| 4284 |
int retVal = TCL_ERROR; |
| 4285 |
|
| 4286 |
if (proc != NULL) { |
| 4287 |
AccessProc *newAccessProcPtr; |
| 4288 |
|
| 4289 |
newAccessProcPtr = (AccessProc *)ckalloc(sizeof(AccessProc)); |
| 4290 |
|
| 4291 |
if (newAccessProcPtr != NULL) { |
| 4292 |
newAccessProcPtr->proc = proc; |
| 4293 |
Tcl_MutexLock(&obsoleteFsHookMutex); |
| 4294 |
newAccessProcPtr->nextPtr = accessProcList; |
| 4295 |
accessProcList = newAccessProcPtr; |
| 4296 |
Tcl_MutexUnlock(&obsoleteFsHookMutex); |
| 4297 |
|
| 4298 |
retVal = TCL_OK; |
| 4299 |
} |
| 4300 |
} |
| 4301 |
|
| 4302 |
return retVal; |
| 4303 |
} |
| 4304 |
|
| 4305 |
|
| 4306 |
|
| 4307 |
|
| 4308 |
|
| 4309 |
|
| 4310 |
|
| 4311 |
|
| 4312 |
|
| 4313 |
|
| 4314 |
|
| 4315 |
|
| 4316 |
|
| 4317 |
|
| 4318 |
|
| 4319 |
|
| 4320 |
|
| 4321 |
|
| 4322 |
|
| 4323 |
|
| 4324 |
int |
| 4325 |
TclAccessDeleteProc(proc) |
| 4326 |
TclAccessProc_ *proc; |
| 4327 |
{ |
| 4328 |
int retVal = TCL_ERROR; |
| 4329 |
AccessProc *tmpAccessProcPtr; |
| 4330 |
AccessProc *prevAccessProcPtr = NULL; |
| 4331 |
|
| 4332 |
|
| 4333 |
|
| 4334 |
|
| 4335 |
|
| 4336 |
|
| 4337 |
|
| 4338 |
Tcl_MutexLock(&obsoleteFsHookMutex); |
| 4339 |
tmpAccessProcPtr = accessProcList; |
| 4340 |
while ((retVal == TCL_ERROR) && (tmpAccessProcPtr != NULL)) { |
| 4341 |
if (tmpAccessProcPtr->proc == proc) { |
| 4342 |
if (prevAccessProcPtr == NULL) { |
| 4343 |
accessProcList = tmpAccessProcPtr->nextPtr; |
| 4344 |
} else { |
| 4345 |
prevAccessProcPtr->nextPtr = tmpAccessProcPtr->nextPtr; |
| 4346 |
} |
| 4347 |
|
| 4348 |
ckfree((char *)tmpAccessProcPtr); |
| 4349 |
|
| 4350 |
retVal = TCL_OK; |
| 4351 |
} else { |
| 4352 |
prevAccessProcPtr = tmpAccessProcPtr; |
| 4353 |
tmpAccessProcPtr = tmpAccessProcPtr->nextPtr; |
| 4354 |
} |
| 4355 |
} |
| 4356 |
Tcl_MutexUnlock(&obsoleteFsHookMutex); |
| 4357 |
|
| 4358 |
return retVal; |
| 4359 |
} |
| 4360 |
|
| 4361 |
|
| 4362 |
|
| 4363 |
|
| 4364 |
|
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
|
| 4369 |
|
| 4370 |
|
| 4371 |
|
| 4372 |
|
| 4373 |
|
| 4374 |
|
| 4375 |
|
| 4376 |
|
| 4377 |
|
| 4378 |
|
| 4379 |
|
| 4380 |
|
| 4381 |
|
| 4382 |
|
| 4383 |
|
| 4384 |
int |
| 4385 |
TclOpenFileChannelInsertProc(proc) |
| 4386 |
TclOpenFileChannelProc_ *proc; |
| 4387 |
{ |
| 4388 |
int retVal = TCL_ERROR; |
| 4389 |
|
| 4390 |
if (proc != NULL) { |
| 4391 |
OpenFileChannelProc *newOpenFileChannelProcPtr; |
| 4392 |
|
| 4393 |
newOpenFileChannelProcPtr = |
| 4394 |
(OpenFileChannelProc *)ckalloc(sizeof(OpenFileChannelProc)); |
| 4395 |
|
| 4396 |
if (newOpenFileChannelProcPtr != NULL) { |
| 4397 |
newOpenFileChannelProcPtr->proc = proc; |
| 4398 |
Tcl_MutexLock(&obsoleteFsHookMutex); |
| 4399 |
newOpenFileChannelProcPtr->nextPtr = openFileChannelProcList; |
| 4400 |
openFileChannelProcList = newOpenFileChannelProcPtr; |
| 4401 |
Tcl_MutexUnlock(&obsoleteFsHookMutex); |
| 4402 |
|
| 4403 |
retVal = TCL_OK; |
| 4404 |
} |
| 4405 |
} |
| 4406 |
|
| 4407 |
return retVal; |
| 4408 |
} |
| 4409 |
|
| 4410 |
|
| 4411 |
|
| 4412 |
|
| 4413 |
|
| 4414 |
|
| 4415 |
|
| 4416 |
|
| 4417 |
|
| 4418 |
|
| 4419 |
|
| 4420 |
|
| 4421 |
|
| 4422 |
|
| 4423 |
|
| 4424 |
|
| 4425 |
|
| 4426 |
|
| 4427 |
|
| 4428 |
|
| 4429 |
int |
| 4430 |
TclOpenFileChannelDeleteProc(proc) |
| 4431 |
TclOpenFileChannelProc_ *proc; |
| 4432 |
{ |
| 4433 |
int retVal = TCL_ERROR; |
| 4434 |
OpenFileChannelProc *tmpOpenFileChannelProcPtr = openFileChannelProcList; |
| 4435 |
OpenFileChannelProc *prevOpenFileChannelProcPtr = NULL; |
| 4436 |
|
| 4437 |
|
| 4438 |
|
| 4439 |
|
| 4440 |
|
| 4441 |
|
| 4442 |
|
| 4443 |
Tcl_MutexLock(&obsoleteFsHookMutex); |
| 4444 |
tmpOpenFileChannelProcPtr = openFileChannelProcList; |
| 4445 |
while ((retVal == TCL_ERROR) && |
| 4446 |
(tmpOpenFileChannelProcPtr != NULL)) { |
| 4447 |
if (tmpOpenFileChannelProcPtr->proc == proc) { |
| 4448 |
if (prevOpenFileChannelProcPtr == NULL) { |
| 4449 |
openFileChannelProcList = tmpOpenFileChannelProcPtr->nextPtr; |
| 4450 |
} else { |
| 4451 |
prevOpenFileChannelProcPtr->nextPtr = |
| 4452 |
tmpOpenFileChannelProcPtr->nextPtr; |
| 4453 |
} |
| 4454 |
|
| 4455 |
ckfree((char *)tmpOpenFileChannelProcPtr); |
| 4456 |
|
| 4457 |
retVal = TCL_OK; |
| 4458 |
} else { |
| 4459 |
prevOpenFileChannelProcPtr = tmpOpenFileChannelProcPtr; |
| 4460 |
tmpOpenFileChannelProcPtr = tmpOpenFileChannelProcPtr->nextPtr; |
| 4461 |
} |
| 4462 |
} |
| 4463 |
Tcl_MutexUnlock(&obsoleteFsHookMutex); |
| 4464 |
|
| 4465 |
return retVal; |
| 4466 |
} |
| 4467 |
#endif |
| 4468 |
|
| 4469 |
|
| 4470 |
|
| 4471 |
|
| 4472 |
|
| 4473 |
|
| 4474 |
static void DupFsPathInternalRep _ANSI_ARGS_((Tcl_Obj *srcPtr, |
| 4475 |
Tcl_Obj *copyPtr)); |
| 4476 |
static void FreeFsPathInternalRep _ANSI_ARGS_((Tcl_Obj *listPtr)); |
| 4477 |
static void UpdateStringOfFsPath _ANSI_ARGS_((Tcl_Obj *objPtr)); |
| 4478 |
static int SetFsPathFromAny _ANSI_ARGS_((Tcl_Interp *interp, |
| 4479 |
Tcl_Obj *objPtr)); |
| 4480 |
static int FindSplitPos _ANSI_ARGS_((char *path, char *separator)); |
| 4481 |
|
| 4482 |
|
| 4483 |
|
| 4484 |
|
| 4485 |
|
| 4486 |
|
| 4487 |
|
| 4488 |
Tcl_ObjType tclFsPathType = { |
| 4489 |
"path", |
| 4490 |
FreeFsPathInternalRep, |
| 4491 |
DupFsPathInternalRep, |
| 4492 |
UpdateStringOfFsPath, |
| 4493 |
SetFsPathFromAny |
| 4494 |
}; |
| 4495 |
|
| 4496 |
|
| 4497 |
|
| 4498 |
|
| 4499 |
|
| 4500 |
|
| 4501 |
|
| 4502 |
|
| 4503 |
|
| 4504 |
|
| 4505 |
|
| 4506 |
|
| 4507 |
typedef struct FsPath { |
| 4508 |
Tcl_Obj *translatedPathPtr; |
| 4509 |
|
| 4510 |
|
| 4511 |
|
| 4512 |
|
| 4513 |
|
| 4514 |
Tcl_Obj *normPathPtr; |
| 4515 |
|
| 4516 |
|
| 4517 |
|
| 4518 |
|
| 4519 |
|
| 4520 |
|
| 4521 |
Tcl_Obj *cwdPtr; |
| 4522 |
|
| 4523 |
|
| 4524 |
|
| 4525 |
int flags; |
| 4526 |
ClientData nativePathPtr; |
| 4527 |
|
| 4528 |
int filesystemEpoch; |
| 4529 |
|
| 4530 |
|
| 4531 |
|
| 4532 |
struct FilesystemRecord *fsRecPtr; |
| 4533 |
|
| 4534 |
|
| 4535 |
} FsPath; |
| 4536 |
|
| 4537 |
|
| 4538 |
|
| 4539 |
|
| 4540 |
|
| 4541 |
#define PATHOBJ(objPtr) (objPtr->internalRep.otherValuePtr) |
| 4542 |
#define PATHFLAGS(objPtr) \ |
| 4543 |
(((FsPath*)(objPtr->internalRep.otherValuePtr))->flags) |
| 4544 |
|
| 4545 |
#define TCLPATH_APPENDED 1 |
| 4546 |
#define TCLPATH_RELATIVE 2 |
| 4547 |
|
| 4548 |
|
| 4549 |
|
| 4550 |
|
| 4551 |
|
| 4552 |
|
| 4553 |
|
| 4554 |
|
| 4555 |
|
| 4556 |
|
| 4557 |
|
| 4558 |
|
| 4559 |
|
| 4560 |
|
| 4561 |
|
| 4562 |
|
| 4563 |
|
| 4564 |
|
| 4565 |
|
| 4566 |
Tcl_PathType |
| 4567 |
Tcl_FSGetPathType(pathObjPtr) |
| 4568 |
Tcl_Obj *pathObjPtr; |
| 4569 |
{ |
| 4570 |
return FSGetPathType(pathObjPtr, NULL, NULL); |
| 4571 |
} |
| 4572 |
|
| 4573 |
|
| 4574 |
|
| 4575 |
|
| 4576 |
|
| 4577 |
|
| 4578 |
|
| 4579 |
|
| 4580 |
|
| 4581 |
|
| 4582 |
|
| 4583 |
|
| 4584 |
|
| 4585 |
|
| 4586 |
|
| 4587 |
|
| 4588 |
|
| 4589 |
|
| 4590 |
|
| 4591 |
|
| 4592 |
|
| 4593 |
|
| 4594 |
|
| 4595 |
|
| 4596 |
|
| 4597 |
Tcl_PathType |
| 4598 |
FSGetPathType(pathObjPtr, filesystemPtrPtr, driveNameLengthPtr) |
| 4599 |
Tcl_Obj *pathObjPtr; |
| 4600 |
Tcl_Filesystem **filesystemPtrPtr; |
| 4601 |
int *driveNameLengthPtr; |
| 4602 |
{ |
| 4603 |
if (Tcl_FSConvertToPathType(NULL, pathObjPtr) != TCL_OK) { |
| 4604 |
return GetPathType(pathObjPtr, filesystemPtrPtr, |
| 4605 |
driveNameLengthPtr, NULL); |
| 4606 |
} else { |
| 4607 |
FsPath *fsPathPtr = (FsPath*) PATHOBJ(pathObjPtr); |
| 4608 |
if (fsPathPtr->cwdPtr != NULL) { |
| 4609 |
if (PATHFLAGS(pathObjPtr) == 0) { |
| 4610 |
return TCL_PATH_RELATIVE; |
| 4611 |
} |
| 4612 |
return FSGetPathType(fsPathPtr->cwdPtr, filesystemPtrPtr, |
| 4613 |
driveNameLengthPtr); |
| 4614 |
} else { |
| 4615 |
return GetPathType(pathObjPtr, filesystemPtrPtr, |
| 4616 |
driveNameLengthPtr, NULL); |
| 4617 |
} |
| 4618 |
} |
| 4619 |
} |
| 4620 |
|
| 4621 |
|
| 4622 |
|
| 4623 |
|
| 4624 |
|
| 4625 |
|
| 4626 |
|
| 4627 |
|
| 4628 |
|
| 4629 |
|
| 4630 |
|
| 4631 |
|
| 4632 |
|
| 4633 |
|
| 4634 |
|
| 4635 |
|
| 4636 |
|
| 4637 |
|
| 4638 |
|
| 4639 |
|
| 4640 |
|
| 4641 |
Tcl_Obj* |
| 4642 |
Tcl_FSJoinPath(listObj, elements) |
| 4643 |
Tcl_Obj *listObj; |
| 4644 |
int elements; |
| 4645 |
{ |
| 4646 |
Tcl_Obj *res; |
| 4647 |
int i; |
| 4648 |
Tcl_Filesystem *fsPtr = NULL; |
| 4649 |
|
| 4650 |
if (elements < 0) { |
| 4651 |
if (Tcl_ListObjLength(NULL, listObj, &elements) != TCL_OK) { |
| 4652 |
return NULL; |
| 4653 |
} |
| 4654 |
} else { |
| 4655 |
|
| 4656 |
int listTest; |
| 4657 |
if (Tcl_ListObjLength(NULL, listObj, &listTest) != TCL_OK) { |
| 4658 |
return NULL; |
| 4659 |
} |
| 4660 |
|
| 4661 |
|
| 4662 |
|
| 4663 |
|
| 4664 |
if (elements > listTest) { |
| 4665 |
elements = listTest; |
| 4666 |
} |
| 4667 |
} |
| 4668 |
|
| 4669 |
res = Tcl_NewObj(); |
| 4670 |
|
| 4671 |
for (i = 0; i < elements; i++) { |
| 4672 |
Tcl_Obj *elt; |
| 4673 |
int driveNameLength; |
| 4674 |
Tcl_PathType type; |
| 4675 |
char *strElt; |
| 4676 |
int strEltLen; |
| 4677 |
int length; |
| 4678 |
char *ptr; |
| 4679 |
Tcl_Obj *driveName = NULL; |
| 4680 |
|
| 4681 |
Tcl_ListObjIndex(NULL, listObj, i, &elt); |
| 4682 |
|
| 4683 |
|
| 4684 |
|
| 4685 |
|
| 4686 |
|
| 4687 |
|
| 4688 |
|
| 4689 |
|
| 4690 |
|
| 4691 |
|
| 4692 |
if ((i == (elements-2)) && (i == 0) && (elt->typePtr == &tclFsPathType) |
| 4693 |
&& !(elt->bytes != NULL && (elt->bytes[0] == '\0'))) { |
| 4694 |
Tcl_Obj *tail; |
| 4695 |
Tcl_PathType type; |
| 4696 |
Tcl_ListObjIndex(NULL, listObj, i+1, &tail); |
| 4697 |
type = GetPathType(tail, NULL, NULL, NULL); |
| 4698 |
if (type == TCL_PATH_RELATIVE) { |
| 4699 |
CONST char *str; |
| 4700 |
int len; |
| 4701 |
str = Tcl_GetStringFromObj(tail,&len); |
| 4702 |
if (len == 0) { |
| 4703 |
|
| 4704 |
|
| 4705 |
|
| 4706 |
|
| 4707 |
|
| 4708 |
Tcl_DecrRefCount(res); |
| 4709 |
return elt; |
| 4710 |
} |
| 4711 |
|
| 4712 |
|
| 4713 |
|
| 4714 |
|
| 4715 |
|
| 4716 |
|
| 4717 |
|
| 4718 |
|
| 4719 |
|
| 4720 |
if (str[0] != '.' && ((tclPlatform != TCL_PLATFORM_WINDOWS) |
| 4721 |
|| (strchr(str, '\\') == NULL))) { |
| 4722 |
Tcl_DecrRefCount(res); |
| 4723 |
return TclNewFSPathObj(elt, str, len); |
| 4724 |
} |
| 4725 |
|
| 4726 |
|
| 4727 |
|
| 4728 |
|
| 4729 |
|
| 4730 |
} else { |
| 4731 |
if (tclPlatform == TCL_PLATFORM_UNIX) { |
| 4732 |
Tcl_DecrRefCount(res); |
| 4733 |
return tail; |
| 4734 |
} else { |
| 4735 |
CONST char *str; |
| 4736 |
int len; |
| 4737 |
str = Tcl_GetStringFromObj(tail,&len); |
| 4738 |
if (tclPlatform == TCL_PLATFORM_WINDOWS) { |
| 4739 |
if (strchr(str, '\\') == NULL) { |
| 4740 |
Tcl_DecrRefCount(res); |
| 4741 |
return tail; |
| 4742 |
} |
| 4743 |
} else if (tclPlatform == TCL_PLATFORM_MAC) { |
| 4744 |
if (strchr(str, '/') == NULL) { |
| 4745 |
Tcl_DecrRefCount(res); |
| 4746 |
return tail; |
| 4747 |
} |
| 4748 |
} |
| 4749 |
} |
| 4750 |
} |
| 4751 |
} |
| 4752 |
strElt = Tcl_GetStringFromObj(elt, &strEltLen); |
| 4753 |
type = GetPathType(elt, &fsPtr, &driveNameLength, &driveName); |
| 4754 |
if (type != TCL_PATH_RELATIVE) { |
| 4755 |
|
| 4756 |
Tcl_DecrRefCount(res); |
| 4757 |
if (driveName != NULL) { |
| 4758 |
res = Tcl_DuplicateObj(driveName); |
| 4759 |
Tcl_DecrRefCount(driveName); |
| 4760 |
} else { |
| 4761 |
res = Tcl_NewStringObj(strElt, driveNameLength); |
| 4762 |
} |
| 4763 |
strElt += driveNameLength; |
| 4764 |
} |
| 4765 |
|
| 4766 |
ptr = Tcl_GetStringFromObj(res, &length); |
| 4767 |
|
| 4768 |
|
| 4769 |
|
| 4770 |
|
| 4771 |
|
| 4772 |
if (length > 0 && strEltLen > 0) { |
| 4773 |
if ((strElt[0] == '.') && (strElt[1] == '/') |
| 4774 |
&& (strElt[2] == '~')) { |
| 4775 |
strElt += 2; |
| 4776 |
} |
| 4777 |
} |
| 4778 |
|
| 4779 |
|
| 4780 |
|
| 4781 |
|
| 4782 |
|
| 4783 |
|
| 4784 |
|
| 4785 |
if (*strElt == '\0') continue; |
| 4786 |
|
| 4787 |
if (fsPtr == &tclNativeFilesystem || fsPtr == NULL) { |
| 4788 |
TclpNativeJoinPath(res, strElt); |
| 4789 |
} else { |
| 4790 |
char separator = '/'; |
| 4791 |
int needsSep = 0; |
| 4792 |
|
| 4793 |
if (fsPtr->filesystemSeparatorProc != NULL) { |
| 4794 |
Tcl_Obj *sep = (*fsPtr->filesystemSeparatorProc)(res); |
| 4795 |
if (sep != NULL) { |
| 4796 |
separator = Tcl_GetString(sep)[0]; |
| 4797 |
} |
| 4798 |
} |
| 4799 |
|
| 4800 |
if (length > 0 && ptr[length -1] != '/') { |
| 4801 |
Tcl_AppendToObj(res, &separator, 1); |
| 4802 |
length++; |
| 4803 |
} |
| 4804 |
Tcl_SetObjLength(res, length + (int) strlen(strElt)); |
| 4805 |
|
| 4806 |
ptr = Tcl_GetString(res) + length; |
| 4807 |
for (; *strElt != '\0'; strElt++) { |
| 4808 |
if (*strElt == separator) { |
| 4809 |
while (strElt[1] == separator) { |
| 4810 |
strElt++; |
| 4811 |
} |
| 4812 |
if (strElt[1] != '\0') { |
| 4813 |
if (needsSep) { |
| 4814 |
*ptr++ = separator; |
| 4815 |
} |
| 4816 |
} |
| 4817 |
} else { |
| 4818 |
*ptr++ = *strElt; |
| 4819 |
needsSep = 1; |
| 4820 |
} |
| 4821 |
} |
| 4822 |
length = ptr - Tcl_GetString(res); |
| 4823 |
Tcl_SetObjLength(res, length); |
| 4824 |
} |
| 4825 |
} |
| 4826 |
return res; |
| 4827 |
} |
| 4828 |
|
| 4829 |
|
| 4830 |
|
| 4831 |
|
| 4832 |
|
| 4833 |
|
| 4834 |
|
| 4835 |
|
| 4836 |
|
| 4837 |
|
| 4838 |
|
| 4839 |
|
| 4840 |
|
| 4841 |
|
| 4842 |
|
| 4843 |
|
| 4844 |
|
| 4845 |
|
| 4846 |
|
| 4847 |
|
| 4848 |
|
| 4849 |
|
| 4850 |
|
| 4851 |
int |
| 4852 |
Tcl_FSConvertToPathType(interp, objPtr) |
| 4853 |
Tcl_Interp *interp; |
| 4854 |
|
| 4855 |
Tcl_Obj *objPtr; |
| 4856 |
|
| 4857 |
{ |
| 4858 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 4859 |
|
| 4860 |
|
| 4861 |
|
| 4862 |
|
| 4863 |
|
| 4864 |
|
| 4865 |
|
| 4866 |
|
| 4867 |
|
| 4868 |
|
| 4869 |
if (objPtr->typePtr == &tclFsPathType) { |
| 4870 |
FsPath *fsPathPtr = (FsPath*) PATHOBJ(objPtr); |
| 4871 |
if (fsPathPtr->filesystemEpoch != tsdPtr->filesystemEpoch) { |
| 4872 |
if (objPtr->bytes == NULL) { |
| 4873 |
UpdateStringOfFsPath(objPtr); |
| 4874 |
} |
| 4875 |
FreeFsPathInternalRep(objPtr); |
| 4876 |
objPtr->typePtr = NULL; |
| 4877 |
return Tcl_ConvertToType(interp, objPtr, &tclFsPathType); |
| 4878 |
} |
| 4879 |
return TCL_OK; |
| 4880 |
} else { |
| 4881 |
return Tcl_ConvertToType(interp, objPtr, &tclFsPathType); |
| 4882 |
} |
| 4883 |
} |
| 4884 |
|
| 4885 |
|
| 4886 |
|
| 4887 |
|
| 4888 |
|
| 4889 |
static int |
| 4890 |
FindSplitPos(path, separator) |
| 4891 |
char *path; |
| 4892 |
char *separator; |
| 4893 |
{ |
| 4894 |
int count = 0; |
| 4895 |
switch (tclPlatform) { |
| 4896 |
case TCL_PLATFORM_UNIX: |
| 4897 |
case TCL_PLATFORM_MAC: |
| 4898 |
while (path[count] != 0) { |
| 4899 |
if (path[count] == *separator) { |
| 4900 |
return count; |
| 4901 |
} |
| 4902 |
count++; |
| 4903 |
} |
| 4904 |
break; |
| 4905 |
|
| 4906 |
case TCL_PLATFORM_WINDOWS: |
| 4907 |
while (path[count] != 0) { |
| 4908 |
if (path[count] == *separator || path[count] == '\\') { |
| 4909 |
return count; |
| 4910 |
} |
| 4911 |
count++; |
| 4912 |
} |
| 4913 |
break; |
| 4914 |
} |
| 4915 |
return count; |
| 4916 |
} |
| 4917 |
|
| 4918 |
|
| 4919 |
|
| 4920 |
|
| 4921 |
|
| 4922 |
|
| 4923 |
|
| 4924 |
|
| 4925 |
|
| 4926 |
|
| 4927 |
|
| 4928 |
|
| 4929 |
|
| 4930 |
|
| 4931 |
|
| 4932 |
|
| 4933 |
|
| 4934 |
|
| 4935 |
|
| 4936 |
|
| 4937 |
|
| 4938 |
|
| 4939 |
|
| 4940 |
Tcl_Obj* |
| 4941 |
TclNewFSPathObj(Tcl_Obj *dirPtr, CONST char *addStrRep, int len) |
| 4942 |
{ |
| 4943 |
FsPath *fsPathPtr; |
| 4944 |
Tcl_Obj *objPtr; |
| 4945 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 4946 |
|
| 4947 |
objPtr = Tcl_NewObj(); |
| 4948 |
fsPathPtr = (FsPath*)ckalloc((unsigned)sizeof(FsPath)); |
| 4949 |
|
| 4950 |
if (tclPlatform == TCL_PLATFORM_MAC) { |
| 4951 |
|
| 4952 |
|
| 4953 |
|
| 4954 |
|
| 4955 |
|
| 4956 |
|
| 4957 |
if (addStrRep[0] == ':') { |
| 4958 |
addStrRep++; |
| 4959 |
len--; |
| 4960 |
} |
| 4961 |
} |
| 4962 |
|
| 4963 |
fsPathPtr->translatedPathPtr = NULL; |
| 4964 |
fsPathPtr->normPathPtr = Tcl_NewStringObj(addStrRep, len); |
| 4965 |
Tcl_IncrRefCount(fsPathPtr->normPathPtr); |
| 4966 |
fsPathPtr->cwdPtr = dirPtr; |
| 4967 |
Tcl_IncrRefCount(dirPtr); |
| 4968 |
fsPathPtr->nativePathPtr = NULL; |
| 4969 |
fsPathPtr->fsRecPtr = NULL; |
| 4970 |
fsPathPtr->filesystemEpoch = tsdPtr->filesystemEpoch; |
| 4971 |
|
| 4972 |
PATHOBJ(objPtr) = (VOID *) fsPathPtr; |
| 4973 |
PATHFLAGS(objPtr) = TCLPATH_RELATIVE | TCLPATH_APPENDED; |
| 4974 |
objPtr->typePtr = &tclFsPathType; |
| 4975 |
objPtr->bytes = NULL; |
| 4976 |
objPtr->length = 0; |
| 4977 |
|
| 4978 |
return objPtr; |
| 4979 |
} |
| 4980 |
|
| 4981 |
|
| 4982 |
|
| 4983 |
|
| 4984 |
|
| 4985 |
|
| 4986 |
|
| 4987 |
|
| 4988 |
|
| 4989 |
|
| 4990 |
|
| 4991 |
|
| 4992 |
|
| 4993 |
|
| 4994 |
|
| 4995 |
|
| 4996 |
|
| 4997 |
|
| 4998 |
Tcl_Obj* |
| 4999 |
TclFSMakePathRelative(interp, objPtr, cwdPtr) |
| 5000 |
Tcl_Interp *interp; |
| 5001 |
Tcl_Obj *objPtr; |
| 5002 |
Tcl_Obj *cwdPtr; |
| 5003 |
{ |
| 5004 |
int cwdLen, len; |
| 5005 |
CONST char *tempStr; |
| 5006 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 5007 |
|
| 5008 |
if (objPtr->typePtr == &tclFsPathType) { |
| 5009 |
FsPath *fsPathPtr = (FsPath*) PATHOBJ(objPtr); |
| 5010 |
if (PATHFLAGS(objPtr) != 0 |
| 5011 |
&& fsPathPtr->cwdPtr == cwdPtr) { |
| 5012 |
objPtr = fsPathPtr->normPathPtr; |
| 5013 |
|
| 5014 |
if (objPtr->typePtr != NULL) { |
| 5015 |
if (objPtr->bytes == NULL) { |
| 5016 |
if (objPtr->typePtr->updateStringProc == NULL) { |
| 5017 |
if (interp != NULL) { |
| 5018 |
Tcl_ResetResult(interp); |
| 5019 |
Tcl_AppendResult(interp, "can't find object", |
| 5020 |
"string representation", (char *) NULL); |
| 5021 |
} |
| 5022 |
return NULL; |
| 5023 |
} |
| 5024 |
objPtr->typePtr->updateStringProc(objPtr); |
| 5025 |
} |
| 5026 |
if ((objPtr->typePtr->freeIntRepProc) != NULL) { |
| 5027 |
(*objPtr->typePtr->freeIntRepProc)(objPtr); |
| 5028 |
} |
| 5029 |
} |
| 5030 |
|
| 5031 |
fsPathPtr = (FsPath*)ckalloc((unsigned)sizeof(FsPath)); |
| 5032 |
|
| 5033 |
|
| 5034 |
fsPathPtr->translatedPathPtr = objPtr; |
| 5035 |
fsPathPtr->normPathPtr = NULL; |
| 5036 |
fsPathPtr->cwdPtr = cwdPtr; |
| 5037 |
Tcl_IncrRefCount(cwdPtr); |
| 5038 |
fsPathPtr->nativePathPtr = NULL; |
| 5039 |
fsPathPtr->fsRecPtr = NULL; |
| 5040 |
fsPathPtr->filesystemEpoch = tsdPtr->filesystemEpoch; |
| 5041 |
|
| 5042 |
PATHOBJ(objPtr) = (VOID *) fsPathPtr; |
| 5043 |
PATHFLAGS(objPtr) = 0; |
| 5044 |
objPtr->typePtr = &tclFsPathType; |
| 5045 |
|
| 5046 |
return objPtr; |
| 5047 |
} |
| 5048 |
} |
| 5049 |
|
| 5050 |
|
| 5051 |
|
| 5052 |
|
| 5053 |
|
| 5054 |
|
| 5055 |
|
| 5056 |
|
| 5057 |
|
| 5058 |
|
| 5059 |
|
| 5060 |
|
| 5061 |
tempStr = Tcl_GetStringFromObj(cwdPtr, &cwdLen); |
| 5062 |
|
| 5063 |
|
| 5064 |
|
| 5065 |
|
| 5066 |
|
| 5067 |
|
| 5068 |
switch (tclPlatform) { |
| 5069 |
case TCL_PLATFORM_UNIX: |
| 5070 |
if (tempStr[cwdLen-1] != '/') { |
| 5071 |
cwdLen++; |
| 5072 |
} |
| 5073 |
break; |
| 5074 |
case TCL_PLATFORM_WINDOWS: |
| 5075 |
if (tempStr[cwdLen-1] != '/' |
| 5076 |
&& tempStr[cwdLen-1] != '\\') { |
| 5077 |
cwdLen++; |
| 5078 |
} |
| 5079 |
break; |
| 5080 |
case TCL_PLATFORM_MAC: |
| 5081 |
if (tempStr[cwdLen-1] != ':') { |
| 5082 |
cwdLen++; |
| 5083 |
} |
| 5084 |
break; |
| 5085 |
} |
| 5086 |
tempStr = Tcl_GetStringFromObj(objPtr, &len); |
| 5087 |
|
| 5088 |
return Tcl_NewStringObj(tempStr + cwdLen, len - cwdLen); |
| 5089 |
} |
| 5090 |
|
| 5091 |
|
| 5092 |
|
| 5093 |
|
| 5094 |
|
| 5095 |
|
| 5096 |
|
| 5097 |
|
| 5098 |
|
| 5099 |
|
| 5100 |
|
| 5101 |
|
| 5102 |
|
| 5103 |
|
| 5104 |
|
| 5105 |
|
| 5106 |
|
| 5107 |
|
| 5108 |
int |
| 5109 |
TclFSMakePathFromNormalized(interp, objPtr, nativeRep) |
| 5110 |
Tcl_Interp *interp; |
| 5111 |
Tcl_Obj *objPtr; |
| 5112 |
ClientData nativeRep; |
| 5113 |
|
| 5114 |
{ |
| 5115 |
FsPath *fsPathPtr; |
| 5116 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 5117 |
|
| 5118 |
if (objPtr->typePtr == &tclFsPathType) { |
| 5119 |
return TCL_OK; |
| 5120 |
} |
| 5121 |
|
| 5122 |
|
| 5123 |
if (objPtr->typePtr != NULL) { |
| 5124 |
if (objPtr->bytes == NULL) { |
| 5125 |
if (objPtr->typePtr->updateStringProc == NULL) { |
| 5126 |
if (interp != NULL) { |
| 5127 |
Tcl_ResetResult(interp); |
| 5128 |
Tcl_AppendResult(interp, "can't find object", |
| 5129 |
"string representation", (char *) NULL); |
| 5130 |
} |
| 5131 |
return TCL_ERROR; |
| 5132 |
} |
| 5133 |
objPtr->typePtr->updateStringProc(objPtr); |
| 5134 |
} |
| 5135 |
if ((objPtr->typePtr->freeIntRepProc) != NULL) { |
| 5136 |
(*objPtr->typePtr->freeIntRepProc)(objPtr); |
| 5137 |
} |
| 5138 |
} |
| 5139 |
|
| 5140 |
fsPathPtr = (FsPath*)ckalloc((unsigned)sizeof(FsPath)); |
| 5141 |
|
| 5142 |
fsPathPtr->translatedPathPtr = NULL; |
| 5143 |
fsPathPtr->normPathPtr = objPtr; |
| 5144 |
fsPathPtr->cwdPtr = NULL; |
| 5145 |
fsPathPtr->nativePathPtr = nativeRep; |
| 5146 |
fsPathPtr->fsRecPtr = NULL; |
| 5147 |
fsPathPtr->filesystemEpoch = tsdPtr->filesystemEpoch; |
| 5148 |
|
| 5149 |
PATHOBJ(objPtr) = (VOID *) fsPathPtr; |
| 5150 |
PATHFLAGS(objPtr) = 0; |
| 5151 |
objPtr->typePtr = &tclFsPathType; |
| 5152 |
|
| 5153 |
return TCL_OK; |
| 5154 |
} |
| 5155 |
|
| 5156 |
|
| 5157 |
|
| 5158 |
|
| 5159 |
|
| 5160 |
|
| 5161 |
|
| 5162 |
|
| 5163 |
|
| 5164 |
|
| 5165 |
|
| 5166 |
|
| 5167 |
|
| 5168 |
|
| 5169 |
|
| 5170 |
|
| 5171 |
|
| 5172 |
|
| 5173 |
|
| 5174 |
|
| 5175 |
|
| 5176 |
|
| 5177 |
|
| 5178 |
|
| 5179 |
|
| 5180 |
|
| 5181 |
|
| 5182 |
Tcl_Obj * |
| 5183 |
Tcl_FSNewNativePath(fromFilesystem, clientData) |
| 5184 |
Tcl_Filesystem* fromFilesystem; |
| 5185 |
ClientData clientData; |
| 5186 |
{ |
| 5187 |
Tcl_Obj *objPtr; |
| 5188 |
FsPath *fsPathPtr; |
| 5189 |
|
| 5190 |
FilesystemRecord *fsFromPtr; |
| 5191 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 5192 |
|
| 5193 |
objPtr = TclFSInternalToNormalized(fromFilesystem, clientData, &fsFromPtr); |
| 5194 |
if (objPtr == NULL) { |
| 5195 |
return NULL; |
| 5196 |
} |
| 5197 |
|
| 5198 |
|
| 5199 |
|
| 5200 |
|
| 5201 |
|
| 5202 |
if (objPtr->typePtr != NULL) { |
| 5203 |
if (objPtr->bytes == NULL) { |
| 5204 |
if (objPtr->typePtr->updateStringProc == NULL) { |
| 5205 |
return NULL; |
| 5206 |
} |
| 5207 |
objPtr->typePtr->updateStringProc(objPtr); |
| 5208 |
} |
| 5209 |
if ((objPtr->typePtr->freeIntRepProc) != NULL) { |
| 5210 |
(*objPtr->typePtr->freeIntRepProc)(objPtr); |
| 5211 |
} |
| 5212 |
} |
| 5213 |
|
| 5214 |
fsPathPtr = (FsPath*)ckalloc((unsigned)sizeof(FsPath)); |
| 5215 |
|
| 5216 |
fsPathPtr->translatedPathPtr = NULL; |
| 5217 |
|
| 5218 |
fsPathPtr->normPathPtr = objPtr; |
| 5219 |
fsPathPtr->cwdPtr = NULL; |
| 5220 |
fsPathPtr->nativePathPtr = clientData; |
| 5221 |
fsPathPtr->fsRecPtr = fsFromPtr; |
| 5222 |
fsPathPtr->fsRecPtr->fileRefCount++; |
| 5223 |
fsPathPtr->filesystemEpoch = tsdPtr->filesystemEpoch; |
| 5224 |
|
| 5225 |
PATHOBJ(objPtr) = (VOID *) fsPathPtr; |
| 5226 |
PATHFLAGS(objPtr) = 0; |
| 5227 |
objPtr->typePtr = &tclFsPathType; |
| 5228 |
|
| 5229 |
return objPtr; |
| 5230 |
} |
| 5231 |
|
| 5232 |
|
| 5233 |
|
| 5234 |
|
| 5235 |
|
| 5236 |
|
| 5237 |
|
| 5238 |
|
| 5239 |
|
| 5240 |
|
| 5241 |
|
| 5242 |
|
| 5243 |
|
| 5244 |
|
| 5245 |
|
| 5246 |
|
| 5247 |
|
| 5248 |
|
| 5249 |
|
| 5250 |
|
| 5251 |
|
| 5252 |
Tcl_Obj* |
| 5253 |
Tcl_FSGetTranslatedPath(interp, pathPtr) |
| 5254 |
Tcl_Interp *interp; |
| 5255 |
Tcl_Obj* pathPtr; |
| 5256 |
{ |
| 5257 |
Tcl_Obj *retObj = NULL; |
| 5258 |
FsPath *srcFsPathPtr; |
| 5259 |
|
| 5260 |
if (Tcl_FSConvertToPathType(interp, pathPtr) != TCL_OK) { |
| 5261 |
return NULL; |
| 5262 |
} |
| 5263 |
srcFsPathPtr = (FsPath*) PATHOBJ(pathPtr); |
| 5264 |
if (srcFsPathPtr->translatedPathPtr == NULL) { |
| 5265 |
if (PATHFLAGS(pathPtr) != 0) { |
| 5266 |
return Tcl_FSGetNormalizedPath(interp, pathPtr); |
| 5267 |
} |
| 5268 |
|
| 5269 |
|
| 5270 |
|
| 5271 |
|
| 5272 |
|
| 5273 |
|
| 5274 |
retObj = srcFsPathPtr->normPathPtr; |
| 5275 |
} else { |
| 5276 |
|
| 5277 |
retObj = srcFsPathPtr->translatedPathPtr; |
| 5278 |
} |
| 5279 |
|
| 5280 |
Tcl_IncrRefCount(retObj); |
| 5281 |
return retObj; |
| 5282 |
} |
| 5283 |
|
| 5284 |
|
| 5285 |
|
| 5286 |
|
| 5287 |
|
| 5288 |
|
| 5289 |
|
| 5290 |
|
| 5291 |
|
| 5292 |
|
| 5293 |
|
| 5294 |
|
| 5295 |
|
| 5296 |
|
| 5297 |
|
| 5298 |
|
| 5299 |
|
| 5300 |
|
| 5301 |
|
| 5302 |
|
| 5303 |
CONST char* |
| 5304 |
Tcl_FSGetTranslatedStringPath(interp, pathPtr) |
| 5305 |
Tcl_Interp *interp; |
| 5306 |
Tcl_Obj* pathPtr; |
| 5307 |
{ |
| 5308 |
Tcl_Obj *transPtr = Tcl_FSGetTranslatedPath(interp, pathPtr); |
| 5309 |
|
| 5310 |
if (transPtr != NULL) { |
| 5311 |
int len; |
| 5312 |
CONST char *result, *orig; |
| 5313 |
orig = Tcl_GetStringFromObj(transPtr, &len); |
| 5314 |
result = (char*) ckalloc((unsigned)(len+1)); |
| 5315 |
memcpy((VOID*) result, (VOID*) orig, (size_t) (len+1)); |
| 5316 |
Tcl_DecrRefCount(transPtr); |
| 5317 |
return result; |
| 5318 |
} |
| 5319 |
|
| 5320 |
return NULL; |
| 5321 |
} |
| 5322 |
|
| 5323 |
|
| 5324 |
|
| 5325 |
|
| 5326 |
|
| 5327 |
|
| 5328 |
|
| 5329 |
|
| 5330 |
|
| 5331 |
|
| 5332 |
|
| 5333 |
|
| 5334 |
|
| 5335 |
|
| 5336 |
|
| 5337 |
|
| 5338 |
|
| 5339 |
|
| 5340 |
|
| 5341 |
|
| 5342 |
Tcl_Obj* |
| 5343 |
Tcl_FSGetNormalizedPath(interp, pathObjPtr) |
| 5344 |
Tcl_Interp *interp; |
| 5345 |
Tcl_Obj* pathObjPtr; |
| 5346 |
{ |
| 5347 |
FsPath *fsPathPtr; |
| 5348 |
|
| 5349 |
if (Tcl_FSConvertToPathType(interp, pathObjPtr) != TCL_OK) { |
| 5350 |
return NULL; |
| 5351 |
} |
| 5352 |
fsPathPtr = (FsPath*) PATHOBJ(pathObjPtr); |
| 5353 |
|
| 5354 |
if (PATHFLAGS(pathObjPtr) != 0) { |
| 5355 |
|
| 5356 |
|
| 5357 |
|
| 5358 |
|
| 5359 |
Tcl_Obj *dir, *copy; |
| 5360 |
int cwdLen; |
| 5361 |
int pathType; |
| 5362 |
CONST char *cwdStr; |
| 5363 |
ClientData clientData = NULL; |
| 5364 |
|
| 5365 |
pathType = Tcl_FSGetPathType(fsPathPtr->cwdPtr); |
| 5366 |
dir = Tcl_FSGetNormalizedPath(interp, fsPathPtr->cwdPtr); |
| 5367 |
if (dir == NULL) { |
| 5368 |
return NULL; |
| 5369 |
} |
| 5370 |
if (pathObjPtr->bytes == NULL) { |
| 5371 |
UpdateStringOfFsPath(pathObjPtr); |
| 5372 |
} |
| 5373 |
copy = Tcl_DuplicateObj(dir); |
| 5374 |
Tcl_IncrRefCount(copy); |
| 5375 |
Tcl_IncrRefCount(dir); |
| 5376 |
|
| 5377 |
|
| 5378 |
cwdStr = Tcl_GetStringFromObj(copy, &cwdLen); |
| 5379 |
|
| 5380 |
|
| 5381 |
|
| 5382 |
|
| 5383 |
|
| 5384 |
|
| 5385 |
switch (tclPlatform) { |
| 5386 |
case TCL_PLATFORM_UNIX: |
| 5387 |
if (cwdStr[cwdLen-1] != '/') { |
| 5388 |
Tcl_AppendToObj(copy, "/", 1); |
| 5389 |
cwdLen++; |
| 5390 |
} |
| 5391 |
break; |
| 5392 |
case TCL_PLATFORM_WINDOWS: |
| 5393 |
if (cwdStr[cwdLen-1] != '/' |
| 5394 |
&& cwdStr[cwdLen-1] != '\\') { |
| 5395 |
Tcl_AppendToObj(copy, "/", 1); |
| 5396 |
cwdLen++; |
| 5397 |
} |
| 5398 |
break; |
| 5399 |
case TCL_PLATFORM_MAC: |
| 5400 |
if (cwdStr[cwdLen-1] != ':') { |
| 5401 |
Tcl_AppendToObj(copy, ":", 1); |
| 5402 |
cwdLen++; |
| 5403 |
} |
| 5404 |
break; |
| 5405 |
} |
| 5406 |
Tcl_AppendObjToObj(copy, fsPathPtr->normPathPtr); |
| 5407 |
|
| 5408 |
|
| 5409 |
|
| 5410 |
|
| 5411 |
|
| 5412 |
|
| 5413 |
|
| 5414 |
|
| 5415 |
TclFSNormalizeToUniquePath(interp, copy, cwdLen-1, |
| 5416 |
(fsPathPtr->nativePathPtr == NULL ? &clientData : NULL)); |
| 5417 |
|
| 5418 |
|
| 5419 |
if (pathType == TCL_PATH_RELATIVE) { |
| 5420 |
FsPath* origDirFsPathPtr; |
| 5421 |
Tcl_Obj *origDir = fsPathPtr->cwdPtr; |
| 5422 |
origDirFsPathPtr = (FsPath*) PATHOBJ(origDir); |
| 5423 |
|
| 5424 |
fsPathPtr->cwdPtr = origDirFsPathPtr->cwdPtr; |
| 5425 |
Tcl_IncrRefCount(fsPathPtr->cwdPtr); |
| 5426 |
|
| 5427 |
Tcl_DecrRefCount(fsPathPtr->normPathPtr); |
| 5428 |
fsPathPtr->normPathPtr = copy; |
| 5429 |
|
| 5430 |
Tcl_DecrRefCount(dir); |
| 5431 |
Tcl_DecrRefCount(origDir); |
| 5432 |
} else { |
| 5433 |
Tcl_DecrRefCount(fsPathPtr->cwdPtr); |
| 5434 |
fsPathPtr->cwdPtr = NULL; |
| 5435 |
Tcl_DecrRefCount(fsPathPtr->normPathPtr); |
| 5436 |
fsPathPtr->normPathPtr = copy; |
| 5437 |
|
| 5438 |
Tcl_DecrRefCount(dir); |
| 5439 |
} |
| 5440 |
if (clientData != NULL) { |
| 5441 |
fsPathPtr->nativePathPtr = clientData; |
| 5442 |
} |
| 5443 |
PATHFLAGS(pathObjPtr) = 0; |
| 5444 |
} |
| 5445 |
|
| 5446 |
if (fsPathPtr->cwdPtr != NULL) { |
| 5447 |
if (!TclFSCwdPointerEquals(fsPathPtr->cwdPtr)) { |
| 5448 |
if (pathObjPtr->bytes == NULL) { |
| 5449 |
UpdateStringOfFsPath(pathObjPtr); |
| 5450 |
} |
| 5451 |
FreeFsPathInternalRep(pathObjPtr); |
| 5452 |
pathObjPtr->typePtr = NULL; |
| 5453 |
if (Tcl_ConvertToType(interp, pathObjPtr, |
| 5454 |
&tclFsPathType) != TCL_OK) { |
| 5455 |
return NULL; |
| 5456 |
} |
| 5457 |
fsPathPtr = (FsPath*) PATHOBJ(pathObjPtr); |
| 5458 |
} else if (fsPathPtr->normPathPtr == NULL) { |
| 5459 |
int cwdLen; |
| 5460 |
Tcl_Obj *copy; |
| 5461 |
CONST char *cwdStr; |
| 5462 |
ClientData clientData = NULL; |
| 5463 |
|
| 5464 |
copy = Tcl_DuplicateObj(fsPathPtr->cwdPtr); |
| 5465 |
Tcl_IncrRefCount(copy); |
| 5466 |
cwdStr = Tcl_GetStringFromObj(copy, &cwdLen); |
| 5467 |
|
| 5468 |
|
| 5469 |
|
| 5470 |
|
| 5471 |
|
| 5472 |
|
| 5473 |
switch (tclPlatform) { |
| 5474 |
case TCL_PLATFORM_UNIX: |
| 5475 |
if (cwdStr[cwdLen-1] != '/') { |
| 5476 |
Tcl_AppendToObj(copy, "/", 1); |
| 5477 |
cwdLen++; |
| 5478 |
} |
| 5479 |
break; |
| 5480 |
case TCL_PLATFORM_WINDOWS: |
| 5481 |
if (cwdStr[cwdLen-1] != '/' |
| 5482 |
&& cwdStr[cwdLen-1] != '\\') { |
| 5483 |
Tcl_AppendToObj(copy, "/", 1); |
| 5484 |
cwdLen++; |
| 5485 |
} |
| 5486 |
break; |
| 5487 |
case TCL_PLATFORM_MAC: |
| 5488 |
if (cwdStr[cwdLen-1] != ':') { |
| 5489 |
Tcl_AppendToObj(copy, ":", 1); |
| 5490 |
cwdLen++; |
| 5491 |
} |
| 5492 |
break; |
| 5493 |
} |
| 5494 |
Tcl_AppendObjToObj(copy, pathObjPtr); |
| 5495 |
|
| 5496 |
|
| 5497 |
|
| 5498 |
|
| 5499 |
|
| 5500 |
TclFSNormalizeToUniquePath(interp, copy, cwdLen-1, |
| 5501 |
(fsPathPtr->nativePathPtr == NULL ? &clientData : NULL)); |
| 5502 |
fsPathPtr->normPathPtr = copy; |
| 5503 |
if (clientData != NULL) { |
| 5504 |
fsPathPtr->nativePathPtr = clientData; |
| 5505 |
} |
| 5506 |
} |
| 5507 |
} |
| 5508 |
if (fsPathPtr->normPathPtr == NULL) { |
| 5509 |
ClientData clientData = NULL; |
| 5510 |
Tcl_Obj *useThisCwd = NULL; |
| 5511 |
|
| 5512 |
|
| 5513 |
|
| 5514 |
|
| 5515 |
Tcl_Obj *absolutePath = fsPathPtr->translatedPathPtr; |
| 5516 |
char *path = Tcl_GetString(absolutePath); |
| 5517 |
|
| 5518 |
|
| 5519 |
|
| 5520 |
|
| 5521 |
|
| 5522 |
|
| 5523 |
|
| 5524 |
if (path[0] != '\0') { |
| 5525 |
Tcl_PathType type = Tcl_FSGetPathType(pathObjPtr); |
| 5526 |
if (type == TCL_PATH_RELATIVE) { |
| 5527 |
useThisCwd = Tcl_FSGetCwd(interp); |
| 5528 |
|
| 5529 |
if (useThisCwd == NULL) return NULL; |
| 5530 |
|
| 5531 |
absolutePath = Tcl_FSJoinToPath(useThisCwd, 1, &absolutePath); |
| 5532 |
Tcl_IncrRefCount(absolutePath); |
| 5533 |
|
| 5534 |
#ifdef __WIN32__ |
| 5535 |
} else if (type == TCL_PATH_VOLUME_RELATIVE) { |
| 5536 |
|
| 5537 |
|
| 5538 |
|
| 5539 |
|
| 5540 |
|
| 5541 |
|
| 5542 |
|
| 5543 |
|
| 5544 |
|
| 5545 |
|
| 5546 |
|
| 5547 |
|
| 5548 |
|
| 5549 |
|
| 5550 |
useThisCwd = Tcl_FSGetCwd(interp); |
| 5551 |
if (useThisCwd == NULL) return NULL; |
| 5552 |
|
| 5553 |
if (path[0] == '/') { |
| 5554 |
|
| 5555 |
|
| 5556 |
|
| 5557 |
|
| 5558 |
CONST char *drive = Tcl_GetString(useThisCwd); |
| 5559 |
absolutePath = Tcl_NewStringObj(drive,2); |
| 5560 |
Tcl_AppendToObj(absolutePath, path, -1); |
| 5561 |
Tcl_IncrRefCount(absolutePath); |
| 5562 |
|
| 5563 |
} else { |
| 5564 |
|
| 5565 |
|
| 5566 |
|
| 5567 |
|
| 5568 |
CONST char *drive = Tcl_GetString(useThisCwd); |
| 5569 |
char drive_c = path[0]; |
| 5570 |
if (drive_c >= 'a') { |
| 5571 |
drive_c -= ('a' - 'A'); |
| 5572 |
} |
| 5573 |
if (drive[0] == drive_c) { |
| 5574 |
absolutePath = Tcl_DuplicateObj(useThisCwd); |
| 5575 |
|
| 5576 |
} else { |
| 5577 |
Tcl_DecrRefCount(useThisCwd); |
| 5578 |
useThisCwd = NULL; |
| 5579 |
|
| 5580 |
|
| 5581 |
|
| 5582 |
|
| 5583 |
|
| 5584 |
|
| 5585 |
|
| 5586 |
absolutePath = Tcl_NewStringObj(path, 2); |
| 5587 |
} |
| 5588 |
Tcl_IncrRefCount(absolutePath); |
| 5589 |
Tcl_AppendToObj(absolutePath, "/", 1); |
| 5590 |
Tcl_AppendToObj(absolutePath, path+2, -1); |
| 5591 |
} |
| 5592 |
#endif |
| 5593 |
} |
| 5594 |
} |
| 5595 |
|
| 5596 |
fsPathPtr->normPathPtr = TclFSNormalizeAbsolutePath(interp, absolutePath, |
| 5597 |
(fsPathPtr->nativePathPtr == NULL ? &clientData : NULL)); |
| 5598 |
if (0 && (clientData != NULL)) { |
| 5599 |
fsPathPtr->nativePathPtr = |
| 5600 |
(*fsPathPtr->fsRecPtr->fsPtr->dupInternalRepProc)(clientData); |
| 5601 |
} |
| 5602 |
if (!strcmp(Tcl_GetString(fsPathPtr->normPathPtr), |
| 5603 |
Tcl_GetString(pathObjPtr))) { |
| 5604 |
|
| 5605 |
|
| 5606 |
|
| 5607 |
|
| 5608 |
Tcl_DecrRefCount(fsPathPtr->normPathPtr); |
| 5609 |
|
| 5610 |
|
| 5611 |
|
| 5612 |
|
| 5613 |
fsPathPtr->normPathPtr = pathObjPtr; |
| 5614 |
} |
| 5615 |
if (useThisCwd != NULL) { |
| 5616 |
|
| 5617 |
Tcl_DecrRefCount(absolutePath); |
| 5618 |
fsPathPtr->cwdPtr = useThisCwd; |
| 5619 |
} |
| 5620 |
} |
| 5621 |
|
| 5622 |
return fsPathPtr->normPathPtr; |
| 5623 |
} |
| 5624 |
|
| 5625 |
|
| 5626 |
|
| 5627 |
|
| 5628 |
|
| 5629 |
|
| 5630 |
|
| 5631 |
|
| 5632 |
|
| 5633 |
|
| 5634 |
|
| 5635 |
|
| 5636 |
|
| 5637 |
|
| 5638 |
|
| 5639 |
|
| 5640 |
|
| 5641 |
|
| 5642 |
|
| 5643 |
|
| 5644 |
|
| 5645 |
|
| 5646 |
|
| 5647 |
ClientData |
| 5648 |
Tcl_FSGetInternalRep(pathObjPtr, fsPtr) |
| 5649 |
Tcl_Obj* pathObjPtr; |
| 5650 |
Tcl_Filesystem *fsPtr; |
| 5651 |
{ |
| 5652 |
FsPath *srcFsPathPtr; |
| 5653 |
|
| 5654 |
if (Tcl_FSConvertToPathType(NULL, pathObjPtr) != TCL_OK) { |
| 5655 |
return NULL; |
| 5656 |
} |
| 5657 |
srcFsPathPtr = (FsPath*) PATHOBJ(pathObjPtr); |
| 5658 |
|
| 5659 |
|
| 5660 |
|
| 5661 |
|
| 5662 |
|
| 5663 |
|
| 5664 |
|
| 5665 |
|
| 5666 |
|
| 5667 |
|
| 5668 |
|
| 5669 |
|
| 5670 |
|
| 5671 |
|
| 5672 |
|
| 5673 |
|
| 5674 |
if (srcFsPathPtr->fsRecPtr == NULL) { |
| 5675 |
|
| 5676 |
|
| 5677 |
|
| 5678 |
|
| 5679 |
|
| 5680 |
|
| 5681 |
|
| 5682 |
|
| 5683 |
|
| 5684 |
Tcl_FSGetFileSystemForPath(pathObjPtr); |
| 5685 |
|
| 5686 |
|
| 5687 |
|
| 5688 |
|
| 5689 |
|
| 5690 |
|
| 5691 |
|
| 5692 |
srcFsPathPtr = (FsPath*) PATHOBJ(pathObjPtr); |
| 5693 |
if (srcFsPathPtr->fsRecPtr == NULL) { |
| 5694 |
return NULL; |
| 5695 |
} |
| 5696 |
} |
| 5697 |
|
| 5698 |
if (fsPtr != srcFsPathPtr->fsRecPtr->fsPtr) { |
| 5699 |
|
| 5700 |
|
| 5701 |
|
| 5702 |
|
| 5703 |
|
| 5704 |
|
| 5705 |
|
| 5706 |
Tcl_Filesystem *actualFs = Tcl_FSGetFileSystemForPath(pathObjPtr); |
| 5707 |
if (actualFs == fsPtr) { |
| 5708 |
return Tcl_FSGetInternalRep(pathObjPtr, fsPtr); |
| 5709 |
} |
| 5710 |
return NULL; |
| 5711 |
} |
| 5712 |
|
| 5713 |
if (srcFsPathPtr->nativePathPtr == NULL) { |
| 5714 |
Tcl_FSCreateInternalRepProc *proc; |
| 5715 |
proc = srcFsPathPtr->fsRecPtr->fsPtr->createInternalRepProc; |
| 5716 |
|
| 5717 |
if (proc == NULL) { |
| 5718 |
return NULL; |
| 5719 |
} |
| 5720 |
srcFsPathPtr->nativePathPtr = (*proc)(pathObjPtr); |
| 5721 |
} |
| 5722 |
|
| 5723 |
return srcFsPathPtr->nativePathPtr; |
| 5724 |
} |
| 5725 |
|
| 5726 |
|
| 5727 |
|
| 5728 |
|
| 5729 |
|
| 5730 |
|
| 5731 |
|
| 5732 |
|
| 5733 |
|
| 5734 |
|
| 5735 |
|
| 5736 |
|
| 5737 |
|
| 5738 |
|
| 5739 |
|
| 5740 |
|
| 5741 |
|
| 5742 |
|
| 5743 |
|
| 5744 |
|
| 5745 |
int |
| 5746 |
TclFSEnsureEpochOk(pathObjPtr, fsPtrPtr) |
| 5747 |
Tcl_Obj* pathObjPtr; |
| 5748 |
Tcl_Filesystem **fsPtrPtr; |
| 5749 |
{ |
| 5750 |
FsPath *srcFsPathPtr; |
| 5751 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 5752 |
|
| 5753 |
|
| 5754 |
|
| 5755 |
|
| 5756 |
|
| 5757 |
if (Tcl_FSGetNormalizedPath(NULL, pathObjPtr) == NULL) { |
| 5758 |
return TCL_ERROR; |
| 5759 |
} |
| 5760 |
|
| 5761 |
srcFsPathPtr = (FsPath*) PATHOBJ(pathObjPtr); |
| 5762 |
|
| 5763 |
|
| 5764 |
|
| 5765 |
|
| 5766 |
|
| 5767 |
if (srcFsPathPtr->filesystemEpoch != tsdPtr->filesystemEpoch) { |
| 5768 |
|
| 5769 |
|
| 5770 |
|
| 5771 |
|
| 5772 |
if (pathObjPtr->bytes == NULL) { |
| 5773 |
UpdateStringOfFsPath(pathObjPtr); |
| 5774 |
} |
| 5775 |
FreeFsPathInternalRep(pathObjPtr); |
| 5776 |
pathObjPtr->typePtr = NULL; |
| 5777 |
if (SetFsPathFromAny(NULL, pathObjPtr) != TCL_OK) { |
| 5778 |
return TCL_ERROR; |
| 5779 |
} |
| 5780 |
srcFsPathPtr = (FsPath*) PATHOBJ(pathObjPtr); |
| 5781 |
} |
| 5782 |
|
| 5783 |
if (srcFsPathPtr->fsRecPtr != NULL) { |
| 5784 |
*fsPtrPtr = srcFsPathPtr->fsRecPtr->fsPtr; |
| 5785 |
} |
| 5786 |
|
| 5787 |
return TCL_OK; |
| 5788 |
} |
| 5789 |
|
| 5790 |
void |
| 5791 |
TclFSSetPathDetails(pathObjPtr, fsRecPtr, clientData) |
| 5792 |
Tcl_Obj *pathObjPtr; |
| 5793 |
FilesystemRecord *fsRecPtr; |
| 5794 |
ClientData clientData; |
| 5795 |
{ |
| 5796 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 5797 |
|
| 5798 |
FsPath *srcFsPathPtr; |
| 5799 |
|
| 5800 |
srcFsPathPtr = (FsPath*) PATHOBJ(pathObjPtr); |
| 5801 |
srcFsPathPtr->fsRecPtr = fsRecPtr; |
| 5802 |
srcFsPathPtr->nativePathPtr = clientData; |
| 5803 |
srcFsPathPtr->filesystemEpoch = tsdPtr->filesystemEpoch; |
| 5804 |
fsRecPtr->fileRefCount++; |
| 5805 |
} |
| 5806 |
|
| 5807 |
|
| 5808 |
|
| 5809 |
|
| 5810 |
|
| 5811 |
|
| 5812 |
|
| 5813 |
|
| 5814 |
|
| 5815 |
|
| 5816 |
|
| 5817 |
|
| 5818 |
|
| 5819 |
|
| 5820 |
|
| 5821 |
|
| 5822 |
|
| 5823 |
|
| 5824 |
int |
| 5825 |
Tcl_FSEqualPaths(firstPtr, secondPtr) |
| 5826 |
Tcl_Obj* firstPtr; |
| 5827 |
Tcl_Obj* secondPtr; |
| 5828 |
{ |
| 5829 |
if (firstPtr == secondPtr) { |
| 5830 |
return 1; |
| 5831 |
} else { |
| 5832 |
char *firstStr, *secondStr; |
| 5833 |
int firstLen, secondLen, tempErrno; |
| 5834 |
|
| 5835 |
if (firstPtr == NULL || secondPtr == NULL) { |
| 5836 |
return 0; |
| 5837 |
} |
| 5838 |
firstStr = Tcl_GetStringFromObj(firstPtr, &firstLen); |
| 5839 |
secondStr = Tcl_GetStringFromObj(secondPtr, &secondLen); |
| 5840 |
if ((firstLen == secondLen) && (strcmp(firstStr, secondStr) == 0)) { |
| 5841 |
return 1; |
| 5842 |
} |
| 5843 |
|
| 5844 |
|
| 5845 |
|
| 5846 |
|
| 5847 |
|
| 5848 |
tempErrno = Tcl_GetErrno(); |
| 5849 |
firstPtr = Tcl_FSGetNormalizedPath(NULL, firstPtr); |
| 5850 |
secondPtr = Tcl_FSGetNormalizedPath(NULL, secondPtr); |
| 5851 |
Tcl_SetErrno(tempErrno); |
| 5852 |
|
| 5853 |
if (firstPtr == NULL || secondPtr == NULL) { |
| 5854 |
return 0; |
| 5855 |
} |
| 5856 |
firstStr = Tcl_GetStringFromObj(firstPtr, &firstLen); |
| 5857 |
secondStr = Tcl_GetStringFromObj(secondPtr, &secondLen); |
| 5858 |
if ((firstLen == secondLen) && (strcmp(firstStr, secondStr) == 0)) { |
| 5859 |
return 1; |
| 5860 |
} |
| 5861 |
} |
| 5862 |
|
| 5863 |
return 0; |
| 5864 |
} |
| 5865 |
|
| 5866 |
|
| 5867 |
|
| 5868 |
|
| 5869 |
|
| 5870 |
|
| 5871 |
|
| 5872 |
|
| 5873 |
|
| 5874 |
|
| 5875 |
|
| 5876 |
|
| 5877 |
|
| 5878 |
|
| 5879 |
|
| 5880 |
|
| 5881 |
|
| 5882 |
|
| 5883 |
|
| 5884 |
|
| 5885 |
|
| 5886 |
|
| 5887 |
static int |
| 5888 |
SetFsPathFromAny(interp, objPtr) |
| 5889 |
Tcl_Interp *interp; |
| 5890 |
Tcl_Obj *objPtr; |
| 5891 |
{ |
| 5892 |
int len; |
| 5893 |
FsPath *fsPathPtr; |
| 5894 |
Tcl_Obj *transPtr; |
| 5895 |
char *name; |
| 5896 |
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); |
| 5897 |
|
| 5898 |
if (objPtr->typePtr == &tclFsPathType) { |
| 5899 |
return TCL_OK; |
| 5900 |
} |
| 5901 |
|
| 5902 |
|
| 5903 |
|
| 5904 |
|
| 5905 |
|
| 5906 |
|
| 5907 |
|
| 5908 |
|
| 5909 |
|
| 5910 |
|
| 5911 |
|
| 5912 |
|
| 5913 |
|
| 5914 |
|
| 5915 |
|
| 5916 |
|
| 5917 |
name = Tcl_GetStringFromObj(objPtr,&len); |
| 5918 |
|
| 5919 |
|
| 5920 |
|
| 5921 |
|
| 5922 |
if (name[0] == '~') { |
| 5923 |
char *expandedUser; |
| 5924 |
Tcl_DString temp; |
| 5925 |
int split; |
| 5926 |
char separator='/'; |
| 5927 |
|
| 5928 |
if (tclPlatform==TCL_PLATFORM_MAC) { |
| 5929 |
if (strchr(name, ':') != NULL) separator = ':'; |
| 5930 |
} |
| 5931 |
|
| 5932 |
split = FindSplitPos(name, &separator); |
| 5933 |
if (split != len) { |
| 5934 |
|
| 5935 |
name[split] = '\0'; |
| 5936 |
} |
| 5937 |
|
| 5938 |
if (name[1] == '\0') { |
| 5939 |
|
| 5940 |
CONST char *dir; |
| 5941 |
Tcl_DString dirString; |
| 5942 |
if (split != len) { name[split] = separator; } |
| 5943 |
|
| 5944 |
dir = TclGetEnv("HOME", &dirString); |
| 5945 |
if (dir == NULL) { |
| 5946 |
if (interp) { |
| 5947 |
Tcl_ResetResult(interp); |
| 5948 |
Tcl_AppendResult(interp, "couldn't find HOME environment ", |
| 5949 |
"variable to expand path", (char *) NULL); |
| 5950 |
} |
| 5951 |
return TCL_ERROR; |
| 5952 |
} |
| 5953 |
Tcl_DStringInit(&temp); |
| 5954 |
Tcl_JoinPath(1, &dir, &temp); |
| 5955 |
Tcl_DStringFree(&dirString); |
| 5956 |
} else { |
| 5957 |
|
| 5958 |
Tcl_DStringInit(&temp); |
| 5959 |
if (TclpGetUserHome(name+1, &temp) == NULL) { |
| 5960 |
if (interp != NULL) { |
| 5961 |
Tcl_ResetResult(interp); |
| 5962 |
Tcl_AppendResult(interp, "user \"", (name+1), |
| 5963 |
"\" doesn't exist", (char *) NULL); |
| 5964 |
} |
| 5965 |
Tcl_DStringFree(&temp); |
| 5966 |
if (split != len) { name[split] = separator; } |
| 5967 |
return TCL_ERROR; |
| 5968 |
} |
| 5969 |
if (split != len) { name[split] = separator; } |
| 5970 |
} |
| 5971 |
|
| 5972 |
expandedUser = Tcl_DStringValue(&temp); |
| 5973 |
transPtr = Tcl_NewStringObj(expandedUser, Tcl_DStringLength(&temp)); |
| 5974 |
|
| 5975 |
if (split != len) { |
| 5976 |
|
| 5977 |
if (name[split+1] == separator) { |
| 5978 |
|
| 5979 |
|
| 5980 |
|
| 5981 |
|
| 5982 |
|
| 5983 |
|
| 5984 |
|
| 5985 |
|
| 5986 |
int objc; |
| 5987 |
Tcl_Obj **objv; |
| 5988 |
Tcl_Obj *parts = TclpNativeSplitPath(objPtr, NULL); |
| 5989 |
Tcl_ListObjGetElements(NULL, parts, &objc, &objv); |
| 5990 |
|
| 5991 |
objc--; objv++; |
| 5992 |
while (objc--) { |
| 5993 |
TclpNativeJoinPath(transPtr, Tcl_GetString(*objv++)); |
| 5994 |
} |
| 5995 |
Tcl_DecrRefCount(parts); |
| 5996 |
} else { |
| 5997 |
|
| 5998 |
Tcl_Obj *rest = Tcl_NewStringObj(name+split+1,-1); |
| 5999 |
transPtr = Tcl_FSJoinToPath(transPtr, 1, &rest); |
| 6000 |
} |
| 6001 |
} |
| 6002 |
Tcl_DStringFree(&temp); |
| 6003 |
} else { |
| 6004 |
transPtr = Tcl_FSJoinToPath(objPtr,0,NULL); |
| 6005 |
} |
| 6006 |
|
| 6007 |
#if defined(__CYGWIN__) && defined(__WIN32__) |
| 6008 |
{ |
| 6009 |
extern int cygwin_conv_to_win32_path |
| 6010 |
_ANSI_ARGS_((CONST char *, char *)); |
| 6011 |
char winbuf[MAX_PATH+1]; |
| 6012 |
|
| 6013 |
|
| 6014 |
|
| 6015 |
|
| 6016 |
|
| 6017 |
|
| 6018 |
name = Tcl_GetStringFromObj(transPtr, &len); |
| 6019 |
if (len > 0) { |
| 6020 |
cygwin_conv_to_win32_path(name, winbuf); |
| 6021 |
TclWinNoBackslash(winbuf); |
| 6022 |
Tcl_SetStringObj(transPtr, winbuf, -1); |
| 6023 |
} |
| 6024 |
} |
| 6025 |
#endif |
| 6026 |
|
| 6027 |
|
| 6028 |
|
| 6029 |
|
| 6030 |
|
| 6031 |
|
| 6032 |
|
| 6033 |
fsPathPtr = (FsPath*)ckalloc((unsigned)sizeof(FsPath)); |
| 6034 |
|
| 6035 |
fsPathPtr->translatedPathPtr = transPtr; |
| 6036 |
Tcl_IncrRefCount(fsPathPtr->translatedPathPtr); |
| 6037 |
fsPathPtr->normPathPtr = NULL; |
| 6038 |
fsPathPtr->cwdPtr = NULL; |
| 6039 |
fsPathPtr->nativePathPtr = NULL; |
| 6040 |
fsPathPtr->fsRecPtr = NULL; |
| 6041 |
fsPathPtr->filesystemEpoch = tsdPtr->filesystemEpoch; |
| 6042 |
|
| 6043 |
|
| 6044 |
|
| 6045 |
|
| 6046 |
if (objPtr->typePtr != NULL && objPtr->typePtr->freeIntRepProc != NULL) { |
| 6047 |
(objPtr->typePtr->freeIntRepProc)(objPtr); |
| 6048 |
} |
| 6049 |
PATHOBJ(objPtr) = (VOID *) fsPathPtr; |
| 6050 |
PATHFLAGS(objPtr) = 0; |
| 6051 |
objPtr->typePtr = &tclFsPathType; |
| 6052 |
|
| 6053 |
return TCL_OK; |
| 6054 |
} |
| 6055 |
|
| 6056 |
static void |
| 6057 |
FreeFsPathInternalRep(pathObjPtr) |
| 6058 |
Tcl_Obj *pathObjPtr; |
| 6059 |
{ |
| 6060 |
FsPath *fsPathPtr = (FsPath*) PATHOBJ(pathObjPtr); |
| 6061 |
|
| 6062 |
if (fsPathPtr->translatedPathPtr != NULL) { |
| 6063 |
if (fsPathPtr->translatedPathPtr != pathObjPtr) { |
| 6064 |
Tcl_DecrRefCount(fsPathPtr->translatedPathPtr); |
| 6065 |
} |
| 6066 |
} |
| 6067 |
if (fsPathPtr->normPathPtr != NULL) { |
| 6068 |
if (fsPathPtr->normPathPtr != pathObjPtr) { |
| 6069 |
Tcl_DecrRefCount(fsPathPtr->normPathPtr); |
| 6070 |
} |
| 6071 |
fsPathPtr->normPathPtr = NULL; |
| 6072 |
} |
| 6073 |
if (fsPathPtr->cwdPtr != NULL) { |
| 6074 |
Tcl_DecrRefCount(fsPathPtr->cwdPtr); |
| 6075 |
} |
| 6076 |
if (fsPathPtr->nativePathPtr != NULL) { |
| 6077 |
if (fsPathPtr->fsRecPtr != NULL) { |
| 6078 |
if (fsPathPtr->fsRecPtr->fsPtr->freeInternalRepProc != NULL) { |
| 6079 |
(*fsPathPtr->fsRecPtr->fsPtr |
| 6080 |
->freeInternalRepProc)(fsPathPtr->nativePathPtr); |
| 6081 |
fsPathPtr->nativePathPtr = NULL; |
| 6082 |
} |
| 6083 |
} |
| 6084 |
} |
| 6085 |
if (fsPathPtr->fsRecPtr != NULL) { |
| 6086 |
fsPathPtr->fsRecPtr->fileRefCount--; |
| 6087 |
if (fsPathPtr->fsRecPtr->fileRefCount <= 0) { |
| 6088 |
|
| 6089 |
ckfree((char *)fsPathPtr->fsRecPtr); |
| 6090 |
} |
| 6091 |
} |
| 6092 |
|
| 6093 |
ckfree((char*) fsPathPtr); |
| 6094 |
} |
| 6095 |
|
| 6096 |
|
| 6097 |
static void |
| 6098 |
DupFsPathInternalRep(srcPtr, copyPtr) |
| 6099 |
Tcl_Obj *srcPtr; |
| 6100 |
Tcl_Obj *copyPtr; |
| 6101 |
{ |
| 6102 |
FsPath *srcFsPathPtr = (FsPath*) PATHOBJ(srcPtr); |
| 6103 |
FsPath *copyFsPathPtr = (FsPath*) ckalloc((unsigned)sizeof(FsPath)); |
| 6104 |
|
| 6105 |
Tcl_FSDupInternalRepProc *dupProc; |
| 6106 |
|
| 6107 |
PATHOBJ(copyPtr) = (VOID *) copyFsPathPtr; |
| 6108 |
|
| 6109 |
if (srcFsPathPtr->translatedPathPtr != NULL) { |
| 6110 |
copyFsPathPtr->translatedPathPtr = srcFsPathPtr->translatedPathPtr; |
| 6111 |
if (copyFsPathPtr->translatedPathPtr != copyPtr) { |
| 6112 |
Tcl_IncrRefCount(copyFsPathPtr->translatedPathPtr); |
| 6113 |
} |
| 6114 |
} else { |
| 6115 |
copyFsPathPtr->translatedPathPtr = NULL; |
| 6116 |
} |
| 6117 |
|
| 6118 |
if (srcFsPathPtr->normPathPtr != NULL) { |
| 6119 |
copyFsPathPtr->normPathPtr = srcFsPathPtr->normPathPtr; |
| 6120 |
if (copyFsPathPtr->normPathPtr != copyPtr) { |
| 6121 |
Tcl_IncrRefCount(copyFsPathPtr->normPathPtr); |
| 6122 |
} |
| 6123 |
} else { |
| 6124 |
copyFsPathPtr->normPathPtr = NULL; |
| 6125 |
} |
| 6126 |
|
| 6127 |
if (srcFsPathPtr->cwdPtr != NULL) { |
| 6128 |
copyFsPathPtr->cwdPtr = srcFsPathPtr->cwdPtr; |
| 6129 |
Tcl_IncrRefCount(copyFsPathPtr->cwdPtr); |
| 6130 |
} else { |
| 6131 |
copyFsPathPtr->cwdPtr = NULL; |
| 6132 |
} |
| 6133 |
|
| 6134 |
copyFsPathPtr->flags = srcFsPathPtr->flags; |
| 6135 |
|
| 6136 |
if (srcFsPathPtr->fsRecPtr != NULL |
| 6137 |
&& srcFsPathPtr->nativePathPtr != NULL) { |
| 6138 |
dupProc = srcFsPathPtr->fsRecPtr->fsPtr->dupInternalRepProc; |
| 6139 |
if (dupProc != NULL) { |
| 6140 |
copyFsPathPtr->nativePathPtr = |
| 6141 |
(*dupProc)(srcFsPathPtr->nativePathPtr); |
| 6142 |
} else { |
| 6143 |
copyFsPathPtr->nativePathPtr = NULL; |
| 6144 |
} |
| 6145 |
} else { |
| 6146 |
copyFsPathPtr->nativePathPtr = NULL; |
| 6147 |
} |
| 6148 |
copyFsPathPtr->fsRecPtr = srcFsPathPtr->fsRecPtr; |
| 6149 |
copyFsPathPtr->filesystemEpoch = srcFsPathPtr->filesystemEpoch; |
| 6150 |
if (copyFsPathPtr->fsRecPtr != NULL) { |
| 6151 |
copyFsPathPtr->fsRecPtr->fileRefCount++; |
| 6152 |
} |
| 6153 |
|
| 6154 |
copyPtr->typePtr = &tclFsPathType; |
| 6155 |
} |
| 6156 |
|
| 6157 |
|
| 6158 |
|
| 6159 |
|
| 6160 |
|
| 6161 |
|
| 6162 |
|
| 6163 |
|
| 6164 |
|
| 6165 |
|
| 6166 |
|
| 6167 |
|
| 6168 |
|
| 6169 |
|
| 6170 |
|
| 6171 |
|
| 6172 |
|
| 6173 |
static void |
| 6174 |
UpdateStringOfFsPath(objPtr) |
| 6175 |
register Tcl_Obj *objPtr; |
| 6176 |
{ |
| 6177 |
FsPath *fsPathPtr = (FsPath*) PATHOBJ(objPtr); |
| 6178 |
CONST char *cwdStr; |
| 6179 |
int cwdLen; |
| 6180 |
Tcl_Obj *copy; |
| 6181 |
|
| 6182 |
if (PATHFLAGS(objPtr) == 0 || fsPathPtr->cwdPtr == NULL) { |
| 6183 |
panic("Called UpdateStringOfFsPath with invalid object"); |
| 6184 |
} |
| 6185 |
|
| 6186 |
copy = Tcl_DuplicateObj(fsPathPtr->cwdPtr); |
| 6187 |
Tcl_IncrRefCount(copy); |
| 6188 |
|
| 6189 |
cwdStr = Tcl_GetStringFromObj(copy, &cwdLen); |
| 6190 |
|
| 6191 |
|
| 6192 |
|
| 6193 |
|
| 6194 |
|
| 6195 |
|
| 6196 |
switch (tclPlatform) { |
| 6197 |
case TCL_PLATFORM_UNIX: |
| 6198 |
if (cwdStr[cwdLen-1] != '/') { |
| 6199 |
Tcl_AppendToObj(copy, "/", 1); |
| 6200 |
cwdLen++; |
| 6201 |
} |
| 6202 |
break; |
| 6203 |
case TCL_PLATFORM_WINDOWS: |
| 6204 |
|
| 6205 |
|
| 6206 |
|
| 6207 |
|
| 6208 |
|
| 6209 |
if (cwdStr[cwdLen-1] != '/' |
| 6210 |
&& cwdStr[cwdLen-1] != '\\') { |
| 6211 |
if (cwdLen != 2 || cwdStr[1] != ':') { |
| 6212 |
Tcl_AppendToObj(copy, "/", 1); |
| 6213 |
cwdLen++; |
| 6214 |
} |
| 6215 |
} |
| 6216 |
break; |
| 6217 |
case TCL_PLATFORM_MAC: |
| 6218 |
if (cwdStr[cwdLen-1] != ':') { |
| 6219 |
Tcl_AppendToObj(copy, ":", 1); |
| 6220 |
cwdLen++; |
| 6221 |
} |
| 6222 |
break; |
| 6223 |
} |
| 6224 |
Tcl_AppendObjToObj(copy, fsPathPtr->normPathPtr); |
| 6225 |
objPtr->bytes = Tcl_GetStringFromObj(copy, &cwdLen); |
| 6226 |
objPtr->length = cwdLen; |
| 6227 |
copy->bytes = tclEmptyStringRep; |
| 6228 |
copy->length = 0; |
| 6229 |
Tcl_DecrRefCount(copy); |
| 6230 |
} |
| 6231 |
|
| 6232 |
|
| 6233 |
|
| 6234 |
|
| 6235 |
|
| 6236 |
|
| 6237 |
|
| 6238 |
|
| 6239 |
|
| 6240 |
|
| 6241 |
|
| 6242 |
|
| 6243 |
|
| 6244 |
|
| 6245 |
|
| 6246 |
|
| 6247 |
|
| 6248 |
|
| 6249 |
|
| 6250 |
|
| 6251 |
|
| 6252 |
|
| 6253 |
|
| 6254 |
int |
| 6255 |
NativePathInFilesystem(pathPtr, clientDataPtr) |
| 6256 |
Tcl_Obj *pathPtr; |
| 6257 |
ClientData *clientDataPtr; |
| 6258 |
{ |
| 6259 |
|
| 6260 |
|
| 6261 |
|
| 6262 |
|
| 6263 |
|
| 6264 |
|
| 6265 |
|
| 6266 |
|
| 6267 |
if (pathPtr->typePtr == &tclFsPathType) { |
| 6268 |
if (pathPtr->bytes != NULL && pathPtr->bytes[0] == '\0') { |
| 6269 |
|
| 6270 |
return -1; |
| 6271 |
} |
| 6272 |
|
| 6273 |
} else { |
| 6274 |
|
| 6275 |
|
| 6276 |
|
| 6277 |
|
| 6278 |
|
| 6279 |
int len; |
| 6280 |
Tcl_GetStringFromObj(pathPtr,&len); |
| 6281 |
if (len == 0) { |
| 6282 |
|
| 6283 |
return -1; |
| 6284 |
} |
| 6285 |
} |
| 6286 |
|
| 6287 |
|
| 6288 |
|
| 6289 |
|
| 6290 |
return TCL_OK; |
| 6291 |
} |