-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_string3.c
More file actions
97 lines (87 loc) · 2.02 KB
/
Copy path_string3.c
File metadata and controls
97 lines (87 loc) · 2.02 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
#include "shell.h"
/**
* _strncpy - Function copies a string
* @destination: The destination string to be copied to
* @source: The source string to copy
* @max_len: The maximum number of characters to be copied
* Return: Return pointer to the destination string
*/
char *_strncpy(char *destination, char *source, int max_len)
{
int i, j;
char *result = destination;
i = 0;
while (source[i] != '\0' && i < max_len - 1)
{
destination[i] = source[i];
i++;
}
if (i < max_len)
{
j = i;
while (j < max_len)
{
destination[j] = '\0';
j++;
}
}
return (result);
}
/**
* _strncat - Function concatenates two strings
* @destination: The first string
* @source: The second string
* @max_len: The maximum number of bytes to be used
* Return: Return pointer to the concatenated string
*/
char *_strncat(char *destination, char *source, int max_len)
{
int i, j;
char *result = destination;
i = 0;
j = 0;
while (destination[i] != '\0')
i++;
while (source[j] != '\0' && j < max_len)
{
destination[i] = source[j];
i++;
j++;
}
if (j < max_len)
destination[i] = '\0';
return (result);
}
/**
* _strchr - Function locates a character in a string
* @str: The string to be parsed
* @character: The character to look for
* Return: Return a pointer to the first occurrence of the
* character in the string,or NULL if the character is not found
*/
char *_strchr(char *str, char character)
{
do {
if (*str == character)
return (str);
} while (*str++ != '\0');
return (NULL);
}
/**
* _addHistoryEntry - Function adds an entry to the history linked list
* @info: Structure containing potential arguments. Used to maintain
* @buffer: Buffer containing the history entry
* @line_count: Return the line count of the history entry
*
* Return: Always 0
*/
int _addHistoryEntry(info_t *info, char *buffer, int line_count)
{
list_t *new_node = NULL;
if (info->_history)
new_node = info->_history;
_addNodeEnd(&new_node, buffer, line_count);
if (!info->_history)
info->_history = new_node;
return (0);
}