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