main/xutil.c

changeset 0
88d965579617
equal deleted inserted replaced
-1:000000000000 0:88d965579617
1 /*****************************************************************************
2 * Copyright (C) 2008-2019
3 *
4 * Michiel Broek <mbroek at mbse dot eu>
5 *
6 * This file is part of the mbsePi-apps
7 *
8 * This is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * mbsePi-apps is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *****************************************************************************/
22
23 #include "config.h"
24
25
26 char *xmalloc(size_t size)
27 {
28 char *tmp;
29
30 tmp = malloc(size);
31 if (!tmp)
32 abort();
33
34 return tmp;
35 }
36
37
38
39 char *xstrcpy(char *src)
40 {
41 char *tmp;
42
43 if (src == NULL)
44 return(NULL);
45 tmp = xmalloc(strlen(src)+1);
46 strcpy(tmp, src);
47 return tmp;
48 }
49
50
51
52 char *xstrcat(char *src, char *add)
53 {
54 char *tmp;
55 size_t size = 0;
56
57 if ((add == NULL) || (strlen(add) == 0))
58 return src;
59 if (src)
60 size = strlen(src);
61 size += strlen(add);
62 tmp = xmalloc(size + 1);
63 *tmp = '\0';
64 if (src) {
65 strcpy(tmp, src);
66 free(src);
67 }
68 strcat(tmp, add);
69 return tmp;
70 }
71
72

mercurial