1 /* @(#)stat_flags.c 8.2 (Berkeley) 7/28/94 */
2 /* $NetBSD: stat_flags.c,v 1.2 2007/01/16 17:34:02 cbiere Exp $ */
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #if HAVE_NBTOOL_CONFIG_H
34 #include "nbtool_config.h"
36 #define HAVE_STRUCT_STAT_ST_FLAGS 1
39 #include <sys/types.h>
49 #define SAPPEND(s) do { \
51 (void)strlcat(string, prefix, sizeof(string)); \
52 (void)strlcat(string, s, sizeof(string)); \
54 } while (/* CONSTCOND */ 0)
58 * Convert stat flags to a comma-separated string. If no flags
59 * are set, return the default string.
62 flags_to_string(u_long flags
, const char *def
)
69 #if HAVE_STRUCT_STAT_ST_FLAGS
70 if (flags
& UF_APPEND
)
72 if (flags
& UF_IMMUTABLE
)
74 if (flags
& UF_NODUMP
)
76 if (flags
& UF_OPAQUE
)
78 if (flags
& SF_APPEND
)
80 if (flags
& SF_ARCHIVED
)
82 if (flags
& SF_IMMUTABLE
)
85 if (flags
& SF_SNAPSHOT
)
90 return strdup(string
);
94 #define TEST(a, b, f) { \
95 if (!strcmp(a, b)) { \
113 * Take string of arguments and return stat flags. Return 0 on
114 * success, 1 on failure. On failure, stringp is set to point
115 * to the offending token.
118 string_to_flags(char **stringp
, u_long
*setp
, u_long
*clrp
)
128 #if HAVE_STRUCT_STAT_ST_FLAGS
130 while ((p
= strsep(&string
, "\t ,")) != NULL
) {
135 if (p
[0] == 'n' && p
[1] == 'o') {
141 TEST(p
, "arch", SF_ARCHIVED
);
142 TEST(p
, "archived", SF_ARCHIVED
);
146 TEST(p
, "dump", UF_NODUMP
);
150 * Support `nonodump'. Note that
151 * the state of clear is not changed.
153 TEST(p
, "nodump", UF_NODUMP
);
156 TEST(p
, "opaque", UF_OPAQUE
);
159 TEST(p
, "sappnd", SF_APPEND
);
160 TEST(p
, "sappend", SF_APPEND
);
161 TEST(p
, "schg", SF_IMMUTABLE
);
162 TEST(p
, "schange", SF_IMMUTABLE
);
163 TEST(p
, "simmutable", SF_IMMUTABLE
);
166 TEST(p
, "uappnd", UF_APPEND
);
167 TEST(p
, "uappend", UF_APPEND
);
168 TEST(p
, "uchg", UF_IMMUTABLE
);
169 TEST(p
, "uchange", UF_IMMUTABLE
);
170 TEST(p
, "uimmutable", UF_IMMUTABLE
);