-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
83 lines (71 loc) · 1.69 KB
/
utils.c
File metadata and controls
83 lines (71 loc) · 1.69 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "main.h"
/**
* is_printable - function that evaluates if a character is printable
* @b: the character to be checked
* Return: 1 if c is printable, 0 otherwise
*/
int is_printable(char b)
{
if (b >= 32 && b < 127)
return (1);
return (0);
}
/**
* append_hexa_code - function that appends ASCII in hexadecimal code to buffer
* @asc_cod: ASCII CODE.
* @buffer: an array of characters
* @j: Index at which to start appending.
* Return: Always 3
*/
int append_hexa_code(char asc_cod, char buffer[], int j)
{
char map_to[] = "0123456789ABCDEF";
/* The hexa format code is always 2 digits long */
if (asc_cod < 0)
asc_cod *= -1;
buffer[j++] = '\\';
buffer[j++] = 'x';
buffer[j++] = map_to[asc_cod / 16];
buffer[j] = map_to[asc_cod % 16];
return (3);
}
/**
* is_dig - function that verifies if a character is a digit
* @a: the character to be evaluated
* Return: 1 if c is a digit, 0 otherwise
*/
int is_dig(char a)
{
if (a >= '0' && a <= '9')
return (1);
else
return (0);
}
/**
* conv_siz_num - function that casts a number to the specified size
* @num: Number to be casted.
* @siz: Number indicating the type to be casted.
* Return: Casted value of num
*/
long int conv_siz_num(long int num, int siz)
{
if (siz == S_LONG)
return (num);
else if (siz == S_SHORT)
return ((short)num);
return ((int)num);
}
/**
* conv_siz_unsignd - Casts a number to the specified size
* @num: the number to be casted
* @siz: the number indicating the type to be casted
* Return: Casted value of num
*/
long int conv_siz_unsignd(unsigned long int num, int siz)
{
if (siz == S_LONG)
return (num);
else if (siz == S_SHORT)
return ((unsigned short)num);
return ((unsigned int)num);
}