1 /* usmb - mount SMB shares via FUSE and Samba
2 * Copyright (C) 2006-2008 Geoff Johnstone
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 char * concat_strings (int num
, ...)
35 base
= out
= malloc (INIT_LEN
);
39 size_t buff_size
= INIT_LEN
;
42 for (int i
= 0; i
< num
; ++i
)
44 const char *next
= va_arg (ap
, const char *);
45 assert (NULL
!= next
);
47 size_t next_len
= strlen (next
);
49 size_t required
= (out
- base
) + next_len
+ 1;
51 if (buff_size
< required
)
53 while (buff_size
< required
)
55 size_t dbl_len
= buff_size
* 2;
56 if (dbl_len
< buff_size
)
67 ptrdiff_t diff
= out
- base
;
69 char *newbase
= realloc (base
, buff_size
);
81 memcpy (out
, next
, next_len
);
91 char * xstrdup (const char *in
)
97 size_t len
= strlen (in
) + 1;
99 if ((out
= malloc (len
)))
100 memcpy (out
, in
, len
);
107 // the const here lets us pass a pointer to const
108 void xfree (const void *ptr
)
115 void clear_and_free (char *ptr
)
119 for (char *pch
= ptr
; '\0' != *pch
; ++pch
)
127 void free_errno (const void *ptr
)
135 void xfree_errno (const void *ptr
)