aboutsummaryrefslogtreecommitdiffstats
path: root/libft/src/ft_strlchr.c
blob: 228aa89f18ad760fd3194c13562b11724cc7d699 (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_strlchr.c                                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:07:11 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/14 17:07:11 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

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

long
	ft_strlchr(const char *s, int c)
{
	const size_t	len = ft_strlen(s);
	const size_t	rem = ft_strlen(ft_strchr(s, c));

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