/////////////////////////////////////////////////////////////////// Function name : cUnixFSServices::ConvertModeToString Description : takes a TSTRING and fills it with an "ls -l" representation of the object's permission bits ( e.g. "drwxr-x--x" ). Returns : void -- no errors are reported Argument : uint64 perm -- st_mode from "stat" Argument : TSTRING& tstrPerm
| 604 | // Argument : TSTRING& tstrPerm -- converted permissions, ls -l style |
| 605 | // |
| 606 | void cUnixFSServices::ConvertModeToString(uint64 perm, TSTRING& tstrPerm) const |
| 607 | { |
| 608 | TCHAR szPerm[12]; //10 permission bits plus the NULL |
| 609 | strncpy(szPerm, _T("----------"), 11); |
| 610 | |
| 611 | ASSERT(sizeof(unsigned short) <= sizeof(uint32)); |
| 612 | // We do this in case an "unsigned short" is ever larger than the |
| 613 | // value we are switching on, since the size of the mode parameter |
| 614 | // will be unsigned short (whatever that means, for the given platform...) |
| 615 | |
| 616 | // check file type |
| 617 | switch ((uint32)perm & S_IFMT) //some versions of Unix don't like to switch on |
| 618 | //64 bit values. |
| 619 | { |
| 620 | case S_IFDIR: |
| 621 | szPerm[0] = _T('d'); |
| 622 | break; |
| 623 | case S_IFCHR: |
| 624 | szPerm[0] = _T('c'); |
| 625 | break; |
| 626 | case S_IFBLK: |
| 627 | szPerm[0] = _T('b'); |
| 628 | break; |
| 629 | case S_IFIFO: |
| 630 | szPerm[0] = _T('p'); |
| 631 | break; |
| 632 | case S_IFLNK: |
| 633 | szPerm[0] = _T('l'); |
| 634 | break; |
| 635 | |
| 636 | #if HAVE_DOOR_CREATE // Solaris doors |
| 637 | case S_IFDOOR: |
| 638 | szPerm[0] = _T('D'); |
| 639 | break; |
| 640 | #endif |
| 641 | |
| 642 | #if HAVE_PORT_CREATE // Solaris event ports |
| 643 | case S_IFPORT: |
| 644 | szPerm[0] = _T('P'); |
| 645 | break; |
| 646 | #endif |
| 647 | |
| 648 | #ifdef S_IFNAM |
| 649 | case S_IFNAM: |
| 650 | szPerm[0] = _T('n'); |
| 651 | break; |
| 652 | #endif |
| 653 | break; |
| 654 | } |
| 655 | |
| 656 | // check owner read and write |
| 657 | if (perm & S_IRUSR) |
| 658 | szPerm[1] = _T('r'); |
| 659 | if (perm & S_IWUSR) |
| 660 | szPerm[2] = _T('w'); |
| 661 | |
| 662 | // check owner execute |
| 663 | if (perm & S_ISUID && perm & S_IXUSR) |