-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspecifier_func.c
More file actions
117 lines (104 loc) · 2.04 KB
/
Copy pathspecifier_func.c
File metadata and controls
117 lines (104 loc) · 2.04 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "main.h"
/**
* print_space - Prints empty
* @ap: A variable argument list containing a string to be printed
* @count: count number of characters
*
* * Return: Nothing
*/
void print_space(va_list ap, int *count)
{
(void) ap;
*count += _putchar(' ');
}
/**
* print_percent - Prints a percent sign
* @ap: A variable argument list containing nothing
* @count: count number of characters
*
* Return: Nothing
*/
void print_percent(va_list ap, int *count)
{
(void) ap;
*count += _putchar('%');
}
/**
* print_unsigned - Prints unsigned int
* @ap: A variable argument list containing nothing
* @count: count number of characters
*
* Return: Nothing
*/
void print_unsigned(va_list ap, int *count)
{
char *temp_ptr, *buffer;
int num, length;
num = va_arg(ap, int);
buffer = (char *)malloc(12);
if (buffer == NULL)
return;
length = int_to_string(num, buffer, 12);
if (length < 0)
return;
temp_ptr = buffer
;
while (*temp_ptr)
{
*count += _putchar(*temp_ptr);
temp_ptr++;
}
free(buffer);
}
/**
* print_hex - Prints an integer in hexadecimal format
*
* @ap: A va_list containing the integer to print
* @count: A pointer to a counter of printed characters
*/
void print_hex(va_list ap, int *count)
{
unsigned int num;
char hex[100];
int i, length;
num = va_arg(ap, unsigned int);
if (num == 0)
{
*count += _putchar('0');
return;
}
for (i = 0; num != 0; i++)
{
hex[i] = "0123456789abcdef"[num % 16];
num /= 16;
}
length = i;
for (i = length - 1; i >= 0; i--)
*count += _putchar(hex[i]);
}
/**
* print_HEX - Prints an integer in hexadecimal format
*
* @ap: A va_list containing the integer to print
* @count: A pointer to a counter of printed characters
*/
void print_HEX(va_list ap, int *count)
{
unsigned int num;
char hex[100];
int i, length;
num = va_arg(ap, unsigned int);
if (num == 0)
{
*count += _putchar('0');
return;
}
for (i = 0; num != 0; i++)
{
hex[i] = "0123456789ABCDEF"[num % 16];
num /= 16;
}
length = i;
for (i = length - 1; i >= 0; i--)
*count += _putchar(hex[i]);
}