-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
77 lines (70 loc) · 1.17 KB
/
Copy pathutils.c
File metadata and controls
77 lines (70 loc) · 1.17 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
#include "main.h"
/**
* pf_is_digit - checks if c is digit
* @c: char
*
* Return: 1 if digit, 0 otherwise
*/
int pf_is_digit(char c)
{
return (c >= '0' && c <= '9');
}
/**
* pf_strlen - length of string
* @s: string
*
* Return: length
*/
int pf_strlen(const char *s)
{
int n;
if (s == NULL)
return (0);
n = 0;
while (s[n] != '\0')
n++;
return (n);
}
/**
* pf_is_printable - printable ASCII check
* @c: byte
*
* Return: 1 if printable, 0 otherwise
*/
int pf_is_printable(unsigned char c)
{
if (c > 0 && c < 32)
return (0);
if (c >= 127)
return (0);
return (1);
}
/**
* pf_hex_digit - hex digit for value 0..15
* @v: value
* @upper: 1 for uppercase, 0 for lowercase
*
* Return: hex digit
*/
char pf_hex_digit(unsigned int v, int upper)
{
if (v < 10)
return ((char)('0' + v));
if (upper)
return ((char)('A' + (v - 10)));
return ((char)('a' + (v - 10)));
}
/**
* pf_rot13_char - rot13 transform one character
* @c: char
*
* Return: transformed char
*/
char pf_rot13_char(char c)
{
if (c >= 'a' && c <= 'z')
return ((char)('a' + (c - 'a' + 13) % 26));
if (c >= 'A' && c <= 'Z')
return ((char)('A' + (c - 'A' + 13) % 26));
return (c);
}