Debian Codegraph @

src/bsd/strmode.c

raw symbols SCIP
1 /* clang-format off */
2 /*-
3 * Copyright (c) 1990, 1993
4 * The Regents of the University of California. 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 * 4. 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 "bsd/cdefs.h"
32
33 #include <string.h>
34 #include <sys/stat.h>
35 #include <sys/types.h>
36
37 void
38 strmode(mode_t mode, char *p)
39 {
40 /* print type */
41 switch (mode & S_IFMT) {
42 case S_IFDIR: /* directory */
43 *p++ = 'd';
44 break;
45 case S_IFCHR: /* character special */
46 *p++ = 'c';
47 break;
48 case S_IFBLK: /* block special */
49 *p++ = 'b';
50 break;
51 case S_IFREG: /* regular */
52 *p++ = '-';
53 break;
54 case S_IFLNK: /* symbolic link */
55 *p++ = 'l';
56 break;
57 #ifdef S_IFSOCK
58 case S_IFSOCK: /* socket */
59 *p++ = 's';
60 break;
61 #endif
62 #ifdef S_IFIFO
63 case S_IFIFO: /* fifo */
64 *p++ = 'p';
65 break;
66 #endif
67 #ifdef S_IFWHT
68 case S_IFWHT: /* whiteout */
69 *p++ = 'w';
70 break;
71 #endif
72 default: /* unknown */
73 *p++ = '?';
74 break;
75 }
76 /* usr */
77 if (mode & S_IRUSR)
78 *p++ = 'r';
79 else
80 *p++ = '-';
81 if (mode & S_IWUSR)
82 *p++ = 'w';
83 else
84 *p++ = '-';
85 switch (mode & (S_IXUSR | S_ISUID)) {
86 case 0:
87 *p++ = '-';
88 break;
89 case S_IXUSR:
90 *p++ = 'x';
91 break;
92 case S_ISUID:
93 *p++ = 'S';
94 break;
95 case S_IXUSR | S_ISUID:
96 *p++ = 's';
97 break;
98 }
99 /* group */
100 if (mode & S_IRGRP)
101 *p++ = 'r';
102 else
103 *p++ = '-';
104 if (mode & S_IWGRP)
105 *p++ = 'w';
106 else
107 *p++ = '-';
108 switch (mode & (S_IXGRP | S_ISGID)) {
109 case 0:
110 *p++ = '-';
111 break;
112 #ifndef __WIN32
113 case S_IXGRP:
114 *p++ = 'x';
115 break;
116 #endif
117 case S_ISGID:
118 *p++ = 'S';
119 break;
120 #ifndef __WIN32
121 case S_IXGRP | S_ISGID:
122 *p++ = 's';
123 break;
124 #endif
125 }
126 /* other */
127 if (mode & S_IROTH)
128 *p++ = 'r';
129 else
130 *p++ = '-';
131 if (mode & S_IWOTH)
132 *p++ = 'w';
133 else
134 *p++ = '-';
135 switch (mode & (S_IXOTH | S_ISVTX)) {
136 case 0:
137 *p++ = '-';
138 break;
139 #ifndef __WIN32
140 case S_IXOTH:
141 *p++ = 'x';
142 break;
143 case S_ISVTX:
144 *p++ = 'T';
145 break;
146 case S_IXOTH | S_ISVTX:
147 *p++ = 't';
148 break;
149 #endif
150 }
151 *p++ = ' '; /* will be a '+' if ACL's implemented */
152 *p = '\0';
153 }