Changeset 5328
- Timestamp:
- 03/01/08 07:13:28 (7 months ago)
- Files:
-
- libwired/trunk/libwired/base/wi-private.h (modified) (1 diff)
- libwired/trunk/libwired/file/wi-file.c (modified) (15 diffs)
- libwired/trunk/libwired/file/wi-file.h (modified) (2 diffs)
- libwired/trunk/libwired/misc/wi-error.c (modified) (5 diffs)
- libwired/trunk/libwired/misc/wi-error.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libwired/trunk/libwired/base/wi-private.h
r5283 r5328 159 159 #endif 160 160 161 WI_EXPORT void wi_error_set_carbon_error(int); 161 162 WI_EXPORT void wi_error_set_libwired_error(int); 162 163 WI_EXPORT void wi_error_set_libwired_p7_error(int, wi_string_t *, ...); libwired/trunk/libwired/file/wi-file.c
r5320 r5328 135 135 136 136 wi_boolean_t wi_file_delete(wi_string_t *path) { 137 struct statsb;137 wi_file_stat_t sb; 138 138 wi_boolean_t result; 139 139 … … 141 141 return false; 142 142 143 if(S_ISDIR(sb. st_mode))143 if(S_ISDIR(sb.mode)) 144 144 result = _wi_file_delete_directory(path); 145 145 else … … 259 259 260 260 wi_boolean_t wi_file_copy(wi_string_t *frompath, wi_string_t *topath) { 261 struct statsb;261 wi_file_stat_t sb; 262 262 int err; 263 263 wi_boolean_t result; … … 269 269 return false; 270 270 271 if(S_ISDIR(sb. st_mode))271 if(S_ISDIR(sb.mode)) 272 272 result = _wi_file_copy_directory(frompath, topath); 273 273 else … … 381 381 382 382 383 wi_boolean_t wi_file_create_directory(wi_string_t *path, mode_t mode) {383 wi_boolean_t wi_file_create_directory(wi_string_t *path, uint32_t mode) { 384 384 if(mkdir(wi_string_cstring(path), mode) < 0) { 385 385 wi_error_set_errno(errno); … … 393 393 394 394 395 wi_boolean_t wi_file_set_mode(wi_string_t *path, mode_t mode) {395 wi_boolean_t wi_file_set_mode(wi_string_t *path, uint32_t mode) { 396 396 if(chmod(wi_string_cstring(path), mode) < 0) { 397 397 wi_error_set_errno(errno); … … 405 405 406 406 407 wi_boolean_t wi_file_stat(wi_string_t *path, struct stat *sp) { 408 if(stat(wi_string_cstring(path), sp) < 0) { 409 wi_error_set_errno(errno); 410 411 return false; 412 } 407 static wi_boolean_t _wi_file_stat(wi_string_t *path, wi_file_stat_t *sp, wi_boolean_t link) { 408 #ifdef HAVE_STAT64 409 struct stat64 sb; 410 411 if((link && lstat64(wi_string_cstring(path), &sb) < 0) || 412 (!link && stat64(wi_string_cstring(path), &sb) < 0)) { 413 wi_error_set_errno(errno); 414 415 return false; 416 } 417 418 sp->dev = sb.st_dev; 419 sp->ino = sb.st_ino; 420 sp->mode = sb.st_mode; 421 sp->nlink = sb.st_nlink; 422 sp->uid = sb.st_uid; 423 sp->gid = sb.st_gid; 424 sp->rdev = sb.st_rdev; 425 sp->atime = sb.st_atime; 426 sp->mtime = sb.st_mtime; 427 sp->ctime = sb.st_ctime; 428 sp->birthtime = sb.st_birthtime; 429 sp->size = sb.st_size; 430 sp->blocks = sb.st_blocks; 431 sp->blksize = sb.st_blksize; 432 sp->flags = sb.st_flags; 433 sp->gen = sb.st_gen; 413 434 414 435 return true; 415 } 416 417 418 419 wi_boolean_t wi_file_lstat(wi_string_t *path, struct stat *sp) { 420 if(lstat(wi_string_cstring(path), sp) < 0) { 421 wi_error_set_errno(errno); 422 423 return false; 424 } 436 #else 437 struct stat sb; 438 439 if((link && lstat(wi_string_cstring(path), &sb) < 0) || 440 (!link && stat(wi_string_cstring(path), &sb) < 0)) { 441 wi_error_set_errno(errno); 442 443 return false; 444 } 445 446 sp->dev = sb.st_dev; 447 sp->ino = sb.st_ino; 448 sp->mode = sb.st_mode; 449 sp->nlink = sb.st_nlink; 450 sp->uid = sb.st_uid; 451 sp->gid = sb.st_gid; 452 sp->rdev = sb.st_rdev; 453 sp->atime = sb.st_atime; 454 sp->mtime = sb.st_mtime; 455 sp->ctime = sb.st_ctime; 456 457 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME 458 sp->birthtime = sb.st_birthtime; 459 #else 460 sp->birthtime = sb.st_ctime; 461 #endif 462 463 sp->size = sb.st_size; 464 sp->blocks = sb.st_blocks; 465 sp->blksize = sb.st_blksize; 466 sp->flags = sb.st_flags; 467 sp->gen = sb.st_gen; 425 468 426 469 return true; 470 #endif 471 } 472 473 474 475 wi_boolean_t wi_file_stat(wi_string_t *path, wi_file_stat_t *sp) { 476 return _wi_file_stat(path, sp, false); 477 } 478 479 480 481 wi_boolean_t wi_file_lstat(wi_string_t *path, wi_file_stat_t *sp) { 482 return _wi_file_stat(path, sp, true); 427 483 } 428 484 … … 439 495 } 440 496 441 sfp-> f_bsize= sfvb.f_bsize;442 sfp->f _frsize= sfvb.f_frsize;443 sfp-> f_blocks= sfvb.f_blocks;444 sfp-> f_bfree= sfvb.f_bfree;445 sfp-> f_bavail= sfvb.f_bavail;446 sfp->f _files= sfvb.f_files;447 sfp->f _ffree= sfvb.f_ffree;448 sfp->f _favail= sfvb.f_favail;449 sfp->f _fsid = sfvb.f_fsid;450 sfp->f _flag = sfvb.f_flag;451 sfp-> f_namemax = sfvb.f_namemax;497 sfp->bsize = sfvb.f_bsize; 498 sfp->frsize = sfvb.f_frsize; 499 sfp->blocks = sfvb.f_blocks; 500 sfp->bfree = sfvb.f_bfree; 501 sfp->bavail = sfvb.f_bavail; 502 sfp->files = sfvb.f_files; 503 sfp->ffree = sfvb.f_ffree; 504 sfp->favail = sfvb.f_favail; 505 sfp->fsid = sfvb.f_fsid; 506 sfp->flag = sfvb.f_flag; 507 sfp->namemax = sfvb.f_namemax; 452 508 #else 453 509 struct statfs sfb; … … 459 515 } 460 516 461 sfp-> f_bsize= sfb.f_iosize;462 sfp->f _frsize= sfb.f_bsize;463 sfp-> f_blocks= sfb.f_blocks;464 sfp-> f_bfree= sfb.f_bfree;465 sfp-> f_bavail= sfb.f_bavail;466 sfp->f _files= sfb.f_files;467 sfp->f _ffree= sfb.f_ffree;468 sfp->f _favail= sfb.f_ffree;469 sfp->f _fsid = sfb.f_fsid.val[0];470 sfp->f _flag = 0;471 sfp-> f_namemax = 0;517 sfp->bsize = sfb.f_iosize; 518 sfp->frsize = sfb.f_bsize; 519 sfp->blocks = sfb.f_blocks; 520 sfp->bfree = sfb.f_bfree; 521 sfp->bavail = sfb.f_bavail; 522 sfp->files = sfb.f_files; 523 sfp->ffree = sfb.f_ffree; 524 sfp->favail = sfb.f_ffree; 525 sfp->fsid = sfb.f_fsid.val[0]; 526 sfp->flag = 0; 527 sfp->namemax = 0; 472 528 #endif 473 529 … … 478 534 479 535 wi_boolean_t wi_file_exists(wi_string_t *path, wi_boolean_t *is_directory) { 480 struct statsb;536 wi_file_stat_t sb; 481 537 482 538 if(!wi_file_stat(path, &sb)) … … 484 540 485 541 if(is_directory) 486 *is_directory = S_ISDIR(sb. st_mode);542 *is_directory = S_ISDIR(sb.mode); 487 543 488 544 return true; … … 495 551 return wi_file_is_alias_cpath(wi_string_cstring(path)); 496 552 #else 553 wi_error_set_libwired_error(WI_ERROR_FILE_NOCARBON); 554 497 555 return false; 498 556 #endif … … 503 561 wi_boolean_t wi_file_is_alias_cpath(const char *cpath) { 504 562 #ifdef HAVE_CORESERVICES_CORESERVICES_H 505 FSRef f sRef;563 FSRef fileRef; 506 564 Boolean isDir, isAlias; 507 508 if(FSPathMakeRef((UInt8 *) cpath, &fsRef, NULL) != noErr) 509 return false; 510 511 if(FSIsAliasFile(&fsRef, &isAlias, &isDir) != noErr) 512 return false; 565 OSErr err; 566 567 err = FSPathMakeRef((UInt8 *) cpath, &fileRef, NULL); 568 569 if(err != noErr) { 570 wi_error_set_carbon_error(err); 571 572 return false; 573 } 574 575 err = FSIsAliasFile(&fileRef, &isAlias, &isDir); 576 577 if(err != noErr) { 578 wi_error_set_carbon_error(err); 579 580 return false; 581 } 513 582 514 583 return isAlias; 515 584 #else 585 wi_error_set_libwired_error(WI_ERROR_FILE_NOCARBON); 586 516 587 return false; 517 588 #endif … … 524 595 return wi_file_is_invisible_cpath(wi_string_cstring(path)); 525 596 #else 597 wi_error_set_libwired_error(WI_ERROR_FILE_NOCARBON); 598 526 599 return false; 527 600 #endif … … 532 605 wi_boolean_t wi_file_is_invisible_cpath(const char *cpath) { 533 606 #ifdef HAVE_CORESERVICES_CORESERVICES_H 534 FSRef f sRef;607 FSRef fileRef; 535 608 FSCatalogInfo catalogInfo; 536 537 if(FSPathMakeRef((UInt8 *) cpath, &fsRef, NULL) != noErr) 538 return false; 539 540 if(FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &catalogInfo, NULL, NULL, NULL) != noErr) 541 return false; 609 OSErr err; 610 611 err = FSPathMakeRef((UInt8 *) cpath, &fileRef, NULL); 612 613 if(err != noErr) { 614 wi_error_set_carbon_error(err); 615 616 return false; 617 } 618 619 err = FSGetCatalogInfo(&fileRef, kFSCatInfoFinderInfo, &catalogInfo, NULL, NULL, NULL); 620 621 if(err != noErr) { 622 wi_error_set_carbon_error(err); 623 624 return false; 625 } 542 626 543 627 return (((FileInfo *) catalogInfo.finderInfo)->finderFlags & kIsInvisible); 544 628 #else 629 wi_error_set_libwired_error(WI_ERROR_FILE_NOCARBON); 630 545 631 return false; 632 #endif 633 } 634 635 636 637 wi_boolean_t wi_file_set_finder_comment(wi_string_t *path, wi_string_t *comment) { 638 #ifdef HAVE_CORESERVICES_CORESERVICES_H 639 FSRef fileRef; 640 AEDesc fileDesc, commentDesc, builtEvent, replyEvent; 641 OSType finderSignature = 'MACS'; 642 OSErr err; 643 const char *event = 644 "'----': 'obj '{ " 645 " form: enum(prop), " 646 " seld: type(comt), " 647 " want: type(prop), " 648 " from: 'obj '{ " 649 " form: enum(indx), " 650 " want: type(file), " 651 " seld: @," 652 " from: null() " 653 " }" 654 " }, " 655 "data: @"; 656 657 err = FSPathMakeRef((UInt8 *) wi_string_cstring(path), &fileRef, NULL); 658 659 if(err != noErr) { 660 wi_error_set_carbon_error(err); 661 662 return false; 663 } 664 665 AEInitializeDesc(&fileDesc); 666 667 err = AECoercePtr(typeFSRef, &fileRef, sizeof(fileRef), typeAlias, &fileDesc); 668 669 if(err != noErr) { 670 wi_error_set_carbon_error(err); 671 672 return false; 673 } 674 675 err = AECreateDesc(typeUTF8Text, wi_string_cstring(comment), wi_string_length(comment), &commentDesc); 676 677 if(err != noErr) { 678 wi_error_set_carbon_error(err); 679 680 return false; 681 } 682 683 AEInitializeDesc(&builtEvent); 684 AEInitializeDesc(&replyEvent); 685 686 err = AEBuildAppleEvent(kAECoreSuite, 687 kAESetData, 688 typeApplSignature, 689 &finderSignature, 690 sizeof(finderSignature), 691 kAutoGenerateReturnID, 692 kAnyTransactionID, 693 &builtEvent, 694 NULL, 695 event, 696 &fileDesc, 697 &commentDesc); 698 699 AEDisposeDesc(&fileDesc); 700 AEDisposeDesc(&commentDesc); 701 702 if(err != noErr) { 703 wi_error_set_carbon_error(err); 704 705 return false; 706 } 707 708 err = AESendMessage(&builtEvent, &replyEvent, kAENoReply, kAEDefaultTimeout); 709 710 AEDisposeDesc(&builtEvent); 711 AEDisposeDesc(&replyEvent); 712 713 if(err != noErr) { 714 wi_error_set_carbon_error(err); 715 716 return false; 717 } 718 719 return true; 720 #else 721 wi_error_set_libwired_error(WI_ERROR_FILE_NOCARBON); 722 723 return false; 724 #endif 725 } 726 727 728 729 wi_string_t * wi_file_finder_comment(wi_string_t *path) { 730 #ifdef HAVE_CORESERVICES_CORESERVICES_H 731 MDItemRef item; 732 CFStringRef cfPath, cfComment = NULL; 733 wi_string_t *comment = NULL; 734 char buffer[1024]; 735 736 cfPath = CFStringCreateWithCString(NULL, wi_string_cstring(path), kCFStringEncodingUTF8); 737 item = MDItemCreate(NULL, cfPath); 738 739 if(!item) { 740 wi_error_set_carbon_error(0); 741 742 goto end; 743 } 744 745 cfComment = MDItemCopyAttribute(item, kMDItemFinderComment); 746 747 if(!CFStringGetCString(cfComment, buffer, sizeof(buffer), kCFStringEncodingUTF8)) { 748 wi_error_set_carbon_error(0); 749 750 goto end; 751 } 752 753 comment = wi_string_with_cstring(buffer); 754 755 end: 756 if(cfPath) 757 CFRelease(cfPath); 758 759 if(cfComment) 760 CFRelease(cfComment); 761 762 if(item) 763 CFRelease(item); 764 765 return comment; 766 #else 767 wi_error_set_libwired_error(WI_ERROR_FILE_NOCARBON); 768 769 return NULL; 546 770 #endif 547 771 } libwired/trunk/libwired/file/wi-file.h
r5320 r5328 43 43 typedef uint64_t wi_file_offset_t; 44 44 45 struct _wi_file_stat { 46 uint32_t dev; 47 uint64_t ino; 48 uint32_t mode; 49 uint32_t nlink; 50 uint32_t uid; 51 uint32_t gid; 52 uint32_t rdev; 53 uint32_t atime; 54 uint32_t mtime; 55 uint32_t ctime; 56 uint32_t birthtime; 57 uint64_t size; 58 uint64_t blocks; 59 uint32_t blksize; 60 uint32_t flags; 61 uint32_t gen; 62 }; 63 typedef struct _wi_file_stat wi_file_stat_t; 64 45 65 struct _wi_file_statfs { 46 wi_uinteger_t f_bsize;47 wi_uinteger_t f_frsize;48 wi_uinteger_t f_blocks;49 wi_uinteger_t f_bfree;50 wi_uinteger_t f_bavail;51 wi_uinteger_t f_files;52 wi_uinteger_t f_ffree;53 wi_uinteger_t f_favail;54 wi_uinteger_t f_fsid;55 wi_uinteger_t f_flag;56 wi_uinteger_t f_namemax;66 uint32_t bsize; 67 uint32_t frsize; 68 uint64_t blocks; 69 uint64_t bfree; 70 uint64_t bavail; 71 uint64_t files; 72 uint64_t ffree; 73 uint64_t favail; 74 uint32_t fsid; 75 uint64_t flag; 76 uint64_t namemax; 57 77 }; 58 78 typedef struct _wi_file_statfs wi_file_statfs_t; … … 77 97 WI_EXPORT wi_boolean_t wi_file_symlink(wi_string_t *, wi_string_t *); 78 98 WI_EXPORT wi_boolean_t wi_file_copy(wi_string_t *, wi_string_t *); 79 WI_EXPORT wi_boolean_t wi_file_stat(wi_string_t *, struct stat *);80 WI_EXPORT wi_boolean_t wi_file_lstat(wi_string_t *, struct stat *);99 WI_EXPORT wi_boolean_t wi_file_stat(wi_string_t *, wi_file_stat_t *); 100 WI_EXPORT wi_boolean_t wi_file_lstat(wi_string_t *, wi_file_stat_t *); 81 101 WI_EXPORT wi_boolean_t wi_file_statfs(wi_string_t *, wi_file_statfs_t *); 82 102 WI_EXPORT wi_boolean_t wi_file_exists(wi_string_t *, wi_boolean_t *); 83 WI_EXPORT wi_boolean_t wi_file_create_directory(wi_string_t *, mode_t);84 WI_EXPORT wi_boolean_t wi_file_set_mode(wi_string_t *, mode_t);103 WI_EXPORT wi_boolean_t wi_file_create_directory(wi_string_t *, uint32_t); 104 WI_EXPORT wi_boolean_t wi_file_set_mode(wi_string_t *, uint32_t); 85 105 WI_EXPORT wi_boolean_t wi_file_is_alias(wi_string_t *); 86 106 WI_EXPORT wi_boolean_t wi_file_is_alias_cpath(const char *); 87 107 WI_EXPORT wi_boolean_t wi_file_is_invisible(wi_string_t *); 88 108 WI_EXPORT wi_boolean_t wi_file_is_invisible_cpath(const char *); 109 WI_EXPORT wi_boolean_t wi_file_set_finder_comment(wi_string_t *, wi_string_t *); 110 WI_EXPORT wi_string_t * wi_file_finder_comment(wi_string_t *); 89 111 90 112 WI_EXPORT wi_array_t * wi_file_directory_contents_at_path(wi_string_t *); libwired/trunk/libwired/misc/wi-error.c
r5295 r5328 86 86 "No available addresses", 87 87 88 /* WI_ERROR_FILE_NOCARBON */ 89 "Carbon not supported", 90 88 91 /* WI_ERROR_HOST_NOAVAILABLEADDRESSES */ 89 92 "No available addresses", … … 132 135 "No valid cipher", 133 136 /* WI_ERROR_SOCKET_NOSSL */ 134 " Socket has no SSL support",137 "OpenSSL not supported", 135 138 /* WI_ERROR_SOCKET_EOF */ 136 139 "End of file", … … 325 328 326 329 330 void wi_error_set_carbon_error(int code) { 331 wi_error_set_error(WI_ERROR_DOMAIN_CARBON, code); 332 } 333 334 335 327 336 void wi_error_set_libwired_error(int code) { 328 337 wi_error_set_error(WI_ERROR_DOMAIN_LIBWIRED, code); … … 372 381 373 382 case WI_ERROR_DOMAIN_REGEX: 374 break;375 376 383 case WI_ERROR_DOMAIN_OPENSSL: 377 break;378 379 384 case WI_ERROR_DOMAIN_LIBXML2: 380 385 break; … … 385 390 #endif 386 391 break; 392 393 case WI_ERROR_DOMAIN_CARBON: 394 error->string = wi_string_init_with_format(wi_string_alloc(), WI_STR("Carbon: %d"), error->code); 395 break; 387 396 388 397 case WI_ERROR_DOMAIN_NONE: libwired/trunk/libwired/misc/wi-error.h
r5295 r5328 45 45 WI_ERROR_DOMAIN_ZLIB, 46 46 WI_ERROR_DOMAIN_LIBXML2, 47 WI_ERROR_DOMAIN_CARBON, 47 48 WI_ERROR_DOMAIN_LIBWIRED 48 49 }; … … 54 55 55 56 WI_ERROR_ADDRESS_NOAVAILABLEADDRESSES, 57 58 WI_ERROR_FILE_NOCARBON, 56 59 57 60 WI_ERROR_HOST_NOAVAILABLEADDRESSES,
