libft
Loading...
Searching...
No Matches
libft.h File Reference
#include <stdlib.h>
#include <unistd.h>
#include "get_next_line.h"
#include "vec.h"

Go to the source code of this file.

Data Structures

struct  s_list
 

Typedefs

typedef struct s_list t_list
 

Functions

int ft_atoi (const char *str)
 ASCII to integer.
 
void ft_bzero (void *s, size_t n)
 Zero a byte string.
 
void * ft_calloc (size_t count, size_t size)
 Allocate and zero.
 
int ft_isalnum (int c)
 Is an alphabet or a number.
 
int ft_isalpha (int c)
 Check if char is alphabet.
 
int ft_isascii (int c)
 Check if char is ASCII.
 
int ft_isdigit (int c)
 Check if char is digit.
 
int ft_isprint (int c)
 Check if char is printable.
 
char * ft_itoa (int n)
 Integer to ASCII.
 
void ft_lstadd_back (t_list **lst, t_list *node)
 List add back.
 
void ft_lstadd_front (t_list **lst, t_list *node)
 List add front.
 
void ft_lstclear (t_list **lst, void(*del)(void *))
 Clear list.
 
void ft_lstdelone (t_list *lst, void(*del)(void *))
 Delete node.
 
void ft_lstiter (t_list *lst, void(*f)(void *))
 Iterate list.
 
t_listft_lstlast (t_list *lst)
 Last node in a list.
 
t_listft_lstmap (t_list *lst, void *(*f)(void *), void(*del)(void *))
 List map.
 
t_listft_lstnew (void *content)
 Create a new node.
 
int ft_lstsize (t_list *lst)
 Size of a list.
 
char * ft_ltoa (long n)
 Long to ASCII.
 
void * ft_memchr (const void *s, int c, size_t n)
 Scan memory for a character.
 
int ft_memcmp (const void *s1, const void *s2, size_t n)
 Memory compare.
 
void * ft_memcpy (void *dst, const void *src, size_t n)
 Copies memory to destination.
 
void * ft_memmove (void *dst, const void *src, size_t len)
 Copy memory area.
 
void * ft_memset (void *b, int c, int len)
 Fill memory area with a contant byte.
 
void ft_putchar_fd (char c, int fd)
 Writes char to file.
 
void ft_putendl_fd (char *s, int fd)
 Writes new line to file.
 
void ft_putnbr_fd (int n, int fd)
 Writes number to file.
 
void ft_putstr_fd (char *s, int fd)
 Writes string to file.
 
char ** ft_split (char const *s, char c)
 Splits string to substrings.
 
char * ft_strchr (const char *s, int c)
 Search a character.
 
char * ft_strdup (const char *s1)
 Duplicates a string.
 
void ft_striteri (char *s, void(*f)(unsigned int, char *))
 Calls a function for each char of a string.
 
char * ft_strjoin (char const *s1, char const *s2)
 Joins two strings together.
 
size_t ft_strlcat (char *dst, const char *src, size_t dstsize)
 Adds string to end of a string.
 
size_t ft_strlcpy (char *dst, const char *src, size_t dstsize)
 Copies string to destination.
 
size_t ft_strlen (const char *s)
 Length of the string.
 
char * ft_strmapi (char const *s, char(*f)(unsigned int, char))
 Create a copy of a string passing each char through a function.
 
int ft_strncmp (const char *s1, const char *s2, size_t n)
 String compare.
 
char * ft_strnstr (const char *haystack, const char *needle, size_t len)
 Search string from string.
 
char * ft_strrchr (const char *s, int c)
 Search a character starting from the end.
 
char * ft_strtrim (char const *s1, char const *set)
 Trim start and end of a string.
 
char * ft_substr (char const *s, unsigned int start, size_t len)
 Gets a piece of string out of a string.
 
int ft_tolower (int c)
 Changes char to lowercase.
 
int ft_toupper (int c)
 Changes char to uppercase.
 
char * ft_ulongtohex (unsigned long n)
 Unsigned long to lowercase hexadesimal string.
 

