Debian Codegraph @

strmode.c

raw symbols SCIP
1 /* $OpenBSD: strmode.c,v 1.8 2015/08/31 02:53:57 guenther Exp $ */
2 /*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <string.h>
34
35 #ifdef MBSDPORT_H
36 #include MBSDPORT_H
37 #endif
38
39 __RCSID("$MirOS: src/bin/pax/strmode.c,v 1.5 2020/09/04 20:32:59 tg Exp $");
40
41 void
42 strmode(mode_t mode, char *p)
43 {
44 /* print type */
45 switch (mode & S_IFMT) {
46 case S_IFDIR: /* directory */
47 *p++ = 'd';
48 break;
49 case S_IFCHR: /* character special device */
50 *p++ = 'c';
51 break;
52 case S_IFBLK: /* block special device */
53 *p++ = 'b';
54 break;
55 case S_IFREG: /* regular file */
56 *p++ = '-';
57 break;
58 case S_IFLNK: /* symbolic link */
59 *p++ = 'l';
60 break;
61 case S_IFSOCK: /* socket */
62 *p++ = 's';
63 break;
64 #ifdef S_IFIFO
65 case S_IFIFO: /* FIFO */
66 *p++ = 'p';
67 break;
68 #endif
69 default: /* unknown */
70 *p++ = '?';
71 break;
72 }
73 /* usr */
74 if (mode & S_IRUSR)
75 *p++ = 'r';
76 else
77 *p++ = '-';
78 if (mode & S_IWUSR)
79 *p++ = 'w';
80 else
81 *p++ = '-';
82 switch (mode & (S_IXUSR | S_ISUID)) {
83 case 0:
84 *p++ = '-';
85 break;
86 case S_IXUSR:
87 *p++ = 'x';
88 break;
89 case S_ISUID:
90 *p++ = 'S';
91 break;
92 case S_IXUSR | S_ISUID:
93 *p++ = 's';
94 break;
95 }
96 /* group */
97 if (mode & S_IRGRP)
98 *p++ = 'r';
99 else
100 *p++ = '-';
101 if (mode & S_IWGRP)
102 *p++ = 'w';
103 else
104 *p++ = '-';
105 switch (mode & (S_IXGRP | S_ISGID)) {
106 case 0:
107 *p++ = '-';
108 break;
109 case S_IXGRP:
110 *p++ = 'x';
111 break;
112 case S_ISGID:
113 *p++ = 'S';
114 break;
115 case S_IXGRP | S_ISGID:
116 *p++ = 's';
117 break;
118 }
119 /* other */
120 if (mode & S_IROTH)
121 *p++ = 'r';
122 else
123 *p++ = '-';
124 if (mode & S_IWOTH)
125 *p++ = 'w';
126 else
127 *p++ = '-';
128 switch (mode & (S_IXOTH | S_ISVTX)) {
129 case 0:
130 *p++ = '-';
131 break;
132 case S_IXOTH:
133 *p++ = 'x';
134 break;
135 case S_ISVTX:
136 *p++ = 'T';
137 break;
138 case S_IXOTH | S_ISVTX:
139 *p++ = 't';
140 break;
141 }
142 *p++ = ' '; /* will be a '+' if ACLs implemented */
143 *p = '\0';
144 }
145 #ifdef DEF_WEAK
146 DEF_WEAK(strmode);
147 #endif