library name fixups
[libmvfs.git] / libmvfs / strmode.c
blob8d938275e3ae15f488468edcfb91f4fb27d58747
1 /* $OpenBSD: strmode.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */
2 /*-
3 * Copyright (c) 1990 The Regents of the University of California.
4 * All rights reserved.
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.
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.
31 #include "mvfs-internal.h"
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <string.h>
37 void mvfs_strmode(mode_t, char *);
39 void
40 mvfs_strmode(mode_t mode, char *p)
42 /* print type */
43 switch (mode & S_IFMT) {
44 case S_IFDIR: /* directory */
45 *p++ = 'd';
46 break;
47 case S_IFCHR: /* character special */
48 *p++ = 'c';
49 break;
50 case S_IFBLK: /* block special */
51 *p++ = 'b';
52 break;
53 case S_IFREG: /* regular */
54 *p++ = '-';
55 break;
56 case S_IFLNK: /* symbolic link */
57 *p++ = 'l';
58 break;
59 case S_IFSOCK: /* socket */
60 *p++ = 's';
61 break;
62 #ifdef S_IFIFO
63 case S_IFIFO: /* fifo */
64 *p++ = 'p';
65 break;
66 #endif
67 default: /* unknown */
68 *p++ = '?';
69 break;
71 /* usr */
72 if (mode & S_IRUSR)
73 *p++ = 'r';
74 else
75 *p++ = '-';
76 if (mode & S_IWUSR)
77 *p++ = 'w';
78 else
79 *p++ = '-';
80 switch (mode & (S_IXUSR | S_ISUID)) {
81 case 0:
82 *p++ = '-';
83 break;
84 case S_IXUSR:
85 *p++ = 'x';
86 break;
87 case S_ISUID:
88 *p++ = 'S';
89 break;
90 case S_IXUSR | S_ISUID:
91 *p++ = 's';
92 break;
94 /* group */
95 if (mode & S_IRGRP)
96 *p++ = 'r';
97 else
98 *p++ = '-';
99 if (mode & S_IWGRP)
100 *p++ = 'w';
101 else
102 *p++ = '-';
103 switch (mode & (S_IXGRP | S_ISGID)) {
104 case 0:
105 *p++ = '-';
106 break;
107 case S_IXGRP:
108 *p++ = 'x';
109 break;
110 case S_ISGID:
111 *p++ = 'S';
112 break;
113 case S_IXGRP | S_ISGID:
114 *p++ = 's';
115 break;
117 /* other */
118 if (mode & S_IROTH)
119 *p++ = 'r';
120 else
121 *p++ = '-';
122 if (mode & S_IWOTH)
123 *p++ = 'w';
124 else
125 *p++ = '-';
126 switch (mode & (S_IXOTH | S_ISVTX)) {
127 case 0:
128 *p++ = '-';
129 break;
130 case S_IXOTH:
131 *p++ = 'x';
132 break;
133 case S_ISVTX:
134 *p++ = 'T';
135 break;
136 case S_IXOTH | S_ISVTX:
137 *p++ = 't';
138 break;
140 *p++ = ' '; /* will be a '+' if ACLs implemented */
141 *p = '\0';