File: [Platon] / libco / libco / co_string.h (download)
Revision 1.2, Sun Mar 30 10:27:09 2003 UTC (21 years ago) by yenar
Changes since 1.1: +4 -2
lines
fix documentation header [co_string.h]
|
/***{{{*******************************************************************
* This file is part of libco - object library for C *
* Copyright (c) 2002 *
* Peter Rockai (yenar) <yenar@host.sk> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, *
* Boston, MA 02111-1307 USA *
*******************************************************************}}}***/
/* {{{ file description */
/**
* @file co_string.h
* @brief Simple string manipulation functions.
**/
/* }}} */
#ifndef __CO_STRING_H__
#define __CO_STRING_H__
/* {{{ includes */
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <co_exception.h>
/* }}} */
/* {{{ */ static inline int strcpy2 (char *tg, const char *src, size_t s)
/// Safe strcpy (do not try to overwrite 0 pointer nor read from it)
{
if (!tg) return 1;
if (!src) {
strncpy (tg, s >= 6 ? "(nil)" : "0", s);
tg [s] = 0;
return 0;
}
strncpy (tg, src, s);
tg [s] = 0;
return 0;
} /* }}} */
/* {{{ */ static inline char *strdup2 (const char *src)
/// Safe strcpy (do not try to overwrite 0 pointer nor read from it)
{
char *r = 0;
if (!src)
r = strdup ("(nil)");
else
r = strdup (src);
COX_FREE_PUSH (r);
return r;
} /* }}} */
#define __X_in_fnc(ret, fnc, arg) static inline ret fnc ## _in (arg __arg) \
{ \
if (__arg == 0) return 0; \
return fnc (__arg); \
}
__X_in_fnc (char *, strdup, char *);
__X_in_fnc (int, atoi, char *);
__X_in_fnc (double, atof, char *);
#undef __X_in_fnc
char *vsaprintf (const char *fmt, va_list ap);
char *saprintf (const char *fmt, ...);
char *strimplode (const char *delim, ...);
char *str_env_subst (const char *in);
#endif /* __CO_STRING_H__ */
Platon Group <platon@platon.org> http://platon.org/
|