1 /* $NetBSD: stat_flags.c,v 1.2 2007/01/16 17:34:02 cbiere 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #if HAVE_NBTOOL_CONFIG_H
33 #include "nbtool_config.h"
35 #define HAVE_STRUCT_STAT_ST_FLAGS 1
38 #include <sys/cdefs.h>
41 static char sccsid
[] = "@(#)stat_flags.c 8.2 (Berkeley) 7/28/94";
43 __RCSID("$NetBSD: stat_flags.c,v 1.2 2007/01/16 17:34:02 cbiere Exp $");
47 #include <sys/types.h>
56 #define SAPPEND(s) do { \
58 (void)strlcat(string, prefix, sizeof(string)); \
59 (void)strlcat(string, s, sizeof(string)); \
61 } while (/* CONSTCOND */ 0)
65 * Convert stat flags to a comma-separated string. If no flags
66 * are set, return the default string.
69 flags_to_string(u_long flags
, const char *def
)
76 #if HAVE_STRUCT_STAT_ST_FLAGS
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
)
92 if (flags
& SF_SNAPSHOT
)
97 return strdup(string
);
101 #define TEST(a, b, f) { \
102 if (!strcmp(a, b)) { \
120 * Take string of arguments and return stat flags. Return 0 on
121 * success, 1 on failure. On failure, stringp is set to point
122 * to the offending token.
125 string_to_flags(char **stringp
, u_long
*setp
, u_long
*clrp
)
135 #if HAVE_STRUCT_STAT_ST_FLAGS
137 while ((p
= strsep(&string
, "\t ,")) != NULL
) {
142 if (p
[0] == 'n' && p
[1] == 'o') {
148 TEST(p
, "arch", SF_ARCHIVED
);
149 TEST(p
, "archived", SF_ARCHIVED
);
153 TEST(p
, "dump", UF_NODUMP
);
157 * Support `nonodump'. Note that
158 * the state of clear is not changed.
160 TEST(p
, "nodump", UF_NODUMP
);
163 TEST(p
, "opaque", UF_OPAQUE
);
166 TEST(p
, "sappnd", SF_APPEND
);
167 TEST(p
, "sappend", SF_APPEND
);
168 TEST(p
, "schg", SF_IMMUTABLE
);
169 TEST(p
, "schange", SF_IMMUTABLE
);
170 TEST(p
, "simmutable", SF_IMMUTABLE
);
173 TEST(p
, "uappnd", UF_APPEND
);
174 TEST(p
, "uappend", UF_APPEND
);
175 TEST(p
, "uchg", UF_IMMUTABLE
);
176 TEST(p
, "uchange", UF_IMMUTABLE
);
177 TEST(p
, "uimmutable", UF_IMMUTABLE
);