strip added smb:// shares of their user/pass when adding, and instead store that...
[vuplus_xbmc] / lib / cmyth / libcmyth / safe_string.h
1 /*
2  *  Copyright (C) 2006, Simon Hyde
3  *  http://www.mvpmc.org/
4  *
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.
9  *
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.
14  *
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
18  */
19
20 /** \file mvp_string.h
21  * Some basic string handling routines to help avoid segfaults/buffer overflows
22  */
23
24 #ifndef __MVP_STRING_H
25 #define __MVP_STRING_H
26
27 #include <stdio.h>
28
29 static inline char * safe_strncpy(char *dest,const char *src,size_t n)
30 {
31     if(src == NULL)
32     {
33         dest[0] = '\0';
34     }
35     else
36     {
37         dest[n-1] = '\0';
38         strncpy(dest,src,n-1);
39     }
40     return dest;
41 }
42
43 #define sizeof_strncpy(dest,src) (safe_strncpy(dest,src,sizeof(dest)))
44
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))
48
49 #endif /* __MVP_STRING_H */