Skip to content

Commit b592dab

Browse files
committed
fix memcmp, add different*, change directory structure
1 parent ddc0451 commit b592dab

19 files changed

Lines changed: 109 additions & 4 deletions

src/compare/mem_different.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* fake_file_name (file name is useless too) :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: 42header-remover <whatever@example.com> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 1970/01/01 00:00:00 by VCS handles #+# #+# */
9+
/* Updated: 1970/01/01 00:00:00 by file history ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include <ft/memory.h>
14+
15+
void *ft_mem_different(void *s1, void *s2, size_t size)
16+
{
17+
size_t i;
18+
19+
i = 0;
20+
while (i < size)
21+
{
22+
if (*((unsigned char *) s1 + i) != *((unsigned char *) s2 + i))
23+
return (s1);
24+
i++;
25+
}
26+
return (NULL);
27+
}

src/compare/mem_different_index.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* fake_file_name (file name is useless too) :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: 42header-remover <whatever@example.com> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 1970/01/01 00:00:00 by VCS handles #+# #+# */
9+
/* Updated: 1970/01/01 00:00:00 by file history ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include <ft/memory.h>
14+
15+
size_t ft_mem_different_index(void *s1, void *s2, size_t size)
16+
{
17+
size_t i;
18+
19+
i = 0;
20+
while (i < size)
21+
{
22+
if (*((unsigned char *) s1 + i) != *((unsigned char *) s2 + i))
23+
return (i);
24+
i++;
25+
}
26+
return (size);
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* fake_file_name (file name is useless too) :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: 42header-remover <whatever@example.com> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 1970/01/01 00:00:00 by VCS handles #+# #+# */
9+
/* Updated: 1970/01/01 00:00:00 by file history ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include <ft/memory.h>
14+
15+
size_t ft_mem_different_index_reverse(void *s1, void *s2, size_t size)
16+
{
17+
size_t i;
18+
19+
i = size;
20+
while (i--)
21+
if (*((unsigned char *) s1 + i) != *((unsigned char *) s2 + i))
22+
return (i);
23+
return (size);
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* fake_file_name (file name is useless too) :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: 42header-remover <whatever@example.com> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 1970/01/01 00:00:00 by VCS handles #+# #+# */
9+
/* Updated: 1970/01/01 00:00:00 by file history ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include <ft/memory.h>
14+
15+
void *ft_mem_different_reverse(void *s1, void *s2, size_t size)
16+
{
17+
size_t i;
18+
19+
i = size;
20+
while (i--)
21+
if (*((unsigned char *) s1 + i) != *((unsigned char *) s2 + i))
22+
return (s1);
23+
return (NULL);
24+
}

src/memcmp.c renamed to src/compare/memcmp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ int ft_memcmp(void *s1, void *s2, size_t size)
1919
i = 0;
2020
while (i < size)
2121
{
22-
if ((unsigned char *) s1 > (unsigned char *) s2)
22+
if (*((unsigned char *) s1 + i) > *((unsigned char *) s2 + i))
2323
return (1);
24-
if ((unsigned char *) s1 < (unsigned char *) s2)
24+
if (*((unsigned char *) s1 + i) < *((unsigned char *) s2 + i))
2525
return (-1);
2626
i++;
2727
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)