-
Notifications
You must be signed in to change notification settings - Fork 7
/
ulib.c
49 lines (44 loc) · 1003 Bytes
/
ulib.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
#include "ulib.h"
int wrap(const char *from, const char tail, char *to)
{
if(from == NULL || tail == '\0')
return FALSE;
int from_str_length = strlen(from) * sizeof(char);
strncpy(to, from, from_str_length);
memset(to + from_str_length, tail, 1);
return TRUE;
}
int un_wrap(char *str, char *tail)
{
if (str == NULL)
return FALSE;
size_t tail_position = (strlen(str) - 1) * sizeof(char);
if (tail != NULL)
*tail = *(str + tail_position);
memset(str + tail_position, 0, 1);
return TRUE;
}
int compare_wrap(const char *str,char tail)
{
char tailstr[2] = {tail, 0};
if (strcspn(str,tailstr) == strlen(str) - 1)
return TRUE;
else
return FALSE;
}
char *long_to_string(long number)
{
long _number = number;
int size;
for (size = 1; _number != 0; size += 1) {
_number /= 10;
}//end for
char *str = (char *)malloc_string_safe(str, size);
char ch;
for (int i = size - 2; i != -1; i -= 1) {
ch = number % 10;
number /= 10;
str[i] = ch + 48;
}//end for
return str;
}