2 * Copyright (C) 2006-2009, Simon Hyde
3 * http://www.mvpmc.org/
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 /** \file safe_string.h
21 * Some basic string handling routines to help avoid segfaults/buffer overflows
24 #ifndef __CMYTH_STRING_H
25 #define __CMYTH_STRING_H
29 static inline char * safe_strncpy(char *dest,const char *src,size_t n)
38 strncpy(dest,src,n-1);
43 #define sizeof_strncpy(dest,src) (safe_strncpy(dest,src,sizeof(dest)))
45 #define safe_atol(str) (((str) == NULL)? (long)0: atol(str))
46 #define safe_atoll(str) (((str) == NULL)? (long long)0: atoll(str))
47 #define safe_atoi(str) (((str) == NULL)? (int)0: atoi(str))
49 #endif /* __CMYTH_STRING_H */