maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_strlcat.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_strlcat.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: rmikhayl <rmikhayl@student.42london.c +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/12/17 17:25:26 by rmikhayl #+# #+# */
9/* Updated: 2023/12/17 17:25:26 by rmikhayl ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "libft.h"
14
15/* *************************** ft_strlcat *********************************** */
16/* Combines two text strings, 'dst' and 'src', ensuring the result fits */
17/* within 'size' characters. Returns the length of the combined text. If */
18/* something's missing or 'size' is too small, undefined behavoiur. */
19/* */
20/* In layman's terms: It's like adding more words to an existing sentence, */
21/* making sure it doesn't get too long. If there's not enough space or */
22/* something is missing, it doesn't work right and doesn't give you the */
23/* correct result. */
24/* ************************************************************************** */
25
26size_t ft_strlcat(char *dst, const char *src, size_t size)
27{
28 char *d;
29 const char *s;
30 size_t len_dst;
31 size_t remaining_space;
32
33 len_dst = 0;
34 s = src;
35 d = dst;
36 while (size > 0 && *d != '\0')
37 {
38 d++;
39 size--;
40 len_dst++;
41 }
42 remaining_space = size;
43 if (remaining_space == 0)
44 return (len_dst + ft_strlen(src));
45 while (--remaining_space > 0 && *s != '\0')
46 *d++ = *s++;
47 *d = '\0';
48 return (len_dst + ft_strlen(src));
49}
size_t ft_strlcat(char *dst, const char *src, size_t size)
Definition ft_strlcat.c:26
size_t ft_strlen(const char *s)
Definition ft_strlen.c:15