aboutsummaryrefslogtreecommitdiffstats
path: root/libft/src/ft_memlchr.c
blob: 11237436aeb135c541db43b3a0a758863d44be82 (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
/* ************************************************************************** */
/*                                                          LE - /            */
/*                                                              /             */
/*   ft_memlchr.c                                     .::    .:/ .      .::   */
/*                                                 +:+:+   +:    +:  +:+:+    */
/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */
/*                                                 #+#   #+    #+    #+#      */
/*   Created: 2019/12/11 16:50:58 by rbousset     #+#   ##    ##    #+#       */
/*   Updated: 2019/12/11 16:50:59 by rbousset    ###    #+. /#+    ###.fr     */
/*                                                         /                  */
/*                                                        /                   */
/* ************************************************************************** */

#include <libft.h>
#include <stddef.h>

long
	ft_memlchr(const void *s, int c, size_t n)
{
	const size_t len = ft_strlen((const char *)s);
	const size_t rem = ft_strlen((const char *)ft_memchr(s, c, n));

	if (len - rem >= ft_strlen((const char *)s))
		return (-1);
	return (len - rem);
}