-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrlib.c
More file actions
40 lines (35 loc) · 1.62 KB
/
strlib.c
File metadata and controls
40 lines (35 loc) · 1.62 KB
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
38
39
40
///////////////////////////////////////////////////////////////////////////////////
// School: Brno University of Technology, Faculty of Information Technology //
// Course: Formal Languages and Compilers //
// Project: IFJ17 //
// Module: Work with strings //
// Authors: Kristián Liščinský (xlisci01) //
// Matúš Liščinský (xlisci02) //
// Šimon Stupinský (xstupi00) //
// Vladimír Marcin (xmarci10) //
///////////////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <stdbool.h>
#include "strlib.h"
#include "error.h"
#include "clear.h"
/// replace malloc & realloc calls with our malloc & realloc wrapper
#define malloc(size) _malloc(size)
#define realloc(ptr, new_size, old_size) _realloc(ptr, new_size, old_size)
bool extendStr(string_t * str, size_t new_size){
if( !(str->string =(char *)(realloc(str->string, sizeof(char)*new_size+1, str->capacity+1))) )
print_err(99);
str->capacity=new_size;
return true;
}
string_t * strInit(size_t size){
string_t * str = (string_t *) malloc(sizeof(string_t));
if(!str)
print_err(99);
str->string = (char *) malloc(sizeof(char) * size + 1);
if(!(str->string))
print_err(99);
str->capacity = size;
str->length = 0;
return str;
}