1244557Sbrooks/*-
2244557Sbrooks * Copyright (c) 2012 SRI International
3244557Sbrooks * All rights reserved.
4244557Sbrooks *
5244557Sbrooks * This software was developed by SRI International and the University of
6244557Sbrooks * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7244557Sbrooks * ("CTSRD"), as part of the DARPA CRASH research programme.
8244557Sbrooks *
9244557Sbrooks * Redistribution and use in source and binary forms, with or without
10244557Sbrooks * modification, are permitted provided that the following conditions
11244557Sbrooks * are met:
12244557Sbrooks * 1. Redistributions of source code must retain the above copyright
13244557Sbrooks *    notice, this list of conditions and the following disclaimer.
14244557Sbrooks * 2. Redistributions in binary form must reproduce the above copyright
15244557Sbrooks *    notice, this list of conditions and the following disclaimer in the
16244557Sbrooks *    documentation and/or other materials provided with the distribution.
17244557Sbrooks *
18244557Sbrooks * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19244557Sbrooks * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20244557Sbrooks * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21244557Sbrooks * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22244557Sbrooks * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23244557Sbrooks * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24244557Sbrooks * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25244557Sbrooks * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26244557Sbrooks * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27244557Sbrooks * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28244557Sbrooks * SUCH DAMAGE.
29244557Sbrooks *
30244557Sbrooks * $FreeBSD$
31244557Sbrooks */
32244557Sbrooks
33244557Sbrooks#include <sys/cdefs.h>
34244557Sbrooks#include <sys/types.h>
35244557Sbrooks
36244557Sbrooks#include <stdlib.h>
37244557Sbrooks#include <string.h>
38244557Sbrooks#include <unistd.h>
39244557Sbrooks#include <util.h>
40244557Sbrooks
41244557Sbrookschar *
42244557Sbrooksflags_to_string(u_long flags, const char *def)
43244557Sbrooks{
44244557Sbrooks	char *str;
45244557Sbrooks
46244557Sbrooks	str = fflagstostr(flags);
47244557Sbrooks	if (*str == '\0') {
48244557Sbrooks		free(str);
49244557Sbrooks		str = strdup(def);
50244557Sbrooks	}
51244557Sbrooks	return (str);
52244557Sbrooks}
53244557Sbrooks
54244557Sbrooksint
55244557Sbrooksstring_to_flags(char **stringp, u_long *setp, u_long *clrp)
56244557Sbrooks{
57244557Sbrooks
58244557Sbrooks	return strtofflags(stringp, setp, clrp);
59244557Sbrooks}
60