Skip to content

Commit

Permalink
update (libft): some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lareii committed Apr 27, 2024
1 parent 93db771 commit f5d9363
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
5 changes: 2 additions & 3 deletions libft/src/memory/ft_memchr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ebabaogl <ebabaogl@student.42kocaeli.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/26 15:41:55 by ebabaogl #+# #+# */
/* Updated: 2024/04/27 18:12:05 by ebabaogl ### ########.fr */
/* Updated: 2024/04/27 19:12:10 by ebabaogl ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -17,12 +17,11 @@ void *ft_memchr(const void *s, int c, size_t n)
unsigned char *p;

p = (unsigned char *)s;
while (n > 0)
while (n--)
{
if (*p == (unsigned char)c)
return (p);
p++;
n--;
}
return (0);
}
5 changes: 2 additions & 3 deletions libft/src/memory/ft_memcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ebabaogl <ebabaogl@student.42kocaeli.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/26 15:52:23 by ebabaogl #+# #+# */
/* Updated: 2024/04/27 18:12:05 by ebabaogl ### ########.fr */
/* Updated: 2024/04/27 19:12:18 by ebabaogl ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,7 +19,7 @@ int ft_memcmp(const void *s1, const void *s2, size_t n)

p1 = (unsigned char *)s1;
p2 = (unsigned char *)s2;
while (n > 0)
while (n--)
{
if (*p1 > *p2)
return (1);
Expand All @@ -30,7 +30,6 @@ int ft_memcmp(const void *s1, const void *s2, size_t n)
p1++;
p2++;
}
n--;
}
return (0);
}
4 changes: 2 additions & 2 deletions libft/src/memory/ft_memcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ebabaogl <ebabaogl@student.42kocaeli.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/23 14:31:16 by ebabaogl #+# #+# */
/* Updated: 2024/04/27 18:52:42 by ebabaogl ### ########.fr */
/* Updated: 2024/04/27 19:11:18 by ebabaogl ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -24,4 +24,4 @@ void *ft_memcpy(void *dst, const void *src, size_t n)
while (n--)
*d++ = *s++;
return (dst);
}
}
4 changes: 2 additions & 2 deletions libft/src/memory/ft_memmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ebabaogl <ebabaogl@student.42kocaeli.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/26 14:19:12 by ebabaogl #+# #+# */
/* Updated: 2024/04/27 18:53:17 by ebabaogl ### ########.fr */
/* Updated: 2024/04/27 19:11:21 by ebabaogl ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -28,4 +28,4 @@ void *ft_memmove(void *dest, const void *src, size_t n)
while (n--)
*d++ = *s++;
return (dest);
}
}
10 changes: 3 additions & 7 deletions libft/src/memory/ft_memset.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ebabaogl <ebabaogl@student.42kocaeli.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/19 16:38:06 by ebabaogl #+# #+# */
/* Updated: 2024/04/27 18:12:05 by ebabaogl ### ########.fr */
/* Updated: 2024/04/27 19:12:36 by ebabaogl ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -17,11 +17,7 @@ void *ft_memset(void *s, int c, size_t n)
unsigned char *ptr;

ptr = (unsigned char *)s;
while (n > 0)
{
*ptr = c;
ptr++;
n--;
}
while (n--)
*ptr++ = c;
return (s);
}
2 changes: 1 addition & 1 deletion libft/src/string/ft_strlen.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ebabaogl <ebabaogl@student.42kocaeli.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/19 16:20:27 by ebabaogl #+# #+# */
/* Updated: 2024/04/27 18:12:05 by ebabaogl ### ########.fr */
/* Updated: 2024/04/27 19:12:50 by ebabaogl ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down

0 comments on commit f5d9363

Please sign in to comment.