Subversion Repositories Mokou

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 nishi 1
/* $Id: util.c 2 2024-09-05 18:31:51Z nishi $ */
2
 
3
#include "mk_util.h"
4
 
5
#include <stdlib.h>
6
#include <string.h>
7
 
8
char* mk_strcat(const char* a, const char* b){
9
	char* str = malloc(strlen(a) + strlen(b) + 1);
10
	memcpy(str, a, strlen(a));
11
	memcpy(str + strlen(a), b, strlen(b));
12
	str[strlen(a) + strlen(b)] = 0;
13
	return str;
14
}
15
 
16
char* mk_strcat3(const char* a, const char* b, const char* c){
17
	char* tmp = mk_strcat(a, b);
18
	char* str = mk_strcat(tmp, c);
19
	free(tmp);
20
	return str;
21
}
22
 
23
char* mk_strdup(const char* a){
24
	return mk_strcat(a, "");
25
}
26
 
27
bool mk_endswith(const char* str, const char* end){
28
	if(strlen(str) < strlen(end)) return false;
29
	int i;
30
	for(i = strlen(str) - strlen(end); str[i] != 0; i++){
31
		if(str[i] != end[i - strlen(str) + strlen(end)]) return false;
32
	}
33
	return true;
34
}