35 lines
1.3 KiB
C
35 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strncmp.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/05/22 16:29:43 by tosuman #+# #+# */
|
|
/* Updated: 2023/06/02 19:59:48 by tischmid ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
|
|
int ft_strncmp(char const *s1, char const *s2, size_t n)
|
|
{
|
|
unsigned char *us1;
|
|
unsigned char *us2;
|
|
|
|
if (!n)
|
|
return (0);
|
|
us1 = (unsigned char *) s1;
|
|
us2 = (unsigned char *) s2;
|
|
while (*us1 && *us2 && *us1 == *us2 && --n)
|
|
{
|
|
us1++;
|
|
us2++;
|
|
}
|
|
if (*us1 != *us2)
|
|
return ((*us1 - *us2 != 0)
|
|
* (-2 * (*us1 - *us2 < 0) + 1));
|
|
return (0);
|
|
}
|