141580Sbostic /*- 241580Sbostic * Copyright (c) 1990 The Regents of the University of California. 341580Sbostic * All rights reserved. 441580Sbostic * 541580Sbostic * %sccs.include.redist.c% 641580Sbostic */ 741580Sbostic 841580Sbostic #if defined(LIBC_SCCS) && !defined(lint) 9*42181Sbostic static char sccsid[] = "@(#)strmode.c 5.2 (Berkeley) 05/17/90"; 1041580Sbostic #endif /* LIBC_SCCS and not lint */ 1141580Sbostic 1241580Sbostic #include <sys/types.h> 1341580Sbostic #include <sys/stat.h> 14*42181Sbostic #include <string.h> 1541580Sbostic 16*42181Sbostic 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 (void)putchar('?'); 4941580Sbostic break; 5041580Sbostic } 5141580Sbostic /* usr */ 5241580Sbostic if (mode & S_IRUSR) 5341580Sbostic *p++ = 'r'; 5441580Sbostic else 5541580Sbostic *p++ = '-'; 5641580Sbostic if (mode & S_IWUSR) 5741580Sbostic *p++ = 'w'; 5841580Sbostic else 5941580Sbostic *p++ = '-'; 6041580Sbostic switch (mode & (S_IXUSR | S_ISUID)) { 6141580Sbostic case 0: 6241580Sbostic *p++ = '-'; 6341580Sbostic break; 6441580Sbostic case S_IXUSR: 6541580Sbostic *p++ = 'x'; 6641580Sbostic break; 6741580Sbostic case S_ISUID: 6841580Sbostic *p++ = 'S'; 6941580Sbostic break; 7041580Sbostic case S_IXUSR | S_ISUID: 7141580Sbostic *p++ = 's'; 7241580Sbostic break; 7341580Sbostic } 7441580Sbostic /* group */ 7541580Sbostic if (mode & S_IRGRP) 7641580Sbostic *p++ = 'r'; 7741580Sbostic else 7841580Sbostic *p++ = '-'; 7941580Sbostic if (mode & S_IWGRP) 8041580Sbostic *p++ = 'w'; 8141580Sbostic else 8241580Sbostic *p++ = '-'; 8341580Sbostic switch (mode & (S_IXGRP | S_ISGID)) { 8441580Sbostic case 0: 8541580Sbostic *p++ = '-'; 8641580Sbostic break; 8741580Sbostic case S_IXGRP: 8841580Sbostic *p++ = 'x'; 8941580Sbostic break; 9041580Sbostic case S_ISGID: 9141580Sbostic *p++ = 'S'; 9241580Sbostic break; 9341580Sbostic case S_IXGRP | S_ISGID: 9441580Sbostic *p++ = 's'; 9541580Sbostic break; 9641580Sbostic } 9741580Sbostic /* other */ 9841580Sbostic if (mode & S_IROTH) 9941580Sbostic *p++ = 'r'; 10041580Sbostic else 10141580Sbostic *p++ = '-'; 10241580Sbostic if (mode & S_IWOTH) 10341580Sbostic *p++ = 'w'; 10441580Sbostic else 10541580Sbostic *p++ = '-'; 10641580Sbostic switch (mode & (S_IXOTH | S_ISVTX)) { 10741580Sbostic case 0: 10841580Sbostic *p++ = '-'; 10941580Sbostic break; 11041580Sbostic case S_IXOTH: 11141580Sbostic *p++ = 'x'; 11241580Sbostic break; 11341580Sbostic case S_ISVTX: 11441580Sbostic *p++ = 'T'; 11541580Sbostic break; 11641580Sbostic case S_IXOTH | S_ISVTX: 11741580Sbostic *p++ = 't'; 11841580Sbostic break; 11941580Sbostic } 12041580Sbostic *p++ = ' '; /* will be a '+' if ACL's implemented */ 12141580Sbostic *p = '\0'; 12241580Sbostic } 123