source: trunk/src/gmake/kmkbuiltin/strmode.c@ 426

Last change on this file since 426 was 370, checked in by bird, 20 years ago

o Ported all kmk builtins to win32.
o Fixed serveral bugs in kmk builtins.
o Probably broke both linux, bsd and OS/2. :-)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. 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#if defined(LIBC_SCCS) && !defined(lint)
35static char sccsid[] = "@(#)strmode.c 8.3 (Berkeley) 8/15/94";
36#include <sys/cdefs.h>
37//__FBSDID("$FreeBSD: src/lib/libc/string/strmode.c,v 1.4 2002/03/21 18:44:54 obrien Exp $");
38#endif /* LIBC_SCCS and not lint */
39
40
41#include <sys/types.h>
42#include <sys/stat.h>
43#include <string.h>
44#ifdef _MSC_VER
45#include "mscfakes.h"
46#endif
47
48void
49strmode(mode, p)
50 mode_t mode;
51 char *p;
52{
53 /* print type */
54 switch (mode & S_IFMT) {
55 case S_IFDIR: /* directory */
56 *p++ = 'd';
57 break;
58 case S_IFCHR: /* character special */
59 *p++ = 'c';
60 break;
61#ifdef S_IFBLK
62 case S_IFBLK: /* block special */
63 *p++ = 'b';
64 break;
65#endif
66 case S_IFREG: /* regular */
67 *p++ = '-';
68 break;
69#ifndef _MSC_VER
70 case S_IFLNK: /* symbolic link */
71 *p++ = 'l';
72 break;
73#endif
74#ifdef S_IFSOCK
75 case S_IFSOCK: /* socket */
76 *p++ = 's';
77 break;
78#endif
79#ifdef S_IFIFO
80 case S_IFIFO: /* fifo */
81 *p++ = 'p';
82 break;
83#endif
84#ifdef S_IFWHT
85 case S_IFWHT: /* whiteout */
86 *p++ = 'w';
87 break;
88#endif
89 default: /* unknown */
90 *p++ = '?';
91 break;
92 }
93 /* usr */
94 if (mode & S_IRUSR)
95 *p++ = 'r';
96 else
97 *p++ = '-';
98 if (mode & S_IWUSR)
99 *p++ = 'w';
100 else
101 *p++ = '-';
102 switch (mode & (S_IXUSR | S_ISUID)) {
103 case 0:
104 *p++ = '-';
105 break;
106 case S_IXUSR:
107 *p++ = 'x';
108 break;
109 case S_ISUID:
110 *p++ = 'S';
111 break;
112 case S_IXUSR | S_ISUID:
113 *p++ = 's';
114 break;
115 }
116 /* group */
117 if (mode & S_IRGRP)
118 *p++ = 'r';
119 else
120 *p++ = '-';
121 if (mode & S_IWGRP)
122 *p++ = 'w';
123 else
124 *p++ = '-';
125 switch (mode & (S_IXGRP | S_ISGID)) {
126 case 0:
127 *p++ = '-';
128 break;
129 case S_IXGRP:
130 *p++ = 'x';
131 break;
132 case S_ISGID:
133 *p++ = 'S';
134 break;
135 case S_IXGRP | S_ISGID:
136 *p++ = 's';
137 break;
138 }
139 /* other */
140 if (mode & S_IROTH)
141 *p++ = 'r';
142 else
143 *p++ = '-';
144 if (mode & S_IWOTH)
145 *p++ = 'w';
146 else
147 *p++ = '-';
148#ifdef S_ISVTX
149 switch (mode & (S_IXOTH | S_ISVTX)) {
150#else
151 switch (mode & (S_IXOTH)) {
152#endif
153 case 0:
154 *p++ = '-';
155 break;
156 case S_IXOTH:
157 *p++ = 'x';
158 break;
159#ifdef S_ISVTX
160 case S_ISVTX:
161 *p++ = 'T';
162 break;
163 case S_IXOTH | S_ISVTX:
164 *p++ = 't';
165 break;
166#endif
167 }
168 *p++ = ' '; /* will be a '+' if ACL's implemented */
169 *p = '\0';
170}
Note: See TracBrowser for help on using the repository browser.