| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "tclWinInt.h" |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#define DOTREE_PRED 1 |
| 23 |
#define DOTREE_POSTD 2 |
| 24 |
#define DOTREE_F 3 |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
static int GetWinFileAttributes _ANSI_ARGS_((Tcl_Interp *interp, |
| 31 |
int objIndex, Tcl_Obj *fileName, |
| 32 |
Tcl_Obj **attributePtrPtr)); |
| 33 |
static int GetWinFileLongName _ANSI_ARGS_((Tcl_Interp *interp, |
| 34 |
int objIndex, Tcl_Obj *fileName, |
| 35 |
Tcl_Obj **attributePtrPtr)); |
| 36 |
static int GetWinFileShortName _ANSI_ARGS_((Tcl_Interp *interp, |
| 37 |
int objIndex, Tcl_Obj *fileName, |
| 38 |
Tcl_Obj **attributePtrPtr)); |
| 39 |
static int SetWinFileAttributes _ANSI_ARGS_((Tcl_Interp *interp, |
| 40 |
int objIndex, Tcl_Obj *fileName, |
| 41 |
Tcl_Obj *attributePtr)); |
| 42 |
static int CannotSetAttribute _ANSI_ARGS_((Tcl_Interp *interp, |
| 43 |
int objIndex, Tcl_Obj *fileName, |
| 44 |
Tcl_Obj *attributePtr)); |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
enum { |
| 51 |
WIN_ARCHIVE_ATTRIBUTE, |
| 52 |
WIN_HIDDEN_ATTRIBUTE, |
| 53 |
WIN_LONGNAME_ATTRIBUTE, |
| 54 |
WIN_READONLY_ATTRIBUTE, |
| 55 |
WIN_SHORTNAME_ATTRIBUTE, |
| 56 |
WIN_SYSTEM_ATTRIBUTE |
| 57 |
}; |
| 58 |
|
| 59 |
static int attributeArray[] = {FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_HIDDEN, |
| 60 |
0, FILE_ATTRIBUTE_READONLY, 0, FILE_ATTRIBUTE_SYSTEM}; |
| 61 |
|
| 62 |
|
| 63 |
CONST char *tclpFileAttrStrings[] = { |
| 64 |
"-archive", "-hidden", "-longname", "-readonly", |
| 65 |
"-shortname", "-system", (char *) NULL |
| 66 |
}; |
| 67 |
|
| 68 |
CONST TclFileAttrProcs tclpFileAttrProcs[] = { |
| 69 |
{GetWinFileAttributes, SetWinFileAttributes}, |
| 70 |
{GetWinFileAttributes, SetWinFileAttributes}, |
| 71 |
{GetWinFileLongName, CannotSetAttribute}, |
| 72 |
{GetWinFileAttributes, SetWinFileAttributes}, |
| 73 |
{GetWinFileShortName, CannotSetAttribute}, |
| 74 |
{GetWinFileAttributes, SetWinFileAttributes}}; |
| 75 |
|
| 76 |
#if defined(HAVE_NO_SEH) && defined(TCL_MEM_DEBUG) |
| 77 |
static void *INITIAL_ESP, |
| 78 |
*INITIAL_EBP, |
| 79 |
*INITIAL_HANDLER, |
| 80 |
*RESTORED_ESP, |
| 81 |
*RESTORED_EBP, |
| 82 |
*RESTORED_HANDLER; |
| 83 |
#endif |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
typedef int (TraversalProc)(CONST TCHAR *srcPtr, CONST TCHAR *dstPtr, |
| 90 |
int type, Tcl_DString *errorPtr); |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
static void StatError(Tcl_Interp *interp, Tcl_Obj *fileName); |
| 97 |
static int ConvertFileNameFormat(Tcl_Interp *interp, |
| 98 |
int objIndex, Tcl_Obj *fileName, int longShort, |
| 99 |
Tcl_Obj **attributePtrPtr); |
| 100 |
static int DoCopyFile(CONST TCHAR *srcPtr, CONST TCHAR *dstPtr); |
| 101 |
static int DoCreateDirectory(CONST TCHAR *pathPtr); |
| 102 |
static int DoRemoveJustDirectory(CONST TCHAR *nativeSrc, |
| 103 |
int ignoreError, Tcl_DString *errorPtr); |
| 104 |
static int DoRemoveDirectory(Tcl_DString *pathPtr, int recursive, |
| 105 |
Tcl_DString *errorPtr); |
| 106 |
static int DoRenameFile(CONST TCHAR *nativeSrc, CONST TCHAR *dstPtr); |
| 107 |
static int TraversalCopy(CONST TCHAR *srcPtr, CONST TCHAR *dstPtr, |
| 108 |
int type, Tcl_DString *errorPtr); |
| 109 |
static int TraversalDelete(CONST TCHAR *srcPtr, CONST TCHAR *dstPtr, |
| 110 |
int type, Tcl_DString *errorPtr); |
| 111 |
static int TraverseWinTree(TraversalProc *traverseProc, |
| 112 |
Tcl_DString *sourcePtr, Tcl_DString *dstPtr, |
| 113 |
Tcl_DString *errorPtr); |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
int |
| 159 |
TclpObjRenameFile(srcPathPtr, destPathPtr) |
| 160 |
Tcl_Obj *srcPathPtr; |
| 161 |
Tcl_Obj *destPathPtr; |
| 162 |
{ |
| 163 |
return DoRenameFile(Tcl_FSGetNativePath(srcPathPtr), |
| 164 |
Tcl_FSGetNativePath(destPathPtr)); |
| 165 |
} |
| 166 |
|
| 167 |
static int |
| 168 |
DoRenameFile( |
| 169 |
CONST TCHAR *nativeSrc, |
| 170 |
|
| 171 |
CONST TCHAR *nativeDst) |
| 172 |
|
| 173 |
{ |
| 174 |
DWORD srcAttr, dstAttr; |
| 175 |
int retval = -1; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
if (nativeSrc == NULL || nativeSrc[0] == '\0' || |
| 183 |
nativeDst == NULL || nativeDst[0] == '\0') { |
| 184 |
Tcl_SetErrno(ENOENT); |
| 185 |
return TCL_ERROR; |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
#ifdef HAVE_NO_SEH |
| 194 |
# ifdef TCL_MEM_DEBUG |
| 195 |
__asm__ __volatile__ ( |
| 196 |
"movl %%esp, %0" "\n\t" |
| 197 |
"movl %%ebp, %1" "\n\t" |
| 198 |
"movl %%fs:0, %2" "\n\t" |
| 199 |
: "=m"(INITIAL_ESP), |
| 200 |
"=m"(INITIAL_EBP), |
| 201 |
"=r"(INITIAL_HANDLER) ); |
| 202 |
# endif |
| 203 |
|
| 204 |
__asm__ __volatile__ ( |
| 205 |
"pushl %ebp" "\n\t" |
| 206 |
"pushl $__except_dorenamefile_handler" "\n\t" |
| 207 |
"pushl %fs:0" "\n\t" |
| 208 |
"movl %esp, %fs:0"); |
| 209 |
#else |
| 210 |
__try { |
| 211 |
#endif |
| 212 |
if ((*tclWinProcs->moveFileProc)(nativeSrc, nativeDst) != FALSE) { |
| 213 |
retval = TCL_OK; |
| 214 |
} |
| 215 |
#ifdef HAVE_NO_SEH |
| 216 |
__asm__ __volatile__ ( |
| 217 |
"jmp dorenamefile_pop" "\n" |
| 218 |
"dorenamefile_reentry:" "\n\t" |
| 219 |
"movl %%fs:0, %%eax" "\n\t" |
| 220 |
"movl 0x8(%%eax), %%esp" "\n\t" |
| 221 |
"movl 0x8(%%esp), %%ebp" "\n" |
| 222 |
"dorenamefile_pop:" "\n\t" |
| 223 |
"movl (%%esp), %%eax" "\n\t" |
| 224 |
"movl %%eax, %%fs:0" "\n\t" |
| 225 |
"add $12, %%esp" "\n\t" |
| 226 |
: |
| 227 |
: |
| 228 |
: "%eax"); |
| 229 |
|
| 230 |
# ifdef TCL_MEM_DEBUG |
| 231 |
__asm__ __volatile__ ( |
| 232 |
"movl %%esp, %0" "\n\t" |
| 233 |
"movl %%ebp, %1" "\n\t" |
| 234 |
"movl %%fs:0, %2" "\n\t" |
| 235 |
: "=m"(RESTORED_ESP), |
| 236 |
"=m"(RESTORED_EBP), |
| 237 |
"=r"(RESTORED_HANDLER) ); |
| 238 |
|
| 239 |
if (INITIAL_ESP != RESTORED_ESP) |
| 240 |
panic("ESP restored incorrectly"); |
| 241 |
if (INITIAL_EBP != RESTORED_EBP) |
| 242 |
panic("EBP restored incorrectly"); |
| 243 |
if (INITIAL_HANDLER != RESTORED_HANDLER) |
| 244 |
panic("HANDLER restored incorrectly"); |
| 245 |
# endif |
| 246 |
#else |
| 247 |
} __except (EXCEPTION_EXECUTE_HANDLER) {} |
| 248 |
#endif |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
if (retval != -1) |
| 254 |
return retval; |
| 255 |
|
| 256 |
TclWinConvertError(GetLastError()); |
| 257 |
|
| 258 |
srcAttr = (*tclWinProcs->getFileAttributesProc)(nativeSrc); |
| 259 |
dstAttr = (*tclWinProcs->getFileAttributesProc)(nativeDst); |
| 260 |
if (srcAttr == 0xffffffff) { |
| 261 |
if ((*tclWinProcs->getFullPathNameProc)(nativeSrc, 0, NULL, NULL) >= MAX_PATH) { |
| 262 |
errno = ENAMETOOLONG; |
| 263 |
return TCL_ERROR; |
| 264 |
} |
| 265 |
srcAttr = 0; |
| 266 |
} |
| 267 |
if (dstAttr == 0xffffffff) { |
| 268 |
if ((*tclWinProcs->getFullPathNameProc)(nativeDst, 0, NULL, NULL) >= MAX_PATH) { |
| 269 |
errno = ENAMETOOLONG; |
| 270 |
return TCL_ERROR; |
| 271 |
} |
| 272 |
dstAttr = 0; |
| 273 |
} |
| 274 |
|
| 275 |
if (errno == EBADF) { |
| 276 |
errno = EACCES; |
| 277 |
return TCL_ERROR; |
| 278 |
} |
| 279 |
if (errno == EACCES) { |
| 280 |
decode: |
| 281 |
if (srcAttr & FILE_ATTRIBUTE_DIRECTORY) { |
| 282 |
TCHAR *nativeSrcRest, *nativeDstRest; |
| 283 |
CONST char **srcArgv, **dstArgv; |
| 284 |
int size, srcArgc, dstArgc; |
| 285 |
WCHAR nativeSrcPath[MAX_PATH]; |
| 286 |
WCHAR nativeDstPath[MAX_PATH]; |
| 287 |
Tcl_DString srcString, dstString; |
| 288 |
CONST char *src, *dst; |
| 289 |
|
| 290 |
size = (*tclWinProcs->getFullPathNameProc)(nativeSrc, MAX_PATH, |
| 291 |
nativeSrcPath, &nativeSrcRest); |
| 292 |
if ((size == 0) || (size > MAX_PATH)) { |
| 293 |
return TCL_ERROR; |
| 294 |
} |
| 295 |
size = (*tclWinProcs->getFullPathNameProc)(nativeDst, MAX_PATH, |
| 296 |
nativeDstPath, &nativeDstRest); |
| 297 |
if ((size == 0) || (size > MAX_PATH)) { |
| 298 |
return TCL_ERROR; |
| 299 |
} |
| 300 |
(*tclWinProcs->charLowerProc)((TCHAR *) nativeSrcPath); |
| 301 |
(*tclWinProcs->charLowerProc)((TCHAR *) nativeDstPath); |
| 302 |
|
| 303 |
src = Tcl_WinTCharToUtf((TCHAR *) nativeSrcPath, -1, &srcString); |
| 304 |
dst = Tcl_WinTCharToUtf((TCHAR *) nativeDstPath, -1, &dstString); |
| 305 |
if (strncmp(src, dst, (size_t) Tcl_DStringLength(&srcString)) == 0) { |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
errno = EINVAL; |
| 311 |
Tcl_DStringFree(&srcString); |
| 312 |
Tcl_DStringFree(&dstString); |
| 313 |
return TCL_ERROR; |
| 314 |
} |
| 315 |
Tcl_SplitPath(src, &srcArgc, &srcArgv); |
| 316 |
Tcl_SplitPath(dst, &dstArgc, &dstArgv); |
| 317 |
Tcl_DStringFree(&srcString); |
| 318 |
Tcl_DStringFree(&dstString); |
| 319 |
|
| 320 |
if (srcArgc == 1) { |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
Tcl_SetErrno(EINVAL); |
| 328 |
} else if ((srcArgc > 0) && (dstArgc > 0) && |
| 329 |
(strcmp(srcArgv[0], dstArgv[0]) != 0)) { |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
Tcl_SetErrno(EXDEV); |
| 341 |
} |
| 342 |
|
| 343 |
ckfree((char *) srcArgv); |
| 344 |
ckfree((char *) dstArgv); |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
} else if (Tcl_GetErrno() == EEXIST) { |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
if (srcAttr & FILE_ATTRIBUTE_DIRECTORY) { |
| 361 |
if (dstAttr & FILE_ATTRIBUTE_DIRECTORY) { |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
if (DoRemoveJustDirectory(nativeDst, 0, NULL) == TCL_OK) { |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
if ((*tclWinProcs->moveFileProc)(nativeSrc, nativeDst) != FALSE) { |
| 376 |
return TCL_OK; |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
TclWinConvertError(GetLastError()); |
| 385 |
(*tclWinProcs->createDirectoryProc)(nativeDst, NULL); |
| 386 |
(*tclWinProcs->setFileAttributesProc)(nativeDst, dstAttr); |
| 387 |
if (Tcl_GetErrno() == EACCES) { |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
goto decode; |
| 393 |
} |
| 394 |
} |
| 395 |
} else { |
| 396 |
Tcl_SetErrno(ENOTDIR); |
| 397 |
} |
| 398 |
} else { |
| 399 |
if (dstAttr & FILE_ATTRIBUTE_DIRECTORY) { |
| 400 |
Tcl_SetErrno(EISDIR); |
| 401 |
} else { |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
TCHAR *nativeRest, *nativeTmp, *nativePrefix; |
| 412 |
int result, size; |
| 413 |
WCHAR tempBuf[MAX_PATH]; |
| 414 |
|
| 415 |
size = (*tclWinProcs->getFullPathNameProc)(nativeDst, MAX_PATH, |
| 416 |
tempBuf, &nativeRest); |
| 417 |
if ((size == 0) || (size > MAX_PATH) || (nativeRest == NULL)) { |
| 418 |
return TCL_ERROR; |
| 419 |
} |
| 420 |
nativeTmp = (TCHAR *) tempBuf; |
| 421 |
((char *) nativeRest)[0] = '\0'; |
| 422 |
((char *) nativeRest)[1] = '\0'; |
| 423 |
|
| 424 |
result = TCL_ERROR; |
| 425 |
nativePrefix = (tclWinProcs->useWide) |
| 426 |
? (TCHAR *) L"tclr" : (TCHAR *) "tclr"; |
| 427 |
if ((*tclWinProcs->getTempFileNameProc)(nativeTmp, |
| 428 |
nativePrefix, 0, tempBuf) != 0) { |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
nativeTmp = (TCHAR *) tempBuf; |
| 437 |
(*tclWinProcs->deleteFileProc)(nativeTmp); |
| 438 |
if ((*tclWinProcs->moveFileProc)(nativeDst, nativeTmp) != FALSE) { |
| 439 |
if ((*tclWinProcs->moveFileProc)(nativeSrc, nativeDst) != FALSE) { |
| 440 |
(*tclWinProcs->setFileAttributesProc)(nativeTmp, |
| 441 |
FILE_ATTRIBUTE_NORMAL); |
| 442 |
(*tclWinProcs->deleteFileProc)(nativeTmp); |
| 443 |
return TCL_OK; |
| 444 |
} else { |
| 445 |
(*tclWinProcs->deleteFileProc)(nativeDst); |
| 446 |
(*tclWinProcs->moveFileProc)(nativeTmp, nativeDst); |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
TclWinConvertError(GetLastError()); |
| 456 |
if (Tcl_GetErrno() == EACCES) { |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
goto decode; |
| 462 |
} |
| 463 |
} |
| 464 |
return result; |
| 465 |
} |
| 466 |
} |
| 467 |
} |
| 468 |
return TCL_ERROR; |
| 469 |
} |
| 470 |
#ifdef HAVE_NO_SEH |
| 471 |
static |
| 472 |
__attribute__ ((cdecl)) |
| 473 |
EXCEPTION_DISPOSITION |
| 474 |
_except_dorenamefile_handler( |
| 475 |
struct _EXCEPTION_RECORD *ExceptionRecord, |
| 476 |
void *EstablisherFrame, |
| 477 |
struct _CONTEXT *ContextRecord, |
| 478 |
void *DispatcherContext) |
| 479 |
{ |
| 480 |
__asm__ __volatile__ ( |
| 481 |
"jmp dorenamefile_reentry"); |
| 482 |
|
| 483 |
_except_dorenamefile_handler(NULL, NULL, NULL, NULL); |
| 484 |
return 0; |
| 485 |
} |
| 486 |
#endif |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
int |
| 516 |
TclpObjCopyFile(srcPathPtr, destPathPtr) |
| 517 |
Tcl_Obj *srcPathPtr; |
| 518 |
Tcl_Obj *destPathPtr; |
| 519 |
{ |
| 520 |
return DoCopyFile(Tcl_FSGetNativePath(srcPathPtr), |
| 521 |
Tcl_FSGetNativePath(destPathPtr)); |
| 522 |
} |
| 523 |
|
| 524 |
static int |
| 525 |
DoCopyFile( |
| 526 |
CONST TCHAR *nativeSrc, |
| 527 |
CONST TCHAR *nativeDst) |
| 528 |
{ |
| 529 |
int retval = -1; |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
if (nativeSrc == NULL || nativeSrc[0] == '\0' || |
| 537 |
nativeDst == NULL || nativeDst[0] == '\0') { |
| 538 |
Tcl_SetErrno(ENOENT); |
| 539 |
return TCL_ERROR; |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
#ifdef HAVE_NO_SEH |
| 548 |
# ifdef TCL_MEM_DEBUG |
| 549 |
__asm__ __volatile__ ( |
| 550 |
"movl %%esp, %0" "\n\t" |
| 551 |
"movl %%ebp, %1" "\n\t" |
| 552 |
"movl %%fs:0, %2" "\n\t" |
| 553 |
: "=m"(INITIAL_ESP), |
| 554 |
"=m"(INITIAL_EBP), |
| 555 |
"=r"(INITIAL_HANDLER) ); |
| 556 |
# endif |
| 557 |
|
| 558 |
__asm__ __volatile__ ( |
| 559 |
"pushl %ebp" "\n\t" |
| 560 |
"pushl $__except_docopyfile_handler" "\n\t" |
| 561 |
"pushl %fs:0" "\n\t" |
| 562 |
"movl %esp, %fs:0"); |
| 563 |
#else |
| 564 |
__try { |
| 565 |
#endif |
| 566 |
if ((*tclWinProcs->copyFileProc)(nativeSrc, nativeDst, 0) != FALSE) { |
| 567 |
retval = TCL_OK; |
| 568 |
} |
| 569 |
#ifdef HAVE_NO_SEH |
| 570 |
__asm__ __volatile__ ( |
| 571 |
"jmp docopyfile_pop" "\n" |
| 572 |
"docopyfile_reentry:" "\n\t" |
| 573 |
"movl %%fs:0, %%eax" "\n\t" |
| 574 |
"movl 0x8(%%eax), %%esp" "\n\t" |
| 575 |
"movl 0x8(%%esp), %%ebp" "\n" |
| 576 |
"docopyfile_pop:" "\n\t" |
| 577 |
"movl (%%esp), %%eax" "\n\t" |
| 578 |
"movl %%eax, %%fs:0" "\n\t" |
| 579 |
"add $12, %%esp" "\n\t" |
| 580 |
: |
| 581 |
: |
| 582 |
: "%eax"); |
| 583 |
|
| 584 |
# ifdef TCL_MEM_DEBUG |
| 585 |
__asm__ __volatile__ ( |
| 586 |
"movl %%esp, %0" "\n\t" |
| 587 |
"movl %%ebp, %1" "\n\t" |
| 588 |
"movl %%fs:0, %2" "\n\t" |
| 589 |
: "=m"(RESTORED_ESP), |
| 590 |
"=m"(RESTORED_EBP), |
| 591 |
"=r"(RESTORED_HANDLER) ); |
| 592 |
|
| 593 |
if (INITIAL_ESP != RESTORED_ESP) |
| 594 |
panic("ESP restored incorrectly"); |
| 595 |
if (INITIAL_EBP != RESTORED_EBP) |
| 596 |
panic("EBP restored incorrectly"); |
| 597 |
if (INITIAL_HANDLER != RESTORED_HANDLER) |
| 598 |
panic("HANDLER restored incorrectly"); |
| 599 |
# endif |
| 600 |
#else |
| 601 |
} __except (EXCEPTION_EXECUTE_HANDLER) {} |
| 602 |
#endif |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
if (retval != -1) |
| 608 |
return retval; |
| 609 |
|
| 610 |
TclWinConvertError(GetLastError()); |
| 611 |
if (Tcl_GetErrno() == EBADF) { |
| 612 |
Tcl_SetErrno(EACCES); |
| 613 |
return TCL_ERROR; |
| 614 |
} |
| 615 |
if (Tcl_GetErrno() == EACCES) { |
| 616 |
DWORD srcAttr, dstAttr; |
| 617 |
|
| 618 |
srcAttr = (*tclWinProcs->getFileAttributesProc)(nativeSrc); |
| 619 |
dstAttr = (*tclWinProcs->getFileAttributesProc)(nativeDst); |
| 620 |
if (srcAttr != 0xffffffff) { |
| 621 |
if (dstAttr == 0xffffffff) { |
| 622 |
dstAttr = 0; |
| 623 |
} |
| 624 |
if ((srcAttr & FILE_ATTRIBUTE_DIRECTORY) || |
| 625 |
(dstAttr & FILE_ATTRIBUTE_DIRECTORY)) { |
| 626 |
if (srcAttr & FILE_ATTRIBUTE_REPARSE_POINT) { |
| 627 |
|
| 628 |
if (TclWinSymLinkCopyDirectory(nativeSrc, nativeDst) == 0) { |
| 629 |
return TCL_OK; |
| 630 |
} |
| 631 |
} |
| 632 |
Tcl_SetErrno(EISDIR); |
| 633 |
} |
| 634 |
if (dstAttr & FILE_ATTRIBUTE_READONLY) { |
| 635 |
(*tclWinProcs->setFileAttributesProc)(nativeDst, |
| 636 |
dstAttr & ~((DWORD)FILE_ATTRIBUTE_READONLY)); |
| 637 |
if ((*tclWinProcs->copyFileProc)(nativeSrc, nativeDst, 0) != FALSE) { |
| 638 |
return TCL_OK; |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
TclWinConvertError(GetLastError()); |
| 646 |
(*tclWinProcs->setFileAttributesProc)(nativeDst, dstAttr); |
| 647 |
} |
| 648 |
} |
| 649 |
} |
| 650 |
return TCL_ERROR; |
| 651 |
} |
| 652 |
#ifdef HAVE_NO_SEH |
| 653 |
static |
| 654 |
__attribute__ ((cdecl)) |
| 655 |
EXCEPTION_DISPOSITION |
| 656 |
_except_docopyfile_handler( |
| 657 |
struct _EXCEPTION_RECORD *ExceptionRecord, |
| 658 |
void *EstablisherFrame, |
| 659 |
struct _CONTEXT *ContextRecord, |
| 660 |
void *DispatcherContext) |
| 661 |
{ |
| 662 |
__asm__ __volatile__ ( |
| 663 |
"jmp docopyfile_reentry"); |
| 664 |
_except_docopyfile_handler(NULL,NULL,NULL,NULL); |
| 665 |
return 0; |
| 666 |
} |
| 667 |
#endif |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
int |
| 695 |
TclpObjDeleteFile(pathPtr) |
| 696 |
Tcl_Obj *pathPtr; |
| 697 |
{ |
| 698 |
return TclpDeleteFile(Tcl_FSGetNativePath(pathPtr)); |
| 699 |
} |
| 700 |
|
| 701 |
int |
| 702 |
TclpDeleteFile( |
| 703 |
CONST TCHAR *nativePath) |
| 704 |
{ |
| 705 |
DWORD attr; |
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
if (nativePath == NULL || nativePath[0] == '\0') { |
| 713 |
Tcl_SetErrno(ENOENT); |
| 714 |
return TCL_ERROR; |
| 715 |
} |
| 716 |
|
| 717 |
if ((*tclWinProcs->deleteFileProc)(nativePath) != FALSE) { |
| 718 |
return TCL_OK; |
| 719 |
} |
| 720 |
TclWinConvertError(GetLastError()); |
| 721 |
|
| 722 |
if (Tcl_GetErrno() == EACCES) { |
| 723 |
attr = (*tclWinProcs->getFileAttributesProc)(nativePath); |
| 724 |
if (attr != 0xffffffff) { |
| 725 |
if (attr & FILE_ATTRIBUTE_DIRECTORY) { |
| 726 |
if (attr & FILE_ATTRIBUTE_REPARSE_POINT) { |
| 727 |
|
| 728 |
if (TclWinSymLinkDelete(nativePath, 0) == 0) { |
| 729 |
return TCL_OK; |
| 730 |
} |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
Tcl_SetErrno(EISDIR); |
| 741 |
} else if (attr & FILE_ATTRIBUTE_READONLY) { |
| 742 |
int res = (*tclWinProcs->setFileAttributesProc)(nativePath, |
| 743 |
attr & ~((DWORD)FILE_ATTRIBUTE_READONLY)); |
| 744 |
if ((res != 0) && ((*tclWinProcs->deleteFileProc)(nativePath) |
| 745 |
!= FALSE)) { |
| 746 |
return TCL_OK; |
| 747 |
} |
| 748 |
TclWinConvertError(GetLastError()); |
| 749 |
if (res != 0) { |
| 750 |
(*tclWinProcs->setFileAttributesProc)(nativePath, attr); |
| 751 |
} |
| 752 |
} |
| 753 |
} |
| 754 |
} else if (Tcl_GetErrno() == ENOENT) { |
| 755 |
attr = (*tclWinProcs->getFileAttributesProc)(nativePath); |
| 756 |
if (attr != 0xffffffff) { |
| 757 |
if (attr & FILE_ATTRIBUTE_DIRECTORY) { |
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
Tcl_SetErrno(EISDIR); |
| 764 |
} |
| 765 |
} |
| 766 |
} else if (Tcl_GetErrno() == EINVAL) { |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
Tcl_SetErrno(EACCES); |
| 773 |
} |
| 774 |
|
| 775 |
return TCL_ERROR; |
| 776 |
} |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
int |
| 804 |
TclpObjCreateDirectory(pathPtr) |
| 805 |
Tcl_Obj *pathPtr; |
| 806 |
{ |
| 807 |
return DoCreateDirectory(Tcl_FSGetNativePath(pathPtr)); |
| 808 |
} |
| 809 |
|
| 810 |
static int |
| 811 |
DoCreateDirectory( |
| 812 |
CONST TCHAR *nativePath) |
| 813 |
{ |
| 814 |
DWORD error; |
| 815 |
if ((*tclWinProcs->createDirectoryProc)(nativePath, NULL) == 0) { |
| 816 |
error = GetLastError(); |
| 817 |
TclWinConvertError(error); |
| 818 |
return TCL_ERROR; |
| 819 |
} |
| 820 |
return TCL_OK; |
| 821 |
} |
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
int |
| 850 |
TclpObjCopyDirectory(srcPathPtr, destPathPtr, errorPtr) |
| 851 |
Tcl_Obj *srcPathPtr; |
| 852 |
Tcl_Obj *destPathPtr; |
| 853 |
Tcl_Obj **errorPtr; |
| 854 |
{ |
| 855 |
Tcl_DString ds; |
| 856 |
Tcl_DString srcString, dstString; |
| 857 |
Tcl_Obj *normSrcPtr, *normDestPtr; |
| 858 |
int ret; |
| 859 |
|
| 860 |
normSrcPtr = Tcl_FSGetNormalizedPath(NULL,srcPathPtr); |
| 861 |
Tcl_WinUtfToTChar(Tcl_GetString(normSrcPtr), -1, &srcString); |
| 862 |
normDestPtr = Tcl_FSGetNormalizedPath(NULL,destPathPtr); |
| 863 |
Tcl_WinUtfToTChar(Tcl_GetString(normDestPtr), -1, &dstString); |
| 864 |
|
| 865 |
ret = TraverseWinTree(TraversalCopy, &srcString, &dstString, &ds); |
| 866 |
|
| 867 |
Tcl_DStringFree(&srcString); |
| 868 |
Tcl_DStringFree(&dstString); |
| 869 |
|
| 870 |
if (ret != TCL_OK) { |
| 871 |
if (!strcmp(Tcl_DStringValue(&ds), Tcl_GetString(normSrcPtr))) { |
| 872 |
*errorPtr = srcPathPtr; |
| 873 |
} else if (!strcmp(Tcl_DStringValue(&ds), Tcl_GetString(normDestPtr))) { |
| 874 |
*errorPtr = destPathPtr; |
| 875 |
} else { |
| 876 |
*errorPtr = Tcl_NewStringObj(Tcl_DStringValue(&ds), -1); |
| 877 |
} |
| 878 |
Tcl_DStringFree(&ds); |
| 879 |
Tcl_IncrRefCount(*errorPtr); |
| 880 |
} |
| 881 |
return ret; |
| 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 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
int |
| 914 |
TclpObjRemoveDirectory(pathPtr, recursive, errorPtr) |
| 915 |
Tcl_Obj *pathPtr; |
| 916 |
int recursive; |
| 917 |
Tcl_Obj **errorPtr; |
| 918 |
{ |
| 919 |
Tcl_DString ds; |
| 920 |
Tcl_Obj *normPtr = NULL; |
| 921 |
int ret; |
| 922 |
if (recursive) { |
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
Tcl_DString native; |
| 929 |
normPtr = Tcl_FSGetNormalizedPath(NULL, pathPtr); |
| 930 |
Tcl_WinUtfToTChar(Tcl_GetString(normPtr), -1, &native); |
| 931 |
ret = DoRemoveDirectory(&native, recursive, &ds); |
| 932 |
Tcl_DStringFree(&native); |
| 933 |
} else { |
| 934 |
ret = DoRemoveJustDirectory(Tcl_FSGetNativePath(pathPtr), |
| 935 |
0, &ds); |
| 936 |
} |
| 937 |
if (ret != TCL_OK) { |
| 938 |
int len = Tcl_DStringLength(&ds); |
| 939 |
if (len > 0) { |
| 940 |
if (normPtr != NULL |
| 941 |
&& !strcmp(Tcl_DStringValue(&ds), Tcl_GetString(normPtr))) { |
| 942 |
*errorPtr = pathPtr; |
| 943 |
} else { |
| 944 |
*errorPtr = Tcl_NewStringObj(Tcl_DStringValue(&ds), -1); |
| 945 |
} |
| 946 |
Tcl_IncrRefCount(*errorPtr); |
| 947 |
} |
| 948 |
Tcl_DStringFree(&ds); |
| 949 |
} |
| 950 |
return ret; |
| 951 |
} |
| 952 |
|
| 953 |
static int |
| 954 |
DoRemoveJustDirectory( |
| 955 |
CONST TCHAR *nativePath, |
| 956 |
|
| 957 |
int ignoreError, |
| 958 |
|
| 959 |
|
| 960 |
Tcl_DString *errorPtr) |
| 961 |
|
| 962 |
|
| 963 |
{ |
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
if (nativePath == NULL || nativePath[0] == '\0') { |
| 970 |
Tcl_SetErrno(ENOENT); |
| 971 |
goto end; |
| 972 |
} |
| 973 |
|
| 974 |
if ((*tclWinProcs->removeDirectoryProc)(nativePath) != FALSE) { |
| 975 |
return TCL_OK; |
| 976 |
} |
| 977 |
TclWinConvertError(GetLastError()); |
| 978 |
|
| 979 |
if (Tcl_GetErrno() == EACCES) { |
| 980 |
DWORD attr = (*tclWinProcs->getFileAttributesProc)(nativePath); |
| 981 |
if (attr != 0xffffffff) { |
| 982 |
if ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0) { |
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
Tcl_SetErrno(ENOTDIR); |
| 989 |
goto end; |
| 990 |
} |
| 991 |
|
| 992 |
if (attr & FILE_ATTRIBUTE_REPARSE_POINT) { |
| 993 |
|
| 994 |
if (TclWinSymLinkDelete(nativePath, 1) != 0) { |
| 995 |
goto end; |
| 996 |
} |
| 997 |
} |
| 998 |
|
| 999 |
if (attr & FILE_ATTRIBUTE_READONLY) { |
| 1000 |
attr &= ~FILE_ATTRIBUTE_READONLY; |
| 1001 |
if ((*tclWinProcs->setFileAttributesProc)(nativePath, attr) == FALSE) { |
| 1002 |
goto end; |
| 1003 |
} |
| 1004 |
if ((*tclWinProcs->removeDirectoryProc)(nativePath) != FALSE) { |
| 1005 |
return TCL_OK; |
| 1006 |
} |
| 1007 |
TclWinConvertError(GetLastError()); |
| 1008 |
(*tclWinProcs->setFileAttributesProc)(nativePath, |
| 1009 |
attr | FILE_ATTRIBUTE_READONLY); |
| 1010 |
} |
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
if (TclWinGetPlatformId() != VER_PLATFORM_WIN32_NT) { |
| 1019 |
CONST char *path, *find; |
| 1020 |
HANDLE handle; |
| 1021 |
WIN32_FIND_DATAA data; |
| 1022 |
Tcl_DString buffer; |
| 1023 |
int len; |
| 1024 |
|
| 1025 |
path = (CONST char *) nativePath; |
| 1026 |
|
| 1027 |
Tcl_DStringInit(&buffer); |
| 1028 |
len = strlen(path); |
| 1029 |
find = Tcl_DStringAppend(&buffer, path, len); |
| 1030 |
if ((len > 0) && (find[len - 1] != '\\')) { |
| 1031 |
Tcl_DStringAppend(&buffer, "\\", 1); |
| 1032 |
} |
| 1033 |
find = Tcl_DStringAppend(&buffer, "*.*", 3); |
| 1034 |
handle = FindFirstFileA(find, &data); |
| 1035 |
if (handle != INVALID_HANDLE_VALUE) { |
| 1036 |
while (1) { |
| 1037 |
if ((strcmp(data.cFileName, ".") != 0) |
| 1038 |
&& (strcmp(data.cFileName, "..") != 0)) { |
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
Tcl_SetErrno(EEXIST); |
| 1044 |
break; |
| 1045 |
} |
| 1046 |
if (FindNextFileA(handle, &data) == FALSE) { |
| 1047 |
break; |
| 1048 |
} |
| 1049 |
} |
| 1050 |
FindClose(handle); |
| 1051 |
} |
| 1052 |
Tcl_DStringFree(&buffer); |
| 1053 |
} |
| 1054 |
} |
| 1055 |
} |
| 1056 |
if (Tcl_GetErrno() == ENOTEMPTY) { |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
Tcl_SetErrno(EEXIST); |
| 1063 |
} |
| 1064 |
if ((ignoreError != 0) && (Tcl_GetErrno() == EEXIST)) { |
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
return TCL_ERROR; |
| 1071 |
} |
| 1072 |
|
| 1073 |
end: |
| 1074 |
if (errorPtr != NULL) { |
| 1075 |
Tcl_WinTCharToUtf(nativePath, -1, errorPtr); |
| 1076 |
} |
| 1077 |
return TCL_ERROR; |
| 1078 |
|
| 1079 |
} |
| 1080 |
|
| 1081 |
static int |
| 1082 |
DoRemoveDirectory( |
| 1083 |
Tcl_DString *pathPtr, |
| 1084 |
|
| 1085 |
int recursive, |
| 1086 |
|
| 1087 |
|
| 1088 |
Tcl_DString *errorPtr) |
| 1089 |
|
| 1090 |
|
| 1091 |
{ |
| 1092 |
int res = DoRemoveJustDirectory(Tcl_DStringValue(pathPtr), recursive, |
| 1093 |
errorPtr); |
| 1094 |
|
| 1095 |
if ((res == TCL_ERROR) && (recursive != 0) && (Tcl_GetErrno() == EEXIST)) { |
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
return TraverseWinTree(TraversalDelete, pathPtr, NULL, errorPtr); |
| 1101 |
} else { |
| 1102 |
return res; |
| 1103 |
} |
| 1104 |
} |
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
static int |
| 1129 |
TraverseWinTree( |
| 1130 |
TraversalProc *traverseProc, |
| 1131 |
|
| 1132 |
Tcl_DString *sourcePtr, |
| 1133 |
|
| 1134 |
Tcl_DString *targetPtr, |
| 1135 |
|
| 1136 |
|
| 1137 |
Tcl_DString *errorPtr) |
| 1138 |
|
| 1139 |
|
| 1140 |
{ |
| 1141 |
DWORD sourceAttr; |
| 1142 |
TCHAR *nativeSource, *nativeTarget, *nativeErrfile; |
| 1143 |
int result, found, sourceLen, targetLen, oldSourceLen, oldTargetLen; |
| 1144 |
HANDLE handle; |
| 1145 |
WIN32_FIND_DATAT data; |
| 1146 |
|
| 1147 |
nativeErrfile = NULL; |
| 1148 |
result = TCL_OK; |
| 1149 |
oldTargetLen = 0; |
| 1150 |
|
| 1151 |
nativeSource = (TCHAR *) Tcl_DStringValue(sourcePtr); |
| 1152 |
nativeTarget = (TCHAR *) (targetPtr == NULL |
| 1153 |
? NULL : Tcl_DStringValue(targetPtr)); |
| 1154 |
|
| 1155 |
oldSourceLen = Tcl_DStringLength(sourcePtr); |
| 1156 |
sourceAttr = (*tclWinProcs->getFileAttributesProc)(nativeSource); |
| 1157 |
if (sourceAttr == 0xffffffff) { |
| 1158 |
nativeErrfile = nativeSource; |
| 1159 |
goto end; |
| 1160 |
} |
| 1161 |
if ((sourceAttr & FILE_ATTRIBUTE_DIRECTORY) == 0) { |
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
return (*traverseProc)(nativeSource, nativeTarget, DOTREE_F, errorPtr); |
| 1167 |
} |
| 1168 |
|
| 1169 |
if (tclWinProcs->useWide) { |
| 1170 |
Tcl_DStringAppend(sourcePtr, (char *) L"\\*.*", 4 * sizeof(WCHAR) + 1); |
| 1171 |
Tcl_DStringSetLength(sourcePtr, Tcl_DStringLength(sourcePtr) - 1); |
| 1172 |
} else { |
| 1173 |
Tcl_DStringAppend(sourcePtr, "\\*.*", 4); |
| 1174 |
} |
| 1175 |
nativeSource = (TCHAR *) Tcl_DStringValue(sourcePtr); |
| 1176 |
handle = (*tclWinProcs->findFirstFileProc)(nativeSource, &data); |
| 1177 |
if (handle == INVALID_HANDLE_VALUE) { |
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
TclWinConvertError(GetLastError()); |
| 1183 |
nativeErrfile = nativeSource; |
| 1184 |
goto end; |
| 1185 |
} |
| 1186 |
|
| 1187 |
nativeSource[oldSourceLen + 1] = '\0'; |
| 1188 |
Tcl_DStringSetLength(sourcePtr, oldSourceLen); |
| 1189 |
result = (*traverseProc)(nativeSource, nativeTarget, DOTREE_PRED, errorPtr); |
| 1190 |
if (result != TCL_OK) { |
| 1191 |
FindClose(handle); |
| 1192 |
return result; |
| 1193 |
} |
| 1194 |
|
| 1195 |
sourceLen = oldSourceLen; |
| 1196 |
|
| 1197 |
if (tclWinProcs->useWide) { |
| 1198 |
sourceLen += sizeof(WCHAR); |
| 1199 |
Tcl_DStringAppend(sourcePtr, (char *) L"\\", sizeof(WCHAR) + 1); |
| 1200 |
Tcl_DStringSetLength(sourcePtr, sourceLen); |
| 1201 |
} else { |
| 1202 |
sourceLen += 1; |
| 1203 |
Tcl_DStringAppend(sourcePtr, "\\", 1); |
| 1204 |
} |
| 1205 |
if (targetPtr != NULL) { |
| 1206 |
oldTargetLen = Tcl_DStringLength(targetPtr); |
| 1207 |
|
| 1208 |
targetLen = oldTargetLen; |
| 1209 |
if (tclWinProcs->useWide) { |
| 1210 |
targetLen += sizeof(WCHAR); |
| 1211 |
Tcl_DStringAppend(targetPtr, (char *) L"\\", sizeof(WCHAR) + 1); |
| 1212 |
Tcl_DStringSetLength(targetPtr, targetLen); |
| 1213 |
} else { |
| 1214 |
targetLen += 1; |
| 1215 |
Tcl_DStringAppend(targetPtr, "\\", 1); |
| 1216 |
} |
| 1217 |
} |
| 1218 |
|
| 1219 |
found = 1; |
| 1220 |
for ( ; found; found = (*tclWinProcs->findNextFileProc)(handle, &data)) { |
| 1221 |
TCHAR *nativeName; |
| 1222 |
int len; |
| 1223 |
|
| 1224 |
if (tclWinProcs->useWide) { |
| 1225 |
WCHAR *wp; |
| 1226 |
|
| 1227 |
wp = data.w.cFileName; |
| 1228 |
if (*wp == '.') { |
| 1229 |
wp++; |
| 1230 |
if (*wp == '.') { |
| 1231 |
wp++; |
| 1232 |
} |
| 1233 |
if (*wp == '\0') { |
| 1234 |
continue; |
| 1235 |
} |
| 1236 |
} |
| 1237 |
nativeName = (TCHAR *) data.w.cFileName; |
| 1238 |
len = Tcl_UniCharLen(data.w.cFileName) * sizeof(WCHAR); |
| 1239 |
} else { |
| 1240 |
if ((strcmp(data.a.cFileName, ".") == 0) |
| 1241 |
|| (strcmp(data.a.cFileName, "..") == 0)) { |
| 1242 |
continue; |
| 1243 |
} |
| 1244 |
nativeName = (TCHAR *) data.a.cFileName; |
| 1245 |
len = strlen(data.a.cFileName); |
| 1246 |
} |
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
Tcl_DStringAppend(sourcePtr, (char *) nativeName, len + 1); |
| 1253 |
Tcl_DStringSetLength(sourcePtr, Tcl_DStringLength(sourcePtr) - 1); |
| 1254 |
if (targetPtr != NULL) { |
| 1255 |
Tcl_DStringAppend(targetPtr, (char *) nativeName, len + 1); |
| 1256 |
Tcl_DStringSetLength(targetPtr, Tcl_DStringLength(targetPtr) - 1); |
| 1257 |
} |
| 1258 |
result = TraverseWinTree(traverseProc, sourcePtr, targetPtr, |
| 1259 |
errorPtr); |
| 1260 |
if (result != TCL_OK) { |
| 1261 |
break; |
| 1262 |
} |
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
Tcl_DStringSetLength(sourcePtr, sourceLen); |
| 1269 |
if (targetPtr != NULL) { |
| 1270 |
Tcl_DStringSetLength(targetPtr, targetLen); |
| 1271 |
} |
| 1272 |
} |
| 1273 |
FindClose(handle); |
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
Tcl_DStringSetLength(sourcePtr, oldSourceLen + 1); |
| 1280 |
Tcl_DStringSetLength(sourcePtr, oldSourceLen); |
| 1281 |
if (targetPtr != NULL) { |
| 1282 |
Tcl_DStringSetLength(targetPtr, oldTargetLen + 1); |
| 1283 |
Tcl_DStringSetLength(targetPtr, oldTargetLen); |
| 1284 |
} |
| 1285 |
if (result == TCL_OK) { |
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
result = (*traverseProc)(Tcl_DStringValue(sourcePtr), |
| 1292 |
(targetPtr == NULL ? NULL : Tcl_DStringValue(targetPtr)), |
| 1293 |
DOTREE_POSTD, errorPtr); |
| 1294 |
} |
| 1295 |
end: |
| 1296 |
if (nativeErrfile != NULL) { |
| 1297 |
TclWinConvertError(GetLastError()); |
| 1298 |
if (errorPtr != NULL) { |
| 1299 |
Tcl_WinTCharToUtf(nativeErrfile, -1, errorPtr); |
| 1300 |
} |
| 1301 |
result = TCL_ERROR; |
| 1302 |
} |
| 1303 |
|
| 1304 |
return result; |
| 1305 |
} |
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
static int |
| 1325 |
TraversalCopy( |
| 1326 |
CONST TCHAR *nativeSrc, |
| 1327 |
CONST TCHAR *nativeDst, |
| 1328 |
int type, |
| 1329 |
Tcl_DString *errorPtr) |
| 1330 |
|
| 1331 |
{ |
| 1332 |
switch (type) { |
| 1333 |
case DOTREE_F: { |
| 1334 |
if (DoCopyFile(nativeSrc, nativeDst) == TCL_OK) { |
| 1335 |
return TCL_OK; |
| 1336 |
} |
| 1337 |
break; |
| 1338 |
} |
| 1339 |
case DOTREE_PRED: { |
| 1340 |
if (DoCreateDirectory(nativeDst) == TCL_OK) { |
| 1341 |
DWORD attr = (*tclWinProcs->getFileAttributesProc)(nativeSrc); |
| 1342 |
if ((*tclWinProcs->setFileAttributesProc)(nativeDst, attr) != FALSE) { |
| 1343 |
return TCL_OK; |
| 1344 |
} |
| 1345 |
TclWinConvertError(GetLastError()); |
| 1346 |
} |
| 1347 |
break; |
| 1348 |
} |
| 1349 |
case DOTREE_POSTD: { |
| 1350 |
return TCL_OK; |
| 1351 |
} |
| 1352 |
} |
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
if (errorPtr != NULL) { |
| 1360 |
Tcl_WinTCharToUtf(nativeDst, -1, errorPtr); |
| 1361 |
} |
| 1362 |
return TCL_ERROR; |
| 1363 |
} |
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
static int |
| 1387 |
TraversalDelete( |
| 1388 |
CONST TCHAR *nativeSrc, |
| 1389 |
CONST TCHAR *dstPtr, |
| 1390 |
int type, |
| 1391 |
Tcl_DString *errorPtr) |
| 1392 |
|
| 1393 |
{ |
| 1394 |
switch (type) { |
| 1395 |
case DOTREE_F: { |
| 1396 |
if (TclpDeleteFile(nativeSrc) == TCL_OK) { |
| 1397 |
return TCL_OK; |
| 1398 |
} |
| 1399 |
break; |
| 1400 |
} |
| 1401 |
case DOTREE_PRED: { |
| 1402 |
return TCL_OK; |
| 1403 |
} |
| 1404 |
case DOTREE_POSTD: { |
| 1405 |
if (DoRemoveJustDirectory(nativeSrc, 0, NULL) == TCL_OK) { |
| 1406 |
return TCL_OK; |
| 1407 |
} |
| 1408 |
break; |
| 1409 |
} |
| 1410 |
} |
| 1411 |
|
| 1412 |
if (errorPtr != NULL) { |
| 1413 |
Tcl_WinTCharToUtf(nativeSrc, -1, errorPtr); |
| 1414 |
} |
| 1415 |
return TCL_ERROR; |
| 1416 |
} |
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
static void |
| 1436 |
StatError( |
| 1437 |
Tcl_Interp *interp, |
| 1438 |
Tcl_Obj *fileName) |
| 1439 |
|
| 1440 |
{ |
| 1441 |
TclWinConvertError(GetLastError()); |
| 1442 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 1443 |
"could not read \"", Tcl_GetString(fileName), |
| 1444 |
"\": ", Tcl_PosixError(interp), |
| 1445 |
(char *) NULL); |
| 1446 |
} |
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
static int |
| 1468 |
GetWinFileAttributes( |
| 1469 |
Tcl_Interp *interp, |
| 1470 |
int objIndex, |
| 1471 |
Tcl_Obj *fileName, |
| 1472 |
Tcl_Obj **attributePtrPtr) |
| 1473 |
{ |
| 1474 |
DWORD result; |
| 1475 |
CONST TCHAR *nativeName; |
| 1476 |
int attr; |
| 1477 |
|
| 1478 |
nativeName = Tcl_FSGetNativePath(fileName); |
| 1479 |
result = (*tclWinProcs->getFileAttributesProc)(nativeName); |
| 1480 |
|
| 1481 |
if (result == 0xffffffff) { |
| 1482 |
StatError(interp, fileName); |
| 1483 |
return TCL_ERROR; |
| 1484 |
} |
| 1485 |
|
| 1486 |
attr = (int)(result & attributeArray[objIndex]); |
| 1487 |
if ((objIndex == WIN_HIDDEN_ATTRIBUTE) && (attr != 0)) { |
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
int len; |
| 1496 |
char *str = Tcl_GetStringFromObj(fileName,&len); |
| 1497 |
if (len < 4) { |
| 1498 |
if (len == 0) { |
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
} else if (len == 1 && (str[0] == '/' || str[0] == '\\')) { |
| 1504 |
|
| 1505 |
attr = 0; |
| 1506 |
} else if ((str[1] == ':') |
| 1507 |
&& (len == 2 || (str[2] == '/' || str[2] == '\\'))) { |
| 1508 |
|
| 1509 |
attr = 0; |
| 1510 |
} |
| 1511 |
} |
| 1512 |
} |
| 1513 |
*attributePtrPtr = Tcl_NewBooleanObj(attr); |
| 1514 |
return TCL_OK; |
| 1515 |
} |
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
static int |
| 1542 |
ConvertFileNameFormat( |
| 1543 |
Tcl_Interp *interp, |
| 1544 |
int objIndex, |
| 1545 |
Tcl_Obj *fileName, |
| 1546 |
int longShort, |
| 1547 |
Tcl_Obj **attributePtrPtr) |
| 1548 |
{ |
| 1549 |
int pathc, i; |
| 1550 |
Tcl_Obj *splitPath; |
| 1551 |
int result = TCL_OK; |
| 1552 |
|
| 1553 |
splitPath = Tcl_FSSplitPath(fileName, &pathc); |
| 1554 |
|
| 1555 |
if (splitPath == NULL || pathc == 0) { |
| 1556 |
if (interp != NULL) { |
| 1557 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 1558 |
"could not read \"", Tcl_GetString(fileName), |
| 1559 |
"\": no such file or directory", |
| 1560 |
(char *) NULL); |
| 1561 |
} |
| 1562 |
result = TCL_ERROR; |
| 1563 |
goto cleanup; |
| 1564 |
} |
| 1565 |
|
| 1566 |
for (i = 0; i < pathc; i++) { |
| 1567 |
Tcl_Obj *elt; |
| 1568 |
char *pathv; |
| 1569 |
int pathLen; |
| 1570 |
Tcl_ListObjIndex(NULL, splitPath, i, &elt); |
| 1571 |
|
| 1572 |
pathv = Tcl_GetStringFromObj(elt, &pathLen); |
| 1573 |
if ((pathv[0] == '/') |
| 1574 |
|| ((pathLen == 3) && (pathv[1] == ':')) |
| 1575 |
|| (strcmp(pathv, ".") == 0) |
| 1576 |
|| (strcmp(pathv, "..") == 0)) { |
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
simple: |
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
pathv[0] = (char) Tcl_UniCharToUpper(UCHAR(pathv[0])); |
| 1588 |
} else { |
| 1589 |
Tcl_Obj *tempPath; |
| 1590 |
Tcl_DString ds; |
| 1591 |
Tcl_DString dsTemp; |
| 1592 |
TCHAR *nativeName; |
| 1593 |
char *tempString; |
| 1594 |
int tempLen; |
| 1595 |
WIN32_FIND_DATAT data; |
| 1596 |
HANDLE handle; |
| 1597 |
DWORD attr; |
| 1598 |
|
| 1599 |
tempPath = Tcl_FSJoinPath(splitPath, i+1); |
| 1600 |
Tcl_IncrRefCount(tempPath); |
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
Tcl_DStringInit(&ds); |
| 1606 |
tempString = Tcl_GetStringFromObj(tempPath,&tempLen); |
| 1607 |
nativeName = Tcl_WinUtfToTChar(tempString, tempLen, &ds); |
| 1608 |
Tcl_DecrRefCount(tempPath); |
| 1609 |
handle = (*tclWinProcs->findFirstFileProc)(nativeName, &data); |
| 1610 |
if (handle == INVALID_HANDLE_VALUE) { |
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
attr = (*tclWinProcs->getFileAttributesProc)(nativeName); |
| 1619 |
if ((attr != 0xFFFFFFFF) && (attr & FILE_ATTRIBUTE_DIRECTORY)) { |
| 1620 |
Tcl_DStringFree(&ds); |
| 1621 |
goto simple; |
| 1622 |
} |
| 1623 |
} |
| 1624 |
|
| 1625 |
if (handle == INVALID_HANDLE_VALUE) { |
| 1626 |
Tcl_DStringFree(&ds); |
| 1627 |
if (interp != NULL) { |
| 1628 |
StatError(interp, fileName); |
| 1629 |
} |
| 1630 |
result = TCL_ERROR; |
| 1631 |
goto cleanup; |
| 1632 |
} |
| 1633 |
if (tclWinProcs->useWide) { |
| 1634 |
nativeName = (TCHAR *) data.w.cAlternateFileName; |
| 1635 |
if (longShort) { |
| 1636 |
if (data.w.cFileName[0] != '\0') { |
| 1637 |
nativeName = (TCHAR *) data.w.cFileName; |
| 1638 |
} |
| 1639 |
} else { |
| 1640 |
if (data.w.cAlternateFileName[0] == '\0') { |
| 1641 |
nativeName = (TCHAR *) data.w.cFileName; |
| 1642 |
} |
| 1643 |
} |
| 1644 |
} else { |
| 1645 |
nativeName = (TCHAR *) data.a.cAlternateFileName; |
| 1646 |
if (longShort) { |
| 1647 |
if (data.a.cFileName[0] != '\0') { |
| 1648 |
nativeName = (TCHAR *) data.a.cFileName; |
| 1649 |
} |
| 1650 |
} else { |
| 1651 |
if (data.a.cAlternateFileName[0] == '\0') { |
| 1652 |
nativeName = (TCHAR *) data.a.cFileName; |
| 1653 |
} |
| 1654 |
} |
| 1655 |
} |
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
Tcl_DStringInit(&dsTemp); |
| 1670 |
Tcl_WinTCharToUtf(nativeName, -1, &dsTemp); |
| 1671 |
|
| 1672 |
if (Tcl_DStringValue(&dsTemp)[0] == '~') { |
| 1673 |
tempPath = Tcl_NewStringObj("./",2); |
| 1674 |
Tcl_AppendToObj(tempPath, Tcl_DStringValue(&dsTemp), |
| 1675 |
Tcl_DStringLength(&dsTemp)); |
| 1676 |
} else { |
| 1677 |
tempPath = Tcl_NewStringObj(Tcl_DStringValue(&dsTemp), |
| 1678 |
Tcl_DStringLength(&dsTemp)); |
| 1679 |
} |
| 1680 |
Tcl_ListObjReplace(NULL, splitPath, i, 1, 1, &tempPath); |
| 1681 |
Tcl_DStringFree(&ds); |
| 1682 |
Tcl_DStringFree(&dsTemp); |
| 1683 |
FindClose(handle); |
| 1684 |
} |
| 1685 |
} |
| 1686 |
|
| 1687 |
*attributePtrPtr = Tcl_FSJoinPath(splitPath, -1); |
| 1688 |
|
| 1689 |
cleanup: |
| 1690 |
if (splitPath != NULL) { |
| 1691 |
Tcl_DecrRefCount(splitPath); |
| 1692 |
} |
| 1693 |
|
| 1694 |
return result; |
| 1695 |
} |
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
static int |
| 1717 |
GetWinFileLongName( |
| 1718 |
Tcl_Interp *interp, |
| 1719 |
int objIndex, |
| 1720 |
Tcl_Obj *fileName, |
| 1721 |
Tcl_Obj **attributePtrPtr) |
| 1722 |
{ |
| 1723 |
return ConvertFileNameFormat(interp, objIndex, fileName, 1, attributePtrPtr); |
| 1724 |
} |
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
static int |
| 1746 |
GetWinFileShortName( |
| 1747 |
Tcl_Interp *interp, |
| 1748 |
int objIndex, |
| 1749 |
Tcl_Obj *fileName, |
| 1750 |
Tcl_Obj **attributePtrPtr) |
| 1751 |
{ |
| 1752 |
return ConvertFileNameFormat(interp, objIndex, fileName, 0, attributePtrPtr); |
| 1753 |
} |
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
static int |
| 1773 |
SetWinFileAttributes( |
| 1774 |
Tcl_Interp *interp, |
| 1775 |
int objIndex, |
| 1776 |
Tcl_Obj *fileName, |
| 1777 |
Tcl_Obj *attributePtr) |
| 1778 |
{ |
| 1779 |
DWORD fileAttributes; |
| 1780 |
int yesNo; |
| 1781 |
int result; |
| 1782 |
CONST TCHAR *nativeName; |
| 1783 |
|
| 1784 |
nativeName = Tcl_FSGetNativePath(fileName); |
| 1785 |
fileAttributes = (*tclWinProcs->getFileAttributesProc)(nativeName); |
| 1786 |
|
| 1787 |
if (fileAttributes == 0xffffffff) { |
| 1788 |
StatError(interp, fileName); |
| 1789 |
return TCL_ERROR; |
| 1790 |
} |
| 1791 |
|
| 1792 |
result = Tcl_GetBooleanFromObj(interp, attributePtr, &yesNo); |
| 1793 |
if (result != TCL_OK) { |
| 1794 |
return result; |
| 1795 |
} |
| 1796 |
|
| 1797 |
if (yesNo) { |
| 1798 |
fileAttributes |= (attributeArray[objIndex]); |
| 1799 |
} else { |
| 1800 |
fileAttributes &= ~(attributeArray[objIndex]); |
| 1801 |
} |
| 1802 |
|
| 1803 |
if (!(*tclWinProcs->setFileAttributesProc)(nativeName, fileAttributes)) { |
| 1804 |
StatError(interp, fileName); |
| 1805 |
return TCL_ERROR; |
| 1806 |
} |
| 1807 |
|
| 1808 |
return result; |
| 1809 |
} |
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
static int |
| 1829 |
CannotSetAttribute( |
| 1830 |
Tcl_Interp *interp, |
| 1831 |
int objIndex, |
| 1832 |
Tcl_Obj *fileName, |
| 1833 |
Tcl_Obj *attributePtr) |
| 1834 |
{ |
| 1835 |
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), |
| 1836 |
"cannot set attribute \"", tclpFileAttrStrings[objIndex], |
| 1837 |
"\" for file \"", Tcl_GetString(fileName), |
| 1838 |
"\": attribute is readonly", |
| 1839 |
(char *) NULL); |
| 1840 |
return TCL_ERROR; |
| 1841 |
} |
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
Tcl_Obj* |
| 1861 |
TclpObjListVolumes(void) |
| 1862 |
{ |
| 1863 |
Tcl_Obj *resultPtr, *elemPtr; |
| 1864 |
char buf[40 * 4]; |
| 1865 |
int i; |
| 1866 |
char *p; |
| 1867 |
|
| 1868 |
resultPtr = Tcl_NewObj(); |
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
if (GetLogicalDriveStringsA(sizeof(buf), buf) == 0) { |
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
buf[1] = ':'; |
| 1887 |
buf[2] = '/'; |
| 1888 |
buf[3] = '\0'; |
| 1889 |
|
| 1890 |
for (i = 0; i < 26; i++) { |
| 1891 |
buf[0] = (char) ('a' + i); |
| 1892 |
if (GetVolumeInformationA(buf, NULL, 0, NULL, NULL, NULL, NULL, 0) |
| 1893 |
|| (GetLastError() == ERROR_NOT_READY)) { |
| 1894 |
elemPtr = Tcl_NewStringObj(buf, -1); |
| 1895 |
Tcl_ListObjAppendElement(NULL, resultPtr, elemPtr); |
| 1896 |
} |
| 1897 |
} |
| 1898 |
} else { |
| 1899 |
for (p = buf; *p != '\0'; p += 4) { |
| 1900 |
p[2] = '/'; |
| 1901 |
elemPtr = Tcl_NewStringObj(p, -1); |
| 1902 |
Tcl_ListObjAppendElement(NULL, resultPtr, elemPtr); |
| 1903 |
} |
| 1904 |
} |
| 1905 |
|
| 1906 |
Tcl_IncrRefCount(resultPtr); |
| 1907 |
return resultPtr; |
| 1908 |
} |