Seluj78/Minishell

View on GitHub
libft/ft_memcmp.c

Summary

Maintainability
Test Coverage
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_memcmp.c                                        :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: jlasne <marvin@42.fr>                      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2016/11/03 13:14:19 by jlasne            #+#    #+#             */
/*   Updated: 2016/11/03 13:24:10 by jlasne           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "libft.h"

int        ft_memcmp(const void *s1, const void *s2, size_t n)
{
    int                i;
    unsigned char    *cs1;
    unsigned char    *cs2;

    i = 0;
    cs1 = (unsigned char *)s1;
    cs2 = (unsigned char *)s2;
    if (!n || !cs1 || !cs2)
        return (0);
    while (n--)
    {
        if (cs1[i] != cs2[i])
            return (cs1[i] - cs2[i]);
        i++;
    }
    return (0);
}
/*
** This compares strings and returns difference
*/