eurephia_nullsafe.h

Go to the documentation of this file.
00001 /* eurephia_nullsafe.h
00002  *
00003  *  standard C string functions, which is made NULL safe by checking
00004  *  if input value is NULL before performing the action.
00005  *
00006  *  GPLv2 only - Copyright (C) 2008 - 2010
00007  *               David Sommerseth <dazo@users.sourceforge.net>
00008  *
00009  *  This program is free software; you can redistribute it and/or
00010  *  modify it under the terms of the GNU General Public License
00011  *  as published by the Free Software Foundation; version 2
00012  *  of the License.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00022  *
00023  */
00024 
00035 #include <eurephia_context.h>
00036 
00037 #ifndef         EUREPHIA_NULLSAFE_H_
00038 #define         EUREPHIA_NULLSAFE_H_
00039 
00047 #define atoi_nullsafe(str) (str != NULL ? atoi(str) : 0)
00048 
00049 
00058 #define strdup_nullsafe(str) (str != NULL ? strdup(str) : NULL)
00059 
00060 
00069 #define append_str(dest, src, size) strncat(dest, src, (size - strlen_nullsafe(dest)))
00070 
00071 
00079 #define strlen_nullsafe(str) (str != NULL ? strlen(str) : 0)
00080 
00081 
00082 
00083 void *_malloc_nullsafe(eurephiaCTX *, size_t, const char *, int);
00084 
00094 #define malloc_nullsafe(ctx, sz) _malloc_nullsafe(ctx, sz, __FILE__, __LINE__)
00095 
00096 
00097 void inline _free_nullsafe(eurephiaCTX *ctx, void *ptr, const char *file, int line);
00098 
00106 #define free_nullsafe(ctx, ptr) { _free_nullsafe(ctx, ptr, __FILE__, __LINE__); ptr = NULL; }
00107 
00108 
00118 #define defaultValue(str, defstr) (strlen_nullsafe(str) == 0 ? defstr : str)
00119 
00120 
00129 #define defaultIntValue(ival, defval) (ival == 0 ? defval : ival)
00130 #endif      /* !EUREPHIA_NULLSAFE_H_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines