/src/CMake/Utilities/cmlibarchive/libarchive/archive_entry_strmode.c
Line | Count | Source |
1 | | /*- |
2 | | * Copyright (c) 2003-2007 Tim Kientzle |
3 | | * All rights reserved. |
4 | | * |
5 | | * Redistribution and use in source and binary forms, with or without |
6 | | * modification, are permitted provided that the following conditions |
7 | | * are met: |
8 | | * 1. Redistributions of source code must retain the above copyright |
9 | | * notice, this list of conditions and the following disclaimer. |
10 | | * 2. Redistributions in binary form must reproduce the above copyright |
11 | | * notice, this list of conditions and the following disclaimer in the |
12 | | * documentation and/or other materials provided with the distribution. |
13 | | * |
14 | | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR |
15 | | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
16 | | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
17 | | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, |
18 | | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
19 | | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
20 | | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
21 | | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 | | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | | */ |
25 | | |
26 | | #include "archive_platform.h" |
27 | | |
28 | | #ifdef HAVE_SYS_STAT_H |
29 | | #include <sys/stat.h> |
30 | | #endif |
31 | | |
32 | | #include "archive_entry.h" |
33 | | #include "archive_entry_private.h" |
34 | | |
35 | | const char * |
36 | | archive_entry_strmode(struct archive_entry *entry) |
37 | 0 | { |
38 | 0 | char *bp = entry->strmode; |
39 | 0 | mode_t mask, mode; |
40 | 0 | int i; |
41 | |
|
42 | 0 | switch (archive_entry_filetype(entry)) { |
43 | 0 | case AE_IFREG: bp[0] = '-'; break; |
44 | 0 | case AE_IFBLK: bp[0] = 'b'; break; |
45 | 0 | case AE_IFCHR: bp[0] = 'c'; break; |
46 | 0 | case AE_IFDIR: bp[0] = 'd'; break; |
47 | 0 | case AE_IFLNK: bp[0] = 'l'; break; |
48 | 0 | case AE_IFSOCK: bp[0] = 's'; break; |
49 | 0 | case AE_IFIFO: bp[0] = 'p'; break; |
50 | 0 | default: |
51 | 0 | bp[0] = (archive_entry_hardlink(entry) != NULL) ? 'h' : '?'; |
52 | 0 | break; |
53 | 0 | } |
54 | | |
55 | 0 | mode = archive_entry_mode(entry); |
56 | 0 | for (i = 0, mask = 0400; i < 9; i++, mask >>= 1) |
57 | 0 | bp[i + 1] = (mode & mask) ? "rwx"[i % 3] : '-'; |
58 | |
|
59 | 0 | if (mode & S_ISUID) |
60 | 0 | bp[3] = (mode & 0100) ? 's' : 'S'; |
61 | 0 | if (mode & S_ISGID) |
62 | 0 | bp[6] = (mode & 0010) ? 's' : 'S'; |
63 | 0 | if (mode & S_ISVTX) |
64 | 0 | bp[9] = (mode & 0001) ? 't' : 'T'; |
65 | 0 | bp[10] = (archive_entry_acl_types(entry) != 0) ? '+' : ' '; |
66 | 0 | bp[11] = '\0'; |
67 | |
|
68 | 0 | return (bp); |
69 | 0 | } |