aboutsummaryrefslogtreecommitdiffstats
path: root/libft/src/ft_memlchr.c
blob: 25319bc8bf8c57ed9f8d75beba8f8ddbaa35e76e (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_memlchr.c                                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: joelecle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:06:42 by joelecle          #+#    #+#             */
/*   Updated: 2020/02/14 17:06:42 by joelecle         ###   ########lyon.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);
}