141580Sbostic /*- 2*61193Sbostic * Copyright (c) 1990, 1993 3*61193Sbostic * 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*61193Sbostic static char sccsid[] = "@(#)strmode.c 8.1 (Berkeley) 06/04/93"; 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 4641580Sbostic default: /* unknown */ 4741580Sbostic *p++ = '?'; 4841580Sbostic break; 4941580Sbostic } 5041580Sbostic /* usr */ 5141580Sbostic if (mode & S_IRUSR) 5241580Sbostic *p++ = 'r'; 5341580Sbostic else 5441580Sbostic *p++ = '-'; 5541580Sbostic if (mode & S_IWUSR) 5641580Sbostic *p++ = 'w'; 5741580Sbostic else 5841580Sbostic *p++ = '-'; 5941580Sbostic switch (mode & (S_IXUSR | S_ISUID)) { 6041580Sbostic case 0: 6141580Sbostic *p++ = '-'; 6241580Sbostic break; 6341580Sbostic case S_IXUSR: 6441580Sbostic *p++ = 'x'; 6541580Sbostic break; 6641580Sbostic case S_ISUID: 6741580Sbostic *p++ = 'S'; 6841580Sbostic break; 6941580Sbostic case S_IXUSR | S_ISUID: 7041580Sbostic *p++ = 's'; 7141580Sbostic break; 7241580Sbostic } 7341580Sbostic /* group */ 7441580Sbostic if (mode & S_IRGRP) 7541580Sbostic *p++ = 'r'; 7641580Sbostic else 7741580Sbostic *p++ = '-'; 7841580Sbostic if (mode & S_IWGRP) 7941580Sbostic *p++ = 'w'; 8041580Sbostic else 8141580Sbostic *p++ = '-'; 8241580Sbostic switch (mode & (S_IXGRP | S_ISGID)) { 8341580Sbostic case 0: 8441580Sbostic *p++ = '-'; 8541580Sbostic break; 8641580Sbostic case S_IXGRP: 8741580Sbostic *p++ = 'x'; 8841580Sbostic break; 8941580Sbostic case S_ISGID: 9041580Sbostic *p++ = 'S'; 9141580Sbostic break; 9241580Sbostic case S_IXGRP | S_ISGID: 9341580Sbostic *p++ = 's'; 9441580Sbostic break; 9541580Sbostic } 9641580Sbostic /* other */ 9741580Sbostic if (mode & S_IROTH) 9841580Sbostic *p++ = 'r'; 9941580Sbostic else 10041580Sbostic *p++ = '-'; 10141580Sbostic if (mode & S_IWOTH) 10241580Sbostic *p++ = 'w'; 10341580Sbostic else 10441580Sbostic *p++ = '-'; 10541580Sbostic switch (mode & (S_IXOTH | S_ISVTX)) { 10641580Sbostic case 0: 10741580Sbostic *p++ = '-'; 10841580Sbostic break; 10941580Sbostic case S_IXOTH: 11041580Sbostic *p++ = 'x'; 11141580Sbostic break; 11241580Sbostic case S_ISVTX: 11341580Sbostic *p++ = 'T'; 11441580Sbostic break; 11541580Sbostic case S_IXOTH | S_ISVTX: 11641580Sbostic *p++ = 't'; 11741580Sbostic break; 11841580Sbostic } 11941580Sbostic *p++ = ' '; /* will be a '+' if ACL's implemented */ 12041580Sbostic *p = '\0'; 12141580Sbostic } 122