summaryrefslogtreecommitdiff
path: root/libs/string.c
blob: 1e65ac136b9830ff6e987887845493b53ae12d4b (plain)
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
#include "string.h"
#include <stdlib.h>
#include <string.h>

String
newString (char *string)
{
	String s;
	if (string != NULL && strlen (string) > 0)
	{
		s.length = strlen (string);
		s.string = (char *)calloc (s.length + 1, sizeof (char));
		strcpy (s.string, string);
	}
	else
	{
		s.length = 0;
		s.string = (char *)calloc (1, sizeof (char));
	}

	return s;
}

void
freeString (String *s)
{
	s->length = 0;
	free (s->string);
}