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