129347Speter/*-
229347Speter * Copyright (c) 2012 SRI International
329347Speter * All rights reserved.
429347Speter *
529347Speter * This software was developed by SRI International and the University of
629347Speter * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
729347Speter * ("CTSRD"), as part of the DARPA CRASH research programme.
829347Speter *
929347Speter * Redistribution and use in source and binary forms, with or without
1029347Speter * modification, are permitted provided that the following conditions
1129347Speter * are met:
1229347Speter * 1. Redistributions of source code must retain the above copyright
1329347Speter *    notice, this list of conditions and the following disclaimer.
1429347Speter * 2. Redistributions in binary form must reproduce the above copyright
1529347Speter *    notice, this list of conditions and the following disclaimer in the
1629347Speter *    documentation and/or other materials provided with the distribution.
1729347Speter *
1829347Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1929347Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2029347Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2129347Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2229347Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2329347Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2429347Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2529347Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2629347Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2729347Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2850477Speter * SUCH DAMAGE.
2929347Speter *
3029347Speter * $FreeBSD$
3129347Speter */
3229347Speter
3329347Speter#include <sys/cdefs.h>
3499593Smike#include <sys/types.h>
3599593Smike
3629347Speter#include <stdlib.h>
3772093Sasmodai#include <string.h>
3829347Speter#include <unistd.h>
3929347Speter#include <util.h>
4099593Smike
4199593Smikechar *
4229347Speterflags_to_string(u_long flags, const char *def)
4333059Sbde{
4429347Speter	char *str;
4529347Speter
4629347Speter	str = fflagstostr(flags);
4729347Speter	if (*str == '\0') {
4829347Speter		free(str);
4929347Speter		str = strdup(def);
5029347Speter	}
5129347Speter	return (str);
5229347Speter}
5329347Speter
5429347Speterint
5529347Speterstring_to_flags(char **stringp, u_long *setp, u_long *clrp)
5629347Speter{
5729347Speter
5829347Speter	return strtofflags(stringp, setp, clrp);
5929347Speter}
6029347Speter