|
1 /***************************************************************************** |
|
2 * Copyright (C) 2017 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of the bms (Brewery Management System) |
|
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 * bms 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 "bms.h" |
|
24 #include "xutil.h" |
|
25 |
|
26 |
|
27 char *xmalloc(size_t size) |
|
28 { |
|
29 char *tmp; |
|
30 |
|
31 tmp = malloc(size); |
|
32 if (!tmp) |
|
33 abort(); |
|
34 |
|
35 return tmp; |
|
36 } |
|
37 |
|
38 |
|
39 |
|
40 char *xstrcpy(char *src) |
|
41 { |
|
42 char *tmp; |
|
43 |
|
44 if (src == NULL) |
|
45 return(NULL); |
|
46 tmp = xmalloc(strlen(src)+1); |
|
47 strcpy(tmp, src); |
|
48 return tmp; |
|
49 } |
|
50 |
|
51 |
|
52 |
|
53 char *xstrcat(char *src, char *add) |
|
54 { |
|
55 char *tmp; |
|
56 size_t size = 0; |
|
57 |
|
58 if ((add == NULL) || (strlen(add) == 0)) |
|
59 return src; |
|
60 if (src) |
|
61 size = strlen(src); |
|
62 size += strlen(add); |
|
63 tmp = xmalloc(size + 1); |
|
64 *tmp = '\0'; |
|
65 if (src) { |
|
66 strcpy(tmp, src); |
|
67 free(src); |
|
68 } |
|
69 strcat(tmp, add); |
|
70 return tmp; |
|
71 } |
|
72 |
|
73 |