xref: /csrg-svn/lib/libc/string/strmode.c (revision 67684)
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*67684Smckusick static char sccsid[] = "@(#)strmode.c	8.3 (Berkeley) 08/15/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
strmode(mode,p)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
4667575Spendry #ifdef S_IFWHT
4767575Spendry 	case S_IFWHT:			/* whiteout */
4867575Spendry 		*p++ = 'w';
4967575Spendry 		break;
5067575Spendry #endif
5141580Sbostic 	default:			/* unknown */
5241580Sbostic 		*p++ = '?';
5341580Sbostic 		break;
5441580Sbostic 	}
5541580Sbostic 	/* usr */
5641580Sbostic 	if (mode & S_IRUSR)
5741580Sbostic 		*p++ = 'r';
5841580Sbostic 	else
5941580Sbostic 		*p++ = '-';
6041580Sbostic 	if (mode & S_IWUSR)
6141580Sbostic 		*p++ = 'w';
6241580Sbostic 	else
6341580Sbostic 		*p++ = '-';
6441580Sbostic 	switch (mode & (S_IXUSR | S_ISUID)) {
6541580Sbostic 	case 0:
6641580Sbostic 		*p++ = '-';
6741580Sbostic 		break;
6841580Sbostic 	case S_IXUSR:
6941580Sbostic 		*p++ = 'x';
7041580Sbostic 		break;
7141580Sbostic 	case S_ISUID:
7241580Sbostic 		*p++ = 'S';
7341580Sbostic 		break;
7441580Sbostic 	case S_IXUSR | S_ISUID:
7541580Sbostic 		*p++ = 's';
7641580Sbostic 		break;
7741580Sbostic 	}
7841580Sbostic 	/* group */
7941580Sbostic 	if (mode & S_IRGRP)
8041580Sbostic 		*p++ = 'r';
8141580Sbostic 	else
8241580Sbostic 		*p++ = '-';
8341580Sbostic 	if (mode & S_IWGRP)
8441580Sbostic 		*p++ = 'w';
8541580Sbostic 	else
8641580Sbostic 		*p++ = '-';
8741580Sbostic 	switch (mode & (S_IXGRP | S_ISGID)) {
8841580Sbostic 	case 0:
8941580Sbostic 		*p++ = '-';
9041580Sbostic 		break;
9141580Sbostic 	case S_IXGRP:
9241580Sbostic 		*p++ = 'x';
9341580Sbostic 		break;
9441580Sbostic 	case S_ISGID:
9541580Sbostic 		*p++ = 'S';
9641580Sbostic 		break;
9741580Sbostic 	case S_IXGRP | S_ISGID:
9841580Sbostic 		*p++ = 's';
9941580Sbostic 		break;
10041580Sbostic 	}
10141580Sbostic 	/* other */
10241580Sbostic 	if (mode & S_IROTH)
10341580Sbostic 		*p++ = 'r';
10441580Sbostic 	else
10541580Sbostic 		*p++ = '-';
10641580Sbostic 	if (mode & S_IWOTH)
10741580Sbostic 		*p++ = 'w';
10841580Sbostic 	else
10941580Sbostic 		*p++ = '-';
11041580Sbostic 	switch (mode & (S_IXOTH | S_ISVTX)) {
11141580Sbostic 	case 0:
11241580Sbostic 		*p++ = '-';
11341580Sbostic 		break;
11441580Sbostic 	case S_IXOTH:
11541580Sbostic 		*p++ = 'x';
11641580Sbostic 		break;
11741580Sbostic 	case S_ISVTX:
11841580Sbostic 		*p++ = 'T';
11941580Sbostic 		break;
12041580Sbostic 	case S_IXOTH | S_ISVTX:
12141580Sbostic 		*p++ = 't';
12241580Sbostic 		break;
12341580Sbostic 	}
12441580Sbostic 	*p++ = ' ';		/* will be a '+' if ACL's implemented */
12541580Sbostic 	*p = '\0';
12641580Sbostic }
127