-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrt.c
86 lines (74 loc) · 1.51 KB
/
wrt.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
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
#include "main.h"
/**
* string_compare - Performs lexicographic comparison of two strings.
* @str1: The first string.
* @str2: The second string.
*
* Return: add descr
*/
int string_compare(char *str1, char *str2)
{
while (*str1 && *str2)
{
if (*str1 != *str2)
return (*str1 - *str2);
str1++;
str2++;
}
if (*str1 == *str2)
return (0);
else
return ((*str1 < *str2 ? -1 : 1));
}
/**
* string_starts_with - Checks if a string starts with a specific substring.
* @haystack: The string to search.
* @needle: The substring to find.
*
* Return: Address of the next character of haystack or NULL if not found.
*/
char *string_starts_with(const char *haystack, const char *needle)
{
while (*needle)
if (*needle++ != *haystack++)
return (NULL);
return ((char *)haystack);
}
/**
* _putchar - writes the character c to stdout
* @c: The character to print
*
* Return: On success 1.
* On error, -1 is returned, and errno is set appropriately.
*/
int _putchar(char c)
{
static int i;
static char buf[BUF_SIZE];
if (c == FLUSH_BUFFER || i >= BUF_SIZE)
{
write(1, buf, i);
i = 0;
}
if (c != FLUSH_BUFFER)
buf[i++] = c;
return (1);
}
/**
* charDup - add descr
* @pathstr: the PATH string
* @start: starting index
* @stop: stopping index
*
* Return: pointer to new buffer
*/
char *charDup(char *pathstr, int start, int stop)
{
static char buf[BUF_SIZE];
int i = 0, k = 0;
for (k = 0, i = start; i < stop; i++)
if (pathstr[i] != ':')
buf[k++] = pathstr[i];
buf[k] = 0;
return (buf);
}