summaryrefslogtreecommitdiff
path: root/libft/ft_memcmp.c
blob: 442d3d01ca4534f6e8309c87215897ac9535c1dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_memcmp.c                                        :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: kdx    <kdx   @student.42angouleme.fr      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/09/28 05:37:18 by kdx               #+#    #+#             */
/*   Updated: 2022/10/13 22:32:42 by kdx              ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "libft.h"
#include <stdint.h>

int	ft_memcmp(const void *s1, const void *s2, size_t n)
{
	const uint8_t	*data_1;
	const uint8_t	*data_2;
	size_t			i;

	if (n == 0)
		return (0);
	data_1 = s1;
	data_2 = s2;
	i = 0;
	while (i + 1 < n)
	{
		if (data_1[i] != data_2[i])
			return (data_1[i] - data_2[i]);
		i += 1;
	}
	return (data_1[i] - data_2[i]);
}