Typedef Documentation

◆ t_list

typedef struct s_list t_list

Function Documentation

◆ ft_atoi()

int ft_atoi ( const char *  str)

ASCII to integer.

Returns integer from number string.

Parameters
strNumber as a string
Returns
int Number as a integer

Definition at line 15 of file ft_atoi.c.

◆ ft_bzero()

void ft_bzero ( void *  s,
size_t  n 
)

Zero a byte string.

Zeroes n number of bytes in memory starting from location pointed by s.

Parameters
sPointer to memory
nNumber of bytes

Definition at line 15 of file ft_bzero.c.

◆ ft_calloc()

void * ft_calloc ( size_t  count,
size_t  size 
)

Allocate and zero.

Allocates memory and sets every byte to 0.

Parameters
countHow many elements
sizeSize of a element (eg. 4 bytes)
Returns
void* Pointer to the allocated memory
Attention
Allocates memory

Definition at line 15 of file ft_calloc.c.

◆ ft_isalnum()

int ft_isalnum ( int  c)

Is an alphabet or a number.

Checks if character is an alphabet or a number.

Parameters
cCharacter as an ASCII desimal
Returns
int 1 if true, 0 if false

Definition at line 15 of file ft_isalnum.c.

◆ ft_isalpha()

int ft_isalpha ( int  c)

Check if char is alphabet.

Parameters
c
Returns
int

Definition at line 13 of file ft_isalpha.c.

◆ ft_isascii()

int ft_isascii ( int  c)

Check if char is ASCII.

Parameters
c
Returns
int

Definition at line 13 of file ft_isascii.c.

◆ ft_isdigit()

int ft_isdigit ( int  c)

Check if char is digit.

Parameters
c
Returns
int

Definition at line 13 of file ft_isdigit.c.

◆ ft_isprint()

int ft_isprint ( int  c)

Check if char is printable.

Parameters
c
Returns
int

Definition at line 13 of file ft_isprint.c.

◆ ft_itoa()

char * ft_itoa ( int  n)

Integer to ASCII.

Returns a number as a string.

Parameters
nNumber
Returns
char* Number n as a string
Attention
Allocates memory

Definition at line 57 of file ft_itoa.c.

◆ ft_lstadd_back()

void ft_lstadd_back ( t_list **  lst,
t_list node 
)

List add back.

Parameters
lst
new

Definition at line 15 of file ft_lstadd_back.c.

◆ ft_lstadd_front()

void ft_lstadd_front ( t_list **  lst,
t_list node 
)

List add front.

Parameters
lst
new

Definition at line 15 of file ft_lstadd_front.c.

◆ ft_lstclear()

void ft_lstclear ( t_list **  lst,
void(*)(void *)  del 
)

Clear list.

Parameters
lst
del

Definition at line 15 of file ft_lstclear.c.

◆ ft_lstdelone()

void ft_lstdelone ( t_list lst,
void(*)(void *)  del 
)

Delete node.

Parameters
lst
del

Definition at line 15 of file ft_lstdelone.c.

◆ ft_lstiter()

void ft_lstiter ( t_list lst,
void(*)(void *)  f 
)

Iterate list.

Parameters
lst
f

Definition at line 15 of file ft_lstiter.c.

◆ ft_lstlast()

t_list * ft_lstlast ( t_list lst)

Last node in a list.

Parameters
lst
Returns
t_list*

Definition at line 15 of file ft_lstlast.c.

◆ ft_lstmap()

t_list * ft_lstmap ( t_list lst,
void *(*)(void *)  f,
void(*)(void *)  del 
)

List map.

Parameters
lst
f
del
Returns
t_list*

Definition at line 15 of file ft_lstmap.c.

◆ ft_lstnew()

t_list * ft_lstnew ( void *  content)

Create a new node.

Parameters
content
Returns
t_list*

Definition at line 15 of file ft_lstnew.c.

◆ ft_lstsize()

int ft_lstsize ( t_list lst)

Size of a list.

Parameters
lst
Returns
int

