]>
git.saurik.com Git - apple/file_cmds.git/blob - ls/stat_flags.c
e46a3e8b70a3ad30212dbff2d13ff52840d22633
1 /* $NetBSD: stat_flags.c,v 1.6 1997/07/20 18:53:12 christos Exp $ */
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)stat_flags.c 8.2 (Berkeley) 7/28/94";
41 __RCSID("$NetBSD: stat_flags.c,v 1.6 1997/07/20 18:53:12 christos Exp $");
45 #include <sys/types.h>
55 #define SAPPEND(s) { \
57 (void)strcat(string, prefix); \
58 (void)strcat(string, s); \
64 * Convert stat flags to a comma-separated string. If no flags
65 * are set, return the default string.
68 flags_to_string(flags
, def
)
72 static char string
[128];
77 if (flags
& UF_APPEND
)
79 if (flags
& UF_IMMUTABLE
)
81 if (flags
& UF_NODUMP
)
83 if (flags
& UF_OPAQUE
)
85 if (flags
& SF_APPEND
)
87 if (flags
& SF_ARCHIVED
)
89 if (flags
& SF_IMMUTABLE
)
91 return (prefix
== NULL
&& def
!= NULL
? def
: string
);
94 #define TEST(a, b, f) { \
95 if (!memcmp(a, b, sizeof(b))) { \
107 * Take string of arguments and return stat flags. Return 0 on
108 * success, 1 on failure. On failure, stringp is set to point
109 * to the offending token.
112 string_to_flags(stringp
, setp
, clrp
)
125 while ((p
= strsep(&string
, "\t ,")) != NULL
) {
129 if (p
[0] == 'n' && p
[1] == 'o') {
135 TEST(p
, "arch", SF_ARCHIVED
);
136 TEST(p
, "archived", SF_ARCHIVED
);
140 TEST(p
, "dump", UF_NODUMP
);
143 TEST(p
, "opaque", UF_OPAQUE
);
146 TEST(p
, "sappnd", SF_APPEND
);
147 TEST(p
, "sappend", SF_APPEND
);
148 TEST(p
, "schg", SF_IMMUTABLE
);
149 TEST(p
, "schange", SF_IMMUTABLE
);
150 TEST(p
, "simmutable", SF_IMMUTABLE
);
153 TEST(p
, "uappnd", UF_APPEND
);
154 TEST(p
, "uappend", UF_APPEND
);
155 TEST(p
, "uchg", UF_IMMUTABLE
);
156 TEST(p
, "uchange", UF_IMMUTABLE
);
157 TEST(p
, "uimmutable", UF_IMMUTABLE
);