tgrekov-libft
HIVE libft Oct 2023
|
Definition in file libft.h.
#include <stdlib.h>
#include <unistd.h>
Go to the source code of this file.
Data Structures | |
struct | s_list |
Linked list node. More... | |
Macros | |
#define | FT_LONG_MAX 9223372036854775807L |
Not allowed to include limits.h. | |
Typedefs | |
typedef struct s_list | t_list |
Linked list node. | |
Functions | |
int | ft_atoi (const char *str) |
Converts ASCII string str to integer representation. | |
void | ft_bzero (void *s, size_t n) |
Write n zeroes to byte string at pointer s . | |
void * | ft_calloc (size_t count, size_t size) |
Allocates count * size bytes with malloc and returns a pointer to the result. | |
int | ft_isalnum (int c) |
Is c an alphanumeric character. | |
int | ft_isalpha (int c) |
Is c an alphabetical character. | |
int | ft_isascii (int c) |
Is c in the ASCII character range. | |
int | ft_isdigit (int c) |
Is c a numeric character. | |
int | ft_isprint (int c) |
Is c a printable character. | |
char * | ft_itoa (int n) |
Converts integer n to an allocated ASCII string. | |
void | ft_lstiter (t_list *lst, void(*f)(void *)) |
Iterates over a list and applies the function f over each node. | |
void | ft_lstadd_back (t_list **lst, t_list *new) |
Adds node at pointer new to the end of the list starting at pointer pointed to by lst . | |
void | ft_lstadd_front (t_list **lst, t_list *new) |
Insert node new into the start of the list pointed to by the pointer at lst . | |
void | ft_lstclear (t_list **lst, void(*del)(void *)) |
Delete every node in a list along with it's content. | |
void | ft_lstdelone (t_list *lst, void(*del)(void *)) |
Delete a node and it's content. | |
t_list * | ft_lstlast (t_list *lst) |
Get the last node in a list. | |
t_list * | ft_lstmap (t_list *lst, void *(*f)(void *), void(*del)(void *)) |
Iterate over a list and create a new one from the results of applying f to the content of each node. | |
t_list * | ft_lstnew (void *content) |
Allocates a new node, set it's content, and return it's address. | |
int | ft_lstsize (t_list *lst) |
Counts the number of nodes in a list. | |
void * | ft_memchr (const void *s, int c, size_t n) |
Finds first occurence of c in byte string at s within n bytes. | |
int | ft_memcmp (const void *s1, const void *s2, size_t n) |
Compares n bytes of byte string s1 against byte string s2 . | |
void * | ft_memcpy (void *dst, const void *src, size_t n) |
Copies n bytes from byte string src to byte string dst . | |
void * | ft_memmove (void *dst, const void *src, size_t len) |
Copies len bytes from byte string src to byte string dst non-destructively. | |
void * | ft_memset (void *b, int c, size_t len) |
Fills len bytes of byte string b with value c . | |
void | ft_putchar_fd (char c, int fd) |
Write character c to file descriptor fd . | |
void | ft_putendl_fd (char *s, int fd) |
Write string at pointer s followed by a newline to file descriptor fd . | |
void | ft_putnbr_fd (int n, int fd) |
Converts integer n to it's ASCII representation and writes it to file descriptor fd . | |
void | ft_putstr_fd (char *s, int fd) |
Write string at pointer s to file descriptor fd . | |
char ** | ft_split (char const *s, char c) |
Split string s by characer c into allocated array of strings, with NULL as the last element. | |
char * | ft_strchr (const char *s, int c) |
Finds first occurence of character c in string s . | |
char * | ft_strdup (const char *s1) |
Allocates memory for, copies to, and returns a duplicate of s1 . | |
void | ft_striteri (char *s, void(*f)(unsigned int, char *)) |
Applies function f to each character of string s . | |
char * | ft_strjoin (char const *s1, char const *s2) |
Allocates enough space for and appends string s2 to string s1 and returns the new string. | |
size_t | ft_strlcat (char *dst, const char *src, size_t dstsize) |
Appends at most dstsize - ft_strlen(dst) - 1 characters of string src to the end of string dst . | |
size_t | ft_strlcpy (char *dst, const char *src, size_t dstsize) |
Copy at most dstsize - 1 characters from string src into dst . | |
size_t | ft_strlen (const char *str) |
Get length of str . | |
char * | ft_strmapi (char const *s, char(*f)(unsigned int, char)) |
Allocates and creates a new string from the output of function f processing each character of string s . | |
int | ft_strncmp (const char *s1, const char *s2, size_t n) |
Compare up to n characters of string s1 with string s2 . | |
char * | ft_strnstr (const char *haystack, const char *needle, size_t len) |
Finds first occurence of needle in string haystack . | |
char * | ft_strrchr (const char *s, int c) |
Finds last occurence of c in string at s . | |
char * | ft_strtrim (char const *s1, char const *set) |
Allocates and returns a copy of s1 with any successive characters found in string set removed from the start and end. | |
char * | ft_substr (char const *s, unsigned int start, size_t len) |
Allocates and returns a substring of s , starting at s + start , and ending no later than s + start + len . | |
int | ft_tolower (int c) |
Convert uppercase letter to corresponding lowercase letter. | |
int | ft_toupper (int c) |
Convert lowercase letter to corresponding uppercase letter. | |
#define FT_LONG_MAX 9223372036854775807L |
int ft_atoi | ( | const char * | str | ) |
Converts ASCII string str
to integer representation.
Converts the initial numerical portion of the string at pointer str
to int representation.
Numerical portion may be preceded by a singular optional + or - sign.
[in] | str | Null-terminated string containing integer |
int | Result of conversion, unless the value (handled as a long during conversion), would overflow or underflow, in which case it returns FT_LONG_MAX or FT_LONG_MAX - 1 , respectively. |
Definition at line 42 of file ft_atoi.c.
References ft_isdigit(), and FT_LONG_MAX.
void ft_bzero | ( | void * | s, |
size_t | n | ||
) |
Write n
zeroes to byte string at pointer s
.
[in] | s | Pointer to start of byte string |
[in] | n | Number of zeroes to write |
Definition at line 28 of file ft_bzero.c.
void * ft_calloc | ( | size_t | count, |
size_t | size | ||
) |
Allocates count
* size
bytes with malloc and returns a pointer to the result.
[in] | count | Number of objects to allocate for |
[in] | size | Size of each object |
void* | Freeable pointer to allocated memory after it is filled with zeroes If either count or size are 0 , returns ft_calloc(1, 1) . If the multiplication of count and size overflows, returns NULL . |
Definition at line 34 of file ft_calloc.c.
References ft_bzero(), and ft_calloc().
int ft_isalnum | ( | int | c | ) |
Is c an alphanumeric character.
[in] | c | Character to test |
int | ft_isalpha(c) || ft_isdigit(c) |
Definition at line 29 of file ft_isalnum.c.
References ft_isalpha(), and ft_isdigit().
int ft_isalpha | ( | int | c | ) |
Is c
an alphabetical character.
[in] | c | Character to test |
int | 1 if c is within either of the ranges A - Z or a - z , otherwise 0 |
Definition at line 27 of file ft_isalpha.c.
int ft_isascii | ( | int | c | ) |
Is c
in the ASCII character range.
[in] | c | Character to test |
int | 1 if c is within the range 0 - 127 , otherwise 0 |
Definition at line 26 of file ft_isascii.c.
int ft_isdigit | ( | int | c | ) |
Is c
a numeric character.
[in] | c | Character to test |
int | 1 if c is within the range 0 - 9 , otherwise 0 |
Definition at line 26 of file ft_isdigit.c.
int ft_isprint | ( | int | c | ) |
Is c
a printable character.
[in] | c | Character to test |
int | 1 if c is within the range ' ' - ~ |
Definition at line 26 of file ft_isprint.c.
char * ft_itoa | ( | int | n | ) |
Converts integer n
to an allocated ASCII string.
[in] | n | Integer to convert |
char* | Null-terminated string containing an ASCII representation of n , preceded by '-' if n is negative. If allocation fails, returns NULL . |
Definition at line 50 of file ft_itoa.c.
References ft_calloc().
Adds node at pointer new
to the end of the list starting at pointer pointed to by lst
.
If lst
is NULL
, does nothing.
If pointer at lst
is NULL
, sets pointer at lst
to new
.
Otherwise sets next property of the last node in the list to new
[in,out] | lst | Pointer to pointer to first node in the list. |
[in] | new | Pointer to the new node to add |
Definition at line 35 of file ft_lstadd_back_bonus.c.
References ft_lstlast(), and s_list::next.
Insert node new
into the start of the list pointed to by the pointer at lst
.
If lst
or new
are NULL
, does nothing.
Sets next property of node at pointer new
to address at pointer lst
and sets pointer at lst
to new
[in,out] | lst | Pointer to pointer to first node in the list. |
[in] | new | Pointer to the new node to add |
Definition at line 34 of file ft_lstadd_front_bonus.c.
void ft_lstclear | ( | t_list ** | lst, |
void(*)(void *) | del | ||
) |
Delete every node in a list along with it's content.
[in,out] | lst | Pointer to a pointer to the first node in the list |
[in] | del | Function used to properly handle the deletion of the node's content |
Definition at line 31 of file ft_lstclear_bonus.c.
References ft_lstdelone(), and s_list::next.
void ft_lstdelone | ( | t_list * | lst, |
void(*)(void *) | del | ||
) |
Delete a node and it's content.
[in,out] | lst | Pointer to the first node in the list |
[in] | del | Function used to properly handle the deletion of the node's content |
Definition at line 29 of file ft_lstdelone_bonus.c.
References s_list::content.
void ft_lstiter | ( | t_list * | lst, |
void(*)(void *) | f | ||
) |
Iterates over a list and applies the function f
over each node.
[in] | lst | Pointer to the first node in the list |
[in] | f | Function which accepts the content of a node |
Definition at line 30 of file ft_lstiter_bonus.c.
References s_list::content, and s_list::next.
Get the last node in a list.
[in] | lst | Pointer to the first node in the list |
t_list* | Pointer to the last node in the list |
Definition at line 28 of file ft_lstlast_bonus.c.
References s_list::next.
Iterate over a list and create a new one from the results of applying f
to the content of each node.
[in] | lst | Pointer to the starting node |
[in] | f | Function which takes the content of the current node and returns the content for the new node |
[in] | del | Function used to properly handle deletion of each node's content in the new list, should allocation fail |
t_list* | Pointer to the first node in the new list |
Definition at line 35 of file ft_lstmap_bonus.c.
References s_list::content, ft_lstadd_back(), ft_lstclear(), ft_lstnew(), and s_list::next.
t_list * ft_lstnew | ( | void * | content | ) |
Allocates a new node, set it's content, and return it's address.
[in] | content | Value to set the content property to |
t_list* | Pointer to the allocated node |
Definition at line 29 of file ft_lstnew_bonus.c.
References s_list::content, and s_list::next.
int ft_lstsize | ( | t_list * | lst | ) |
Counts the number of nodes in a list.
[in] | lst | Pointer to first node in the list |
int | Length of the list |
Definition at line 28 of file ft_lstsize_bonus.c.
References s_list::next.
void * ft_memchr | ( | const void * | s, |
int | c, | ||
size_t | n | ||
) |
Finds first occurence of c
in byte string at s
within n
bytes.
Check is done as unsigned char
[in] | s | Byte string haystack to search |
[in] | c | int needle to find |
[in] | n | Number of bytes to check |
void* | Pointer to first occurence of needle c in haystack s . NULL if none is found within n bytes. |
Definition at line 33 of file ft_memchr.c.
int ft_memcmp | ( | const void * | s1, |
const void * | s2, | ||
size_t | n | ||
) |
Compares n
bytes of byte string s1
against byte string s2
.
Comparisons are done with unsigned char
.
[in] | s1 | First byte string to compare |
[in] | s2 | Second byte string to compare |
[in] | n | Number of bytes to compare |
int | Result of subtracting the differing byte of s2 from that of s1 . If no difference was found in n bytes, returns 0 . |
Definition at line 34 of file ft_memcmp.c.
void * ft_memcpy | ( | void * | dst, |
const void * | src, | ||
size_t | n | ||
) |
Copies n
bytes from byte string src
to byte string dst
.
Copy is always performed from end to start.
If your dst
starts at any point after your src
, even if they overlap, this function is safe.
If your dst
starts prior to your src
and overlaps it, or there is a possibility of this happening, use ft_memmove.
[in] | dst | Pointer to destination byte string |
[in] | src | Pointer to source byte string |
[in] | n | Number of bytes to copy |
void* | dst |
Definition at line 36 of file ft_memcpy.c.
void * ft_memmove | ( | void * | dst, |
const void * | src, | ||
size_t | len | ||
) |
Copies len
bytes from byte string src
to byte string dst
non-destructively.
src
and dst
may overlap in any manner, the function will switch copy directions to ensure the data is copied non-destructively.
[in] | dst | Pointer to destination byte string |
[in] | src | Pointer to source byte string |
[in] | len | Number of bytes to copy |
void* | dst |
Definition at line 34 of file ft_memmove.c.
void * ft_memset | ( | void * | b, |
int | c, | ||
size_t | len | ||
) |
Fills len
bytes of byte string b
with value c
.
[in,out] | b | Pointer to start of byte string |
[in] | c | Integer representation of value to write (cast to unsigned char ) |
[in] | len | Number of bytes to write |
void* | b |
Definition at line 31 of file ft_memset.c.
void ft_putchar_fd | ( | char | c, |
int | fd | ||
) |
Write character c
to file descriptor fd
.
[in] | c | Character to write |
[in] | fd | File descriptor to write to |
Definition at line 28 of file ft_putchar_fd.c.
void ft_putendl_fd | ( | char * | s, |
int | fd | ||
) |
Write string at pointer s
followed by a newline to file descriptor fd
.
[in] | s | Pointer to string to write |
[in] | fd | File descriptor to write to |
Definition at line 29 of file ft_putendl_fd.c.
References ft_putchar_fd(), and ft_putstr_fd().
void ft_putnbr_fd | ( | int | n, |
int | fd | ||
) |
Converts integer n
to it's ASCII representation and writes it to file descriptor fd
.
[in] | n | Integer to convert |
[in] | fd | File descriptor to write to |
Definition at line 29 of file ft_putnbr_fd.c.
References ft_putnbr_fd().
void ft_putstr_fd | ( | char * | s, |
int | fd | ||
) |
Write string at pointer s
to file descriptor fd
.
[in] | s | Pointer to string to write |
[in] | fd | File descriptor to write to |
Definition at line 28 of file ft_putstr_fd.c.
References ft_strlen().
char ** ft_split | ( | char const * | s, |
char | c | ||
) |
Split string s
by characer c
into allocated array of strings, with NULL
as the last element.
[in] | s | Null-terminated string to split |
[in] | c | Character to split on |
char** | Allocated array of allocated string pointers, with NULL as the last element |
Definition at line 72 of file ft_split.c.
References ft_calloc(), and ft_substr().
char * ft_strchr | ( | const char * | s, |
int | c | ||
) |
Finds first occurence of character c
in string s
.
Check is done as char
[in] | s | Null-terminated string haystack to search |
[in] | c | int needle to find |
char* | Pointer to first occurence of needle c in haystack s . NULL if none is found before the end of the string. |
Definition at line 30 of file ft_strchr.c.
char * ft_strdup | ( | const char * | s1 | ) |
Allocates memory for, copies to, and returns a duplicate of s1
.
[in] | s1 | Null-terminated string to copy |
char* | Null-terminated, duplicate string, result of malloc |
Definition at line 28 of file ft_strdup.c.
References ft_memcpy(), and ft_strlen().
void ft_striteri | ( | char * | s, |
void(*)(unsigned int, char *) | f | ||
) |
Applies function f
to each character of string s
.
This function iterates from end to start
[in,out] | s | Null-terminated string to iterate over |
[in] | f | Pointer to a function where the first and second arguments are the index of the current character and a pointer to the current character |
Definition at line 31 of file ft_striteri.c.
References ft_strlen().
char * ft_strjoin | ( | char const * | s1, |
char const * | s2 | ||
) |
Allocates enough space for and appends string s2
to string s1
and returns the new string.
[in] | s1 | Null-terminated prefix string |
[in] | s2 | Null-terminated suffix string |
char* | Null-terminated combination of s1 and s2 |
Definition at line 30 of file ft_strjoin.c.
References ft_memcpy(), and ft_strlen().
size_t ft_strlcat | ( | char * | dst, |
const char * | src, | ||
size_t | dstsize | ||
) |
Appends at most dstsize - ft_strlen(dst) - 1
characters of string src
to the end of string dst
.
Null-terminates dst
if dstsize != 0
and ft_strlen(dst) < dstsize
[in,out] | dst | Null-terminated string to append to |
[in] | src | Null terminated string to append from |
[in] | dstsize | Maximum size of the destination after appending |
size_t | Length of the string the function attempted to create |
Definition at line 34 of file ft_strlcat.c.
References ft_strlen().
size_t ft_strlcpy | ( | char * | dst, |
const char * | src, | ||
size_t | dstsize | ||
) |
Copy at most dstsize - 1
characters from string src
into dst
.
Null-terminates dst
if dstsize != 0
[in,out] | dst | Pointer to allocated memory of at least ft_strlen(src ) or dstsize size, whichever is smaller |
[in] | src | Optionally null-terminated string string |
[in] | dstsize | Number of characters to copy, should be no greater than the allocated space at dst |
size_t | Length of src |
Definition at line 36 of file ft_strlcpy.c.
References ft_strlen().
size_t ft_strlen | ( | const char * | str | ) |
Get length of str
.
[in] | str | String to get the length of |
size_t | Length of string starting at pointer str |
Definition at line 28 of file ft_strlen.c.
char * ft_strmapi | ( | char const * | s, |
char(*)(unsigned int, char) | f | ||
) |
Allocates and creates a new string from the output of function f
processing each character of string s
.
This function iterates from end to start
[in] | s | Null-terminated string to iterate over |
[in] | f | Pointer to a function that returns each character of the new string individually, provided the index and value of each original character |
char* | Null-terminated string populated from successive applications of f . Result of malloc. |
Definition at line 34 of file ft_strmapi.c.
References ft_calloc(), and ft_strlen().
int ft_strncmp | ( | const char * | s1, |
const char * | s2, | ||
size_t | n | ||
) |
Compare up to n
characters of string s1
with string s2
.
[in] | s1 | Optionally null-terminated string |
[in] | s2 | Optionally null-terminated string |
[in] | n | Maximum number of characters to compare |
int | Result of subtracting the differing character of s2 from that of s1 . If no difference was found in n characters, or before the strings were terminated, returns 0 . |
Definition at line 33 of file ft_strncmp.c.
char * ft_strnstr | ( | const char * | haystack, |
const char * | needle, | ||
size_t | len | ||
) |
Finds first occurence of needle
in string haystack
.
[in] | haystack | Optionally null-terminated string haystack to search |
[in] | needle | Null-terminated string needle to find |
[in] | len | Maximum number of bytes to check |
char* | Pointer to the start of the first occurence of needle in haystack . If not found within len characters or before termination of haystack , returns NULL . |
Definition at line 33 of file ft_strnstr.c.
char * ft_strrchr | ( | const char * | s, |
int | c | ||
) |
Finds last occurence of c
in string at s
.
Check is done as char
[in] | s | Null-terminated string haystack to search |
[in] | c | int needle to find |
char* | Pointer to last occurence of needle c in haystack s . NULL if none is found before the end of the string. |
Definition at line 30 of file ft_strrchr.c.
char * ft_strtrim | ( | char const * | s1, |
char const * | set | ||
) |
Allocates and returns a copy of s1
with any successive characters found in string set
removed from the start and end.
[in] | s1 | Null-terminated string to trim |
[in] | set | Null-terminated string containing characters to trim off s1 |
char* | Pointer to allocated trimmed string |
Definition at line 31 of file ft_strtrim.c.
References ft_strchr(), ft_strlcpy(), and ft_strlen().
char * ft_substr | ( | char const * | s, |
unsigned int | start, | ||
size_t | len | ||
) |
Allocates and returns a substring of s
, starting at s
+ start
, and ending no later than s
+ start
+ len
.
[in] | s | Null-terminated string to make a substring of |
[in] | start | Position from s at which to start |
[in] | len | Maximum length of the substring to make |
char* | Pointer to allocated null-terminated substring |
Definition at line 32 of file ft_substr.c.
References ft_calloc(), ft_strlcpy(), and ft_strlen().
int ft_tolower | ( | int | c | ) |
Convert uppercase letter to corresponding lowercase letter.
[in] | c | Character to convert |
int | If c is an uppercase letter character, returns the integer representation of the corresponding lowercase letter character, otherwise returns c . |
Definition at line 28 of file ft_tolower.c.
int ft_toupper | ( | int | c | ) |
Convert lowercase letter to corresponding uppercase letter.
[in] | c | Character to convert |
int | If c is a lowercase letter character, returns the integer representation of the corresponding uppercase letter character, otherwise returns c . |
Definition at line 28 of file ft_toupper.c.