Definition at line 15 of file ft_lstsize.c.

◆ ft_ltoa()

char * ft_ltoa ( long  n)

Long to ASCII.

Returns a number as a string.

Parameters
nlong Number
Returns
char* Number n as a string
Attention
Allocates memory

Definition at line 41 of file ft_ltoa.c.

◆ ft_memchr()

void * ft_memchr ( const void *  s,
int  c,
size_t  n 
)

Scan memory for a character.

Scans n bytes of memory from address s for a character c.

Parameters
sStarting address
cCharacter to find
nTill how many bytes from the starting address s
Returns
void* Address of the found character or a NULL if character not found

Definition at line 15 of file ft_memchr.c.

◆ ft_memcmp()

int ft_memcmp ( const void *  s1,
const void *  s2,
size_t  n 
)

Memory compare.

Compares n number of bytes from two addresses s1 and s1.

Parameters
s1First address
s2Second address
nNumber of bytes
Returns
int If s1 and s2 are equal returns 0. Else returns difference of the byte that was not equal.

Definition at line 15 of file ft_memcmp.c.

◆ ft_memcpy()

void * ft_memcpy ( void *  dst,
const void *  src,
size_t  n 
)

Copies memory to destination.

Copies n bytes of memory from source to destination.

Parameters
dstAddress of the destination
srcAddress of the source
Returns
void* Address of destination
Attention
Does not handle overlapping.

Definition at line 15 of file ft_memcpy.c.

◆ ft_memmove()

void * ft_memmove ( void *  dst,
const void *  src,
size_t  len 
)

Copy memory area.

Copies len bytes of memory from source to destination.

Parameters
dstAddress of the destination
srcAddress of the source
lenNumber of bytes
Returns
void* Address of the destination

Definition at line 15 of file ft_memmove.c.

◆ ft_memset()

void * ft_memset ( void *  b,
int  c,
int  len 
)

Fill memory area with a contant byte.

Fills len number of bytes of memory with c.

Parameters
bMemory address
cValue to set the bytes to
lenNumber of bytes
Returns
void* Address of b

Definition at line 13 of file ft_memset.c.

◆ ft_putchar_fd()

void ft_putchar_fd ( char  c,
int  fd 
)

Writes char to file.

Parameters
c
fd

Definition at line 15 of file ft_putchar_fd.c.

◆ ft_putendl_fd()

void ft_putendl_fd ( char *  s,
int  fd 
)

Writes new line to file.

Parameters
s
fd

Definition at line 15 of file ft_putendl_fd.c.

◆ ft_putnbr_fd()

void ft_putnbr_fd ( int  n,
int  fd 
)

Writes number to file.

Parameters
n
fd

Definition at line 29 of file ft_putnbr_fd.c.

◆ ft_putstr_fd()

void ft_putstr_fd ( char *  s,
int  fd 
)

Writes string to file.

Parameters
s
fd

Definition at line 15 of file ft_putstr_fd.c.

◆ ft_split()

char ** ft_split ( char const *  s,
char  c 
)

Splits string to substrings.

Splits string s by character c to substrings.

Parameters
sString
cCharacter
Returns
char** Array of substrings
Attention
Allocates memory

Definition at line 71 of file ft_split.c.

◆ ft_strchr()

char * ft_strchr ( const char *  s,
int  c 
)

Search a character.

Searches a character from a string and returns it's address.

Parameters
sString
cCharacter
Returns
char* Address of the found character or NULL if not found

Definition at line 15 of file ft_strchr.c.

◆ ft_strdup()

char * ft_strdup ( const char *  s1)

Duplicates a string.

Parameters
s1String to make a copy from
Returns
char* Address of the new string

Definition at line 15 of file ft_strdup.c.

◆ ft_striteri()

void ft_striteri ( char *  s,
void(*)(unsigned int, char *)  f 
)

Calls a function for each char of a string.

Function f takes the index and address of a character in the string.

Parameters
sString
fFunction

Definition at line 15 of file ft_striteri.c.

