-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4d8ad3
commit f42360a
Showing
5 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_memcpy.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/07 14:44:12 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/21 13:28:36 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
NAME | ||
memcpy -- copy memory area | ||
LIBRARY | ||
Standard C Library (libc, -lc) | ||
SYNOPSIS | ||
#include <string.h> | ||
void * | ||
memcpy(void *restrict dst, const void *restrict src, size_t n); | ||
DESCRIPTION | ||
The memcpy() function copies n bytes from memory area src to memory area | ||
dst. If dst and src overlap, | ||
behavior is undefined. Applications in which dst and src might overlap | ||
should use memmove(3) instead. | ||
RETURN VALUES | ||
The memcpy() function returns the original value of dst. | ||
*/ | ||
#include "libft.h" | ||
|
||
void *ft_memcpy(void *dst, const void *src, size_t n) | ||
{ | ||
char *d; | ||
const char *s; | ||
|
||
if (dst == NULL && src == NULL) | ||
return (NULL); | ||
if (n == 0) | ||
return (dst); | ||
d = (char *) dst; | ||
s = (const char *) src; | ||
while (n--) | ||
*d++ = *s++; | ||
if (dst) | ||
return (dst); | ||
return (NULL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_memmove.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/08 11:40:27 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/22 11:23:40 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
NAME | ||
memmove -- copy byte string | ||
LIBRARY | ||
Standard C Library (libc, -lc) | ||
SYNOPSIS | ||
#include <string.h> | ||
void * | ||
memmove(void *dst, const void *src, size_t len); | ||
DESCRIPTION | ||
The memmove() function copies len bytes from string src to string dst. | ||
The two strings may overlap; | ||
the copy is always done in a non-destructive manner. | ||
RETURN VALUES | ||
The memmove() function returns the original value of dst. | ||
*/ | ||
#include "libft.h" | ||
|
||
void *ft_memmove(void *dst, const void *src, size_t len) | ||
{ | ||
size_t i; | ||
|
||
i = 0; | ||
if (dst == NULL && src == NULL) | ||
return ((void *)(NULL)); | ||
if (src < dst) | ||
{ | ||
i = len - 1; | ||
while (i < len) | ||
{ | ||
((unsigned char *)dst)[i] = ((unsigned char *)src)[i]; | ||
i--; | ||
} | ||
} | ||
else | ||
{ | ||
while (i < len) | ||
{ | ||
((unsigned char *)dst)[i] = ((unsigned char *)src)[i]; | ||
i++; | ||
} | ||
} | ||
return (dst); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_memset.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/07 12:02:18 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/14 13:46:34 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
NAME | ||
memset -- fill a byte string with a byte value | ||
LIBRARY | ||
Standard C Library (libc, -lc) | ||
SYNOPSIS | ||
#include <string.h> | ||
void * | ||
memset(void *b, int c, size_t len); | ||
DESCRIPTION | ||
The memset() function writes len bytes of value c | ||
(converted to an unsigned char) to the string b. | ||
RETURN VALUES | ||
The memset() function returns its first argument. | ||
*/ | ||
#include "libft.h" | ||
|
||
void *ft_memset(void *b, int c, size_t len) | ||
{ | ||
size_t i; | ||
|
||
i = 0; | ||
while (i < len) | ||
{ | ||
((unsigned char *)b)[i] = c; | ||
i++; | ||
} | ||
return (b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_putchar_fd.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/18 16:34:20 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/18 17:09:45 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
PROTOTYPE | ||
void ft_putchar_fd(char c, int fd); | ||
PARAMETERS | ||
c: The character to output. | ||
fd: The file descriptor on which to write. | ||
EXTERNAL FUNCTS. | ||
write | ||
DESCRIPTION | ||
Outputs the character 'c' to the given file descriptor. | ||
*/ | ||
#include "libft.h" | ||
|
||
void ft_putchar_fd(char c, int fd) | ||
{ | ||
write(fd, &c, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_putendl_fd.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: ivanderw <marvin@42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/03/18 17:00:39 by ivanderw #+# #+# */ | ||
/* Updated: 2023/03/18 17:07:26 by ivanderw ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
/* | ||
PROTOTYPE | ||
void ft_putendl_fd(char *s, int fd); | ||
PARAMETERS | ||
s: The string to output. | ||
fd: The file descriptor on which to write. | ||
EXTERNAL FUNCTIONS | ||
Write | ||
DESCRIPTION | ||
Outputs the string 's' to the given file descriptor followed by a newline. | ||
*/ | ||
#include "libft.h" | ||
|
||
void ft_putendl_fd(char *s, int fd) | ||
{ | ||
int i; | ||
|
||
i = 0; | ||
while (s[i] != '\0') | ||
{ | ||
ft_putchar_fd(s[i], fd); | ||
i++; | ||
} | ||
ft_putchar_fd('\n', fd); | ||
} |