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