141580Sbostic /*- 261193Sbostic * Copyright (c) 1990, 1993 361193Sbostic * The Regents of the University of California. All rights reserved. 441580Sbostic * 541580Sbostic * %sccs.include.redist.c% 641580Sbostic */ 741580Sbostic 841580Sbostic #if defined(LIBC_SCCS) && !defined(lint) 9*67575Spendry static char sccsid[] = "@(#)strmode.c 8.2 (Berkeley) 07/28/94"; 1041580Sbostic #endif /* LIBC_SCCS and not lint */ 1141580Sbostic 1241580Sbostic #include <sys/types.h> 1341580Sbostic #include <sys/stat.h> 1442181Sbostic #include <string.h> 1541580Sbostic 1642181Sbostic void 1741580Sbostic strmode(mode, p) 1841580Sbostic register mode_t mode; 1941580Sbostic register char *p; 2041580Sbostic { 2141580Sbostic /* print type */ 2241580Sbostic switch (mode & S_IFMT) { 2341580Sbostic case S_IFDIR: /* directory */ 2441580Sbostic *p++ = 'd'; 2541580Sbostic break; 2641580Sbostic case S_IFCHR: /* character special */ 2741580Sbostic *p++ = 'c'; 2841580Sbostic break; 2941580Sbostic case S_IFBLK: /* block special */ 3041580Sbostic *p++ = 'b'; 3141580Sbostic break; 3241580Sbostic case S_IFREG: /* regular */ 3341580Sbostic *p++ = '-'; 3441580Sbostic break; 3541580Sbostic case S_IFLNK: /* symbolic link */ 3641580Sbostic *p++ = 'l'; 3741580Sbostic break; 3841580Sbostic case S_IFSOCK: /* socket */ 3941580Sbostic *p++ = 's'; 4041580Sbostic break; 4141580Sbostic #ifdef S_IFIFO 4241580Sbostic case S_IFIFO: /* fifo */ 4341580Sbostic *p++ = 'p'; 4441580Sbostic break; 4541580Sbostic #endif 46*67575Spendry #ifdef S_IFWHT 47*67575Spendry case S_IFWHT: /* whiteout */ 48*67575Spendry case S_IFWHTD: 49*67575Spendry *p++ = 'w'; 50*67575Spendry break; 51*67575Spendry #endif 5241580Sbostic default: /* unknown */ 5341580Sbostic *p++ = '?'; 5441580Sbostic break; 5541580Sbostic } 5641580Sbostic /* usr */ 5741580Sbostic if (mode & S_IRUSR) 5841580Sbostic *p++ = 'r'; 5941580Sbostic else 6041580Sbostic *p++ = '-'; 6141580Sbostic if (mode & S_IWUSR) 6241580Sbostic *p++ = 'w'; 6341580Sbostic else 6441580Sbostic *p++ = '-'; 6541580Sbostic switch (mode & (S_IXUSR | S_ISUID)) { 6641580Sbostic case 0: 6741580Sbostic *p++ = '-'; 6841580Sbostic break; 6941580Sbostic case S_IXUSR: 7041580Sbostic *p++ = 'x'; 7141580Sbostic break; 7241580Sbostic case S_ISUID: 7341580Sbostic *p++ = 'S'; 7441580Sbostic break; 7541580Sbostic case S_IXUSR | S_ISUID: 7641580Sbostic *p++ = 's'; 7741580Sbostic break; 7841580Sbostic } 7941580Sbostic /* group */ 8041580Sbostic if (mode & S_IRGRP) 8141580Sbostic *p++ = 'r'; 8241580Sbostic else 8341580Sbostic *p++ = '-'; 8441580Sbostic if (mode & S_IWGRP) 8541580Sbostic *p++ = 'w'; 8641580Sbostic else 8741580Sbostic *p++ = '-'; 8841580Sbostic switch (mode & (S_IXGRP | S_ISGID)) { 8941580Sbostic case 0: 9041580Sbostic *p++ = '-'; 9141580Sbostic break; 9241580Sbostic case S_IXGRP: 9341580Sbostic *p++ = 'x'; 9441580Sbostic break; 9541580Sbostic case S_ISGID: 9641580Sbostic *p++ = 'S'; 9741580Sbostic break; 9841580Sbostic case S_IXGRP | S_ISGID: 9941580Sbostic *p++ = 's'; 10041580Sbostic break; 10141580Sbostic } 10241580Sbostic /* other */ 10341580Sbostic if (mode & S_IROTH) 10441580Sbostic *p++ = 'r'; 10541580Sbostic else 10641580Sbostic *p++ = '-'; 10741580Sbostic if (mode & S_IWOTH) 10841580Sbostic *p++ = 'w'; 10941580Sbostic else 11041580Sbostic *p++ = '-'; 11141580Sbostic switch (mode & (S_IXOTH | S_ISVTX)) { 11241580Sbostic case 0: 11341580Sbostic *p++ = '-'; 11441580Sbostic break; 11541580Sbostic case S_IXOTH: 11641580Sbostic *p++ = 'x'; 11741580Sbostic break; 11841580Sbostic case S_ISVTX: 11941580Sbostic *p++ = 'T'; 12041580Sbostic break; 12141580Sbostic case S_IXOTH | S_ISVTX: 12241580Sbostic *p++ = 't'; 12341580Sbostic break; 12441580Sbostic } 12541580Sbostic *p++ = ' '; /* will be a '+' if ACL's implemented */ 12641580Sbostic *p = '\0'; 12741580Sbostic } 128