| 1 | /* $NetBSD: strmode.c,v 1.16 2004/06/20 22:20:15 jmc Exp $ */
|
|---|
| 2 |
|
|---|
| 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.
|
|---|
| 15 | * 3. Neither the name of the University nor the names of its contributors
|
|---|
| 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 |
|
|---|
| 32 | /*#include <sys/cdefs.h>*/
|
|---|
| 33 | #if defined(LIBC_SCCS) && !defined(lint)
|
|---|
| 34 | #if 0
|
|---|
| 35 | static char sccsid[] = "@(#)strmode.c 8.3 (Berkeley) 8/15/94";
|
|---|
| 36 | #else
|
|---|
| 37 | __RCSID("$NetBSD: strmode.c,v 1.16 2004/06/20 22:20:15 jmc Exp $");
|
|---|
| 38 | #endif
|
|---|
| 39 | #endif /* LIBC_SCCS and not lint */
|
|---|
| 40 |
|
|---|
| 41 | #include "config.h"
|
|---|
| 42 | /*#include "namespace.h"*/
|
|---|
| 43 | #include <sys/types.h>
|
|---|
| 44 | #include <sys/stat.h>
|
|---|
| 45 |
|
|---|
| 46 | #include <assert.h>
|
|---|
| 47 | #ifndef _MSC_VER
|
|---|
| 48 | #include <unistd.h>
|
|---|
| 49 | #else
|
|---|
| 50 | #include "mscfakes.h"
|
|---|
| 51 | #endif
|
|---|
| 52 |
|
|---|
| 53 | #ifndef _DIAGASSERT
|
|---|
| 54 | #define _DIAGASSERT assert
|
|---|
| 55 | #endif
|
|---|
| 56 |
|
|---|
| 57 | void
|
|---|
| 58 | bsd_strmode(mode, p)
|
|---|
| 59 | mode_t mode;
|
|---|
| 60 | char *p;
|
|---|
| 61 | {
|
|---|
| 62 |
|
|---|
| 63 | _DIAGASSERT(p != NULL);
|
|---|
| 64 |
|
|---|
| 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;
|
|---|
| 73 | #ifdef S_IFBLK
|
|---|
| 74 | case S_IFBLK: /* block special */
|
|---|
| 75 | *p++ = 'b';
|
|---|
| 76 | break;
|
|---|
| 77 | #endif
|
|---|
| 78 | case S_IFREG: /* regular */
|
|---|
| 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
|
|---|
| 90 | break;
|
|---|
| 91 | #ifdef S_IFLNK
|
|---|
| 92 | case S_IFLNK: /* symbolic link */
|
|---|
| 93 | *p++ = 'l';
|
|---|
| 94 | break;
|
|---|
| 95 | #endif
|
|---|
| 96 | #ifdef S_IFSOCK
|
|---|
| 97 | case S_IFSOCK: /* socket */
|
|---|
| 98 | *p++ = 's';
|
|---|
| 99 | break;
|
|---|
| 100 | #endif
|
|---|
| 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
|
|---|
| 111 | #ifdef S_IFDOOR
|
|---|
| 112 | case S_IFDOOR: /* door */
|
|---|
| 113 | *p++ = 'D';
|
|---|
| 114 | break;
|
|---|
| 115 | #endif
|
|---|
| 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++ = '-';
|
|---|
| 175 | #ifdef S_ISVTX
|
|---|
| 176 | switch (mode & (S_IXOTH | S_ISVTX)) {
|
|---|
| 177 | #else
|
|---|
| 178 | switch (mode & (S_IXOTH)) {
|
|---|
| 179 | #endif
|
|---|
| 180 | case 0:
|
|---|
| 181 | *p++ = '-';
|
|---|
| 182 | break;
|
|---|
| 183 | case S_IXOTH:
|
|---|
| 184 | *p++ = 'x';
|
|---|
| 185 | break;
|
|---|
| 186 | #ifdef S_ISVTX
|
|---|
| 187 | case S_ISVTX:
|
|---|
| 188 | *p++ = 'T';
|
|---|
| 189 | break;
|
|---|
| 190 | case S_IXOTH | S_ISVTX:
|
|---|
| 191 | *p++ = 't';
|
|---|
| 192 | break;
|
|---|
| 193 | #endif
|
|---|
| 194 | }
|
|---|
| 195 | *p++ = ' '; /* will be a '+' if ACL's implemented */
|
|---|
| 196 | *p = '\0';
|
|---|
| 197 | }
|
|---|