1*6bea8766SBrooks Davis /*- 2*6bea8766SBrooks Davis * Copyright (c) 2012 SRI International 3*6bea8766SBrooks Davis * All rights reserved. 4*6bea8766SBrooks Davis * 5*6bea8766SBrooks Davis * This software was developed by SRI International and the University of 6*6bea8766SBrooks Davis * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 7*6bea8766SBrooks Davis * ("CTSRD"), as part of the DARPA CRASH research programme. 8*6bea8766SBrooks Davis * 9*6bea8766SBrooks Davis * Redistribution and use in source and binary forms, with or without 10*6bea8766SBrooks Davis * modification, are permitted provided that the following conditions 11*6bea8766SBrooks Davis * are met: 12*6bea8766SBrooks Davis * 1. Redistributions of source code must retain the above copyright 13*6bea8766SBrooks Davis * notice, this list of conditions and the following disclaimer. 14*6bea8766SBrooks Davis * 2. Redistributions in binary form must reproduce the above copyright 15*6bea8766SBrooks Davis * notice, this list of conditions and the following disclaimer in the 16*6bea8766SBrooks Davis * documentation and/or other materials provided with the distribution. 17*6bea8766SBrooks Davis * 18*6bea8766SBrooks Davis * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19*6bea8766SBrooks Davis * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*6bea8766SBrooks Davis * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*6bea8766SBrooks Davis * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22*6bea8766SBrooks Davis * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23*6bea8766SBrooks Davis * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24*6bea8766SBrooks Davis * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25*6bea8766SBrooks Davis * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26*6bea8766SBrooks Davis * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27*6bea8766SBrooks Davis * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28*6bea8766SBrooks Davis * SUCH DAMAGE. 29*6bea8766SBrooks Davis * 30*6bea8766SBrooks Davis * $FreeBSD$ 31*6bea8766SBrooks Davis */ 32*6bea8766SBrooks Davis 33*6bea8766SBrooks Davis #include <sys/cdefs.h> 34*6bea8766SBrooks Davis #include <sys/types.h> 35*6bea8766SBrooks Davis 36*6bea8766SBrooks Davis #include <stdlib.h> 37*6bea8766SBrooks Davis #include <string.h> 38*6bea8766SBrooks Davis #include <unistd.h> 39*6bea8766SBrooks Davis #include <util.h> 40*6bea8766SBrooks Davis 41*6bea8766SBrooks Davis char * 42*6bea8766SBrooks Davis flags_to_string(u_long flags, const char *def) 43*6bea8766SBrooks Davis { 44*6bea8766SBrooks Davis char *str; 45*6bea8766SBrooks Davis 46*6bea8766SBrooks Davis str = fflagstostr(flags); 47*6bea8766SBrooks Davis if (*str == '\0') { 48*6bea8766SBrooks Davis free(str); 49*6bea8766SBrooks Davis str = strdup(def); 50*6bea8766SBrooks Davis } 51*6bea8766SBrooks Davis return (str); 52*6bea8766SBrooks Davis } 53*6bea8766SBrooks Davis 54*6bea8766SBrooks Davis int 55*6bea8766SBrooks Davis string_to_flags(char **stringp, u_long *setp, u_long *clrp) 56*6bea8766SBrooks Davis { 57*6bea8766SBrooks Davis 58*6bea8766SBrooks Davis return strtofflags(stringp, setp, clrp); 59*6bea8766SBrooks Davis } 60