summaryrefslogtreecommitdiff
path: root/libs/string.c
blob: 9917e4f57b95ee7f107fc67e2b19603da9773503 (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
#include <stdio.h>
#include <stdlib.h>
#include <string.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);
}