-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibft.h
More file actions
182 lines (154 loc) · 7.83 KB
/
Copy pathlibft.h
File metadata and controls
182 lines (154 loc) · 7.83 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: uviana-a <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/18 15:07:18 by uviana-a #+# #+# */
/* Updated: 2023/04/18 15:07:21 by uviana-a ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
/*__________________________________[HEADERS]________________________________*/
# include <stdio.h>
# include <unistd.h>
# include <stdlib.h>
# include <string.h>
# include <ctype.h>
# include <stddef.h>
/*_________________________________[FUNCTIONS]_______________________________*/
/*-----------------------------*Mandatory Part I*----------------------------*/
//MEMORY MANIPULATION:****************************************************
//ft_bzero(): Writes zeroes to a byte string.
void ft_bzero(void *s, size_t n);
//*ft_memcpy(): Copies n bytes of data from a memory area
//(the data CAN'T overleap).
void *ft_memcpy(void *dest, const void *src, size_t n);
//*ft_memset(): Writes a byte to a byte string.
void *ft_memset(void *s, int c, size_t n);
//*ft_memmove(): Copies n bytes of data from
//a memory area (the data CAN overleap).
void *ft_memmove(void *dest, const void *src, size_t n);
//*ft_memchr(): Returns the position in the memory that
// the first occurrence of a character happened.
void *ft_memchr(const void *s, int c, size_t n);
//ft_memcmp(): Compares two memory areas and returns the difference
//between the first different character.
int ft_memcmp(const void *s1, const void *s2, size_t n);
//STRING MANIPULATION:****************************************************
//*ft_calloc(): Alocate some memory of size bytes and sets as 0.
void *ft_calloc(size_t nmemb, size_t size);
//*ft_strdup(): Make some memory with malloc()
//and duplicates a string to there.
char *ft_strdup(const char *s);
//ft_strncmp(): Compares two strings and returns the difference between
//the first different character.
int ft_strncmp(const char *s1, const char *s2, size_t n);
//ft_strlen(): Measure the size of a string without
//the NULL character ('\0').
size_t ft_strlen(const char *s);
//ft_strlcpy(): Copy a string src to a dest and guarantee the null
//terminator, return the size of src.
size_t ft_strlcpy(char *dst, const char *src, size_t size);
//ft_strlcat(): Concatenate a string src to a dest and guarantee
//the null terminator, return the size of src + dest.
size_t ft_strlcat(char *dst, const char *src, size_t size);
//*ft_strchr(): Returns the position in the memory that the first
//occurrence of a character happened."
char *ft_strchr(const char *s, int c);
//*ft_strrchr(): Returns the position in the memory that the
//last occurrence of a character happened."
char *ft_strrchr(const char *s, int c);
//*ft_strnstr(): Returns the position of the first occurrence of a
//string, if it didn't find it returns NULL, if the little
//string isn't find it returns the big string.
char *ft_strnstr(const char *big, const char *little, size_t len);
//CHARACTER CLASSIFICATION:***********************************************
//ft_isalnum(): Alphanumeric character test.
int ft_isalnum(int c);
//ft_isalpha(): Alphabetic character test.
int ft_isalpha(int c);
//ft_isascii(): Ascii character test.
int ft_isascii(int c);
//ft_isdigit(): Decimal digit character test.
int ft_isdigit(int c);
//ft_isprint(): Printing character test (space character inclusive).
int ft_isprint(int c);
//ft_toupper(): Changes one character to uppercase if it's
//lowercase else returns the character without changes.
int ft_toupper(int c);
//ft_tolower(): Changes one character to lowercase if it's
//uppercase else returns the character without changes.
int ft_tolower(int c);
//STRING TO INTEGER CONVERSION:*******************************************
//ft_atoi(): Converts the initial portion of the string in int.
int ft_atoi(const char *nptr);
/*-----------------------------*Mandatory Part II*---------------------------*/
// STRING MANIPULATION:
//*ft_substr(): Returns a pointer to a substring that has size len.
char *ft_substr(char const *s, unsigned int start, size_t len);
//*ft_strjoin(): Concatenate two strings and returns a pointer to
//the new bigger string.
char *ft_strjoin(char const *s1, char const *s2);
//*ft_strtrim(): Returns a pointer to a new string that has the
//characters of the set removed from the beginning and the
//end of the string.
char *ft_strtrim(char const *s1, char const *set);
//**ft_split(): Returns a pointer to an array of strings that
//are obtained by splitting the string s using the character c as a delimiter.
char **ft_split(char const *s, char c);
//*ft_strmapi(): Applies the function f to each character of
//the string s to create a new string resulting from
//successive applications of f.
char *ft_strmapi(char const *s, char (*f) (unsigned int, char));
//*ft_striteri(): Applies the function f to each character
//of the string passed as argument, and passing its index
//as first argument. Each character is passed by address to f
//to be modified if necessary.
void ft_striteri(char *s, void (*f)(unsigned int, char *));
//ft_putchar_fd(): Outputs the character c to the given file descriptor.
// FILE DESCRIPTOR OUTPUT:*************************************************
void ft_putchar_fd(char c, int fd);
//ft_putstr_fd(): Outputs the string s to the given file descriptor.
void ft_putstr_fd(char *s, int fd);
//ft_putendl_fd(): Outputs the string s to the given file descriptor,
//followed by a newline.
void ft_putendl_fd(char *s, int fd);
//ft_putnbr_fd(): Outputs the integer n to the given file descriptor.
void ft_putnbr_fd(int n, int fd);
//INTEGER TO STRING CONVERSION:*******************************************
//*ft_itoa(): Returns a pointer to a new string that
//represents the integer received as an argument.
char *ft_itoa(int n);
/*___________________________________[BONUS]_________________________________*/
//LINKED LIST:************************************************************
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
//LIST CREATION AND MODIFICATION:*****************************************
//*ft_lstnew(): Allocates (with malloc(3)) and returns a new element.
t_list *ft_lstnew(void *content);
//*ft_lstadd_front(): Adds the element ’new’ at the beginning of the list.
void ft_lstadd_front(t_list **lst, t_list *new);
//*ft_lstlast(): Returns the last element of the list.
t_list *ft_lstlast(t_list *lst);
//*ft_lstadd_back(): Adds the element ’new’ at the end of the list.
void ft_lstadd_back(t_list **lst, t_list *new);
//LIST DELETION AND MEMORY MANAGEMENT:************************************
//*ft_lstdelone(): Takes as a parameter an element and frees the memory
void ft_lstdelone(t_list *lst, void (*del)(void *));
//*ft_lstclear(): Deletes and frees the given element and every successor
void ft_lstclear(t_list **lst, void (*del)(void *));
//LIST ITERATION AND MAPPING:*********************************************
//ft_lstiter(): Iterates the list ’lst’ and applies the function
void ft_lstiter(t_list *lst, void (*f)(void *));
//*ft_lstsize(): Counts the number of elements in a list.
int ft_lstsize(t_list *lst);
//*ft_lstmap(): Iterates the list ’lst’ and applies the function returning
//a new list
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
#endif