Show misc_string.h syntax highlighted
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* $Id: misc_string.h,v 1.11 2005/09/22 03:10:12 girod Exp $ */
/**
* \file misc_string.h string-related functions
*
*/
#ifndef __MSTRING_H__
#define __MSTRING_H__
#include "misc_buf.h"
char *misc_string_realloc_null_term(const char *buffer, int length);
void misc_strip_trailing_crlfs(char *line);
int misc_get_line(FILE *f, char *buf);
/**
* this macro makes it easier to do a common task - declare a small
* ring of static buffers for returning a string to a caller.
*
* \a basename -- the name of the pointer you want to be able to use from
* within the function
*
* \a num -- the number of buffers in the ring
*
* \a len -- the length of each buffer in bytes
*/
#define DECLARE_STATIC_BUF_RING(basename, num, len) \
static char basename##_ring[num][len]; \
static int basename##_last_index = 0; \
int basename##_curr_index = ((basename##_last_index + 1) % num); \
char *basename = basename##_ring[(basename##_last_index = basename##_curr_index)]
/**
* \brief tolerates null in either parameter, returns 0 if both
* are null, nonzero is only one is null
*/
int misc_safe_strcmp(char *s1, char *s2);
/**
* \brief tolerates null, returns strdup("") if NULL
*/
static inline char *misc_safe_strdup(char *str)
{
return strdup(str ? str : "");
}
/**
* \brief Hexdump to buf_t..
*/
void misc_hexdump_to_buf(buf_t *buf, char *data, int count, char *prefix);
#endif
See more files for this project here