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