xref: /titanic_50/usr/src/lib/libast/common/string/fmtperm.c (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Glenn Fowler
25  * AT&T Bell Laboratories
26  *
27  * return strperm() expression for perm
28  */
29 
30 #include <ast.h>
31 #include <ls.h>
32 
33 char*
fmtperm(register int perm)34 fmtperm(register int perm)
35 {
36 	register char*	s;
37 	char*		buf;
38 
39 	s = buf = fmtbuf(32);
40 
41 	/*
42 	 * u
43 	 */
44 
45 	*s++ = 'u';
46 	*s++ = '=';
47 	if (perm & S_ISVTX)
48 		*s++ = 't';
49 	if (perm & S_ISUID)
50 		*s++ = 's';
51 	if (perm & S_IRUSR)
52 		*s++ = 'r';
53 	if (perm & S_IWUSR)
54 		*s++ = 'w';
55 	if (perm & S_IXUSR)
56 		*s++ = 'x';
57 	if ((perm & (S_ISGID|S_IXGRP)) == S_ISGID)
58 		*s++ = 'l';
59 
60 	/*
61 	 * g
62 	 */
63 
64 	*s++ = ',';
65 	*s++ = 'g';
66 	*s++ = '=';
67 	if ((perm & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP))
68 		*s++ = 's';
69 	if (perm & S_IRGRP)
70 		*s++ = 'r';
71 	if (perm & S_IWGRP)
72 		*s++ = 'w';
73 	if (perm & S_IXGRP)
74 		*s++ = 'x';
75 
76 	/*
77 	 * o
78 	 */
79 
80 	*s++ = ',';
81 	*s++ = 'o';
82 	*s++ = '=';
83 	if (perm & S_IROTH)
84 		*s++ = 'r';
85 	if (perm & S_IWOTH)
86 		*s++ = 'w';
87 	if (perm & S_IXOTH)
88 		*s++ = 'x';
89 	*s = 0;
90 	return buf;
91 }
92