Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
** strvmerge.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** Started on Sun Jul 30 04:03:35 2006 Seblu
** Last update Sun Jul 30 04:36:05 2006 Seblu
*/
#include <string.h>
#include "macro.h"
/*!
** Merge a vector of string
**
** @param vtable strings to merge
**
** @return a string merged from @arg vtable
*/
char *strvmerge(const char *const *vtable)
{
size_t string_sz = 0;
const char *const *elem;
char *new;
for (elem = vtable; *elem; ++elem)
string_sz += strlen(*elem);
secmalloc(new, ++string_sz * sizeof (char));
string_sz = 0;
for (elem = vtable; *elem; ++elem)
{
strcpy(new + string_sz, *elem);
string_sz += strlen(*elem);
}
return new;
}