util.c revision 259065
1254885Sdumbbell/*- 2254885Sdumbbell * Copyright (c) 2012 SRI International 3254885Sdumbbell * All rights reserved. 4254885Sdumbbell * 5254885Sdumbbell * This software was developed by SRI International and the University of 6254885Sdumbbell * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 7254885Sdumbbell * ("CTSRD"), as part of the DARPA CRASH research programme. 8254885Sdumbbell * 9254885Sdumbbell * Redistribution and use in source and binary forms, with or without 10254885Sdumbbell * modification, are permitted provided that the following conditions 11254885Sdumbbell * are met: 12254885Sdumbbell * 1. Redistributions of source code must retain the above copyright 13254885Sdumbbell * notice, this list of conditions and the following disclaimer. 14254885Sdumbbell * 2. Redistributions in binary form must reproduce the above copyright 15254885Sdumbbell * notice, this list of conditions and the following disclaimer in the 16254885Sdumbbell * documentation and/or other materials provided with the distribution. 17254885Sdumbbell * 18254885Sdumbbell * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19254885Sdumbbell * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20254885Sdumbbell * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21254885Sdumbbell * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22254885Sdumbbell * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23254885Sdumbbell * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24254885Sdumbbell * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25254885Sdumbbell * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26254885Sdumbbell * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27254885Sdumbbell * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28254885Sdumbbell * SUCH DAMAGE. 29254885Sdumbbell * 30254885Sdumbbell * $FreeBSD: releng/10.0/lib/libnetbsd/util.c 244557 2012-12-21 20:37:38Z brooks $ 31254885Sdumbbell */ 32254885Sdumbbell 33254885Sdumbbell#include <sys/cdefs.h> 34254885Sdumbbell#include <sys/types.h> 35254885Sdumbbell 36254885Sdumbbell#include <stdlib.h> 37254885Sdumbbell#include <string.h> 38254885Sdumbbell#include <unistd.h> 39254885Sdumbbell#include <util.h> 40254885Sdumbbell 41254885Sdumbbellchar * 42254885Sdumbbellflags_to_string(u_long flags, const char *def) 43254885Sdumbbell{ 44254885Sdumbbell char *str; 45254885Sdumbbell 46254885Sdumbbell str = fflagstostr(flags); 47254885Sdumbbell if (*str == '\0') { 48254885Sdumbbell free(str); 49254885Sdumbbell str = strdup(def); 50254885Sdumbbell } 51254885Sdumbbell return (str); 52254885Sdumbbell} 53254885Sdumbbell 54254885Sdumbbellint 55254885Sdumbbellstring_to_flags(char **stringp, u_long *setp, u_long *clrp) 56254885Sdumbbell{ 57254885Sdumbbell 58254885Sdumbbell return strtofflags(stringp, setp, clrp); 59254885Sdumbbell} 60254885Sdumbbell