◆ ft_strjoin()

char * ft_strjoin ( char const *  s1,
char const *  s2 
)

Joins two strings together.

Parameters
s1String 1
s2Strong 2
Returns
char* New string containing s1 and s2
Attention
Allocates memory

Definition at line 15 of file ft_strjoin.c.

◆ ft_strlcat()

size_t ft_strlcat ( char *  dst,
const char *  src,
size_t  dstsize 
)

Adds string to end of a string.

Adds source to end of the destination limited by the destination size.

Parameters
dstString
srcString
dstsizeSize of the destination
Returns
size_t Sum of the lengths of source and destination

Definition at line 15 of file ft_strlcat.c.

◆ ft_strlcpy()

size_t ft_strlcpy ( char *  dst,
const char *  src,
size_t  dstsize 
)

Copies string to destination.

Copies string to destination and makes sure it's null terminated.

Parameters
dstString
srcString
dstsizeSize of the destination
Returns
size_t Lenght of the source

Definition at line 15 of file ft_strlcpy.c.

◆ ft_strlen()

size_t ft_strlen ( const char *  s)

Length of the string.

Parameters
sString
Returns
size_t Length of the string

Definition at line 15 of file ft_strlen.c.

◆ ft_strmapi()

char * ft_strmapi ( char const *  s,
char(*)(unsigned int, char)  f 
)

Create a copy of a string passing each char through a function.

Creates a new string and assigns the values to that string by taking a character from the string s and passing it trough the function f. Function f takes a character and index of that character as parameters.

Parameters
sString
fFunction
Returns
char* New string
Attention
Allocates memory

Definition at line 15 of file ft_strmapi.c.

◆ ft_strncmp()

int ft_strncmp ( const char *  s1,
const char *  s2,
size_t  n 
)

String compare.

Compares two strings and returns the difference of the first missmatch character or 0 if strings are equal.

Parameters
s1String
s2String
nNumber of characters to check
Returns
int 0 if equal else the difference of the first missmatch character

Definition at line 15 of file ft_strncmp.c.

◆ ft_strnstr()

char * ft_strnstr ( const char *  haystack,
const char *  needle,
size_t  len 
)

Search string from string.

Searches string from a string and returns the address of the start of the found string.

Parameters
haystackString
needleString
lenHow many char to check
Returns
char* Address of the found string

Definition at line 18 of file ft_strnstr.c.

◆ ft_strrchr()

char * ft_strrchr ( const char *  s,
int  c 
)

Search a character starting from the end.

Searches a character from a string and returns it's address.

Parameters
sString
cCharacter
Returns
char* Address of found char or NULL if not found

Definition at line 15 of file ft_strrchr.c.

◆ ft_strtrim()

char * ft_strtrim ( char const *  s1,
char const *  set 
)

Trim start and end of a string.

Trims set of characters from start and end of a string.

Parameters
s1String
setSet of character to trim from the string
Returns
char* Trimmed string
Attention
Allocates memory

Definition at line 15 of file ft_strtrim.c.

◆ ft_substr()

char * ft_substr ( char const *  s,
unsigned int  start,
size_t  len 
)

Gets a piece of string out of a string.

Gets len length piece of string from a strung starting at index start.

Parameters
sString
startStarting index
lenHow many chars
Returns
char* Address of the new substring
Attention
Allocates memory

Definition at line 22 of file ft_substr.c.

◆ ft_tolower()

int ft_tolower ( int  c)

Changes char to lowercase.

Parameters
c
Returns
int

Definition at line 13 of file ft_tolower.c.

◆ ft_toupper()

int ft_toupper ( int  c)

Changes char to uppercase.

Parameters
c
Returns
int

Definition at line 13 of file ft_toupper.c.

◆ ft_ulongtohex()

char * ft_ulongtohex ( unsigned long  n)

Unsigned long to lowercase hexadesimal string.

Parameters
nunsigned long
Returns
char* hexadesimal string in lowercase
Attention
Allocates memory

Definition at line 47 of file ft_ulongtohex.c.