-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.c
58 lines (51 loc) · 1.16 KB
/
functions.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "functions.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
extern size_t readline(char * line, size_t length, FILE * fd) {
char * buff = (char *)malloc(length);
size_t result = getline(&buff, &length, fd);
strcpy(line, buff);
free(buff);
return result;
}
char * czero(char * val) {
bzero(val,sizeof(val) - 1);
return val;
}
char * strtrim(char * str, char chr){
return strtriml(strtrimr(str, chr),chr);
}
char * strtriml(char * str, char chr){
while(str && strlen(str)){
if(str[0] == chr)
strcpy(str, str+1);
else
break;
}
return str;
}
char * strtrimr(char * str, char chr){
while(str && strlen(str)){
if(str[strlen(str) - 1] == chr)
str[strlen(str) - 1] = 0;
else
break;
}
return str;
}
bool streq(char* string1, char* string2)
{
return strcmp(string1, string2) == 0;
}
char * csprintf(char* target, const char* fmt, ...)
{
char buffer[4096];
va_list args;
va_start(args, fmt);
vsprintf(buffer, fmt, args);
va_end(args);
strcat(target, buffer);
return target;
}