some new functions, sstr and str

This commit is contained in:
Jack Halford 2016-10-14 21:13:10 +02:00
parent 6e45d91e6b
commit 580ef2c432
9 changed files with 76 additions and 17 deletions

View file

@ -3,4 +3,7 @@
# define FT_XATTR_SIZE 10000 # define FT_XATTR_SIZE 10000
# include <sys/types.h> # include <sys/types.h>
# include <sys/xattr.h> # include <sys/xattr.h>
int ft_xattr_print(char *path);
int ft_xattr_count(char *path);
#endif #endif

View file

@ -1,13 +1,16 @@
#ifndef LIBFT_H #ifndef LIBFT_H
#define LIBFT_H #define LIBFT_H
# include "ftprintf.h" # include "ftprintf.h"
# include "ftxattr.h" # include "ftxattr.h"
# include "getnextline.h" # include "getnextline.h"
# include <string.h> # include <string.h>
# include <unistd.h> # include <unistd.h>
# include <stdio.h> # include <stdio.h>
# include <stdlib.h> # include <stdlib.h>
# include <time.h> # include <time.h>
# define FT_SEP(x) (x == ' ' || x == '\t' || x == '\n') # define FT_SEP(x) (x == ' ' || x == '\t' || x == '\n')
# define FT_ABS(x) (((x) < 0) ? -(x) : (x)) # define FT_ABS(x) (((x) < 0) ? -(x) : (x))
# define FT_NEG(x) (((x) < 0) ? 1 : 0) # define FT_NEG(x) (((x) < 0) ? 1 : 0)
@ -109,6 +112,7 @@ t_list *ft_id(t_list *a);
char *ft_strrev(char *str); char *ft_strrev(char *str);
char **ft_strsplit(char const *s, char c); char **ft_strsplit(char const *s, char c);
char *ft_str3join(char const *s1, char const *s2, char const *s3);
char **ft_split_whitespaces(char *str); char **ft_split_whitespaces(char *str);
char *ft_convert_base(char *str, char *base_from, char *base_to, char *flags); char *ft_convert_base(char *str, char *base_from, char *base_to, char *flags);
@ -119,13 +123,12 @@ char *ft_uitoa_base(unsigned int nbr, char *base);
size_t ft_ilen(int n); size_t ft_ilen(int n);
size_t ft_uilen(unsigned int n); size_t ft_uilen(unsigned int n);
void ft_strlsort(char **list, int size, int (*cmp)()); void ft_sstrsort(char **list, int size, int (*cmp)());
void ft_strlprint(char **strl, char sep); void ft_sstrprint(char **list, char sep);
char **ft_sstrdup(char **list);
char **ft_sstradd(char **list, char *new);
int ft_time_isrecent(time_t event); int ft_time_isrecent(time_t event);
int ft_xattr_print(char *path);
int ft_xattr_count(char *path);
char *ft_path_notdir(char *path); char *ft_path_notdir(char *path);
#endif #endif

View file

@ -0,0 +1,19 @@
#include "libft.h"
char **ft_sstradd(char **sstr, char *new)
{
int i;
int size;
char **newlist;
i = 0;
size = 0;
while (sstr && sstr[size])
size++;
newlist = (char **)malloc(sizeof(char *) * (size + 3));
while (sstr && *sstr)
newlist[i++] = *sstr++;
newlist[i++] = new;
newlist[i] = NULL;
return (newlist);
}

View file

@ -0,0 +1,20 @@
#include "libft.h"
char **ft_sstrdup(char **list)
{
int i;
int size;
char **cpy;
i = 0;
size = 0;
while (list[size])
size++;
cpy = (char **)malloc(sizeof(char *) * (size + 1));
while (*list)
{
cpy[i++] = ft_strdup(*list);
list++;
}
return (cpy);
}

View file

@ -0,0 +1,10 @@
#include "libft.h"
void ft_sstrprint(char **list, char sep)
{
int i;
i = 0;
while (list[i])
ft_printf("%s%c", list[i++], sep);
}

View file

@ -1,6 +1,6 @@
#include "libft.h" #include "libft.h"
void ft_strlsort(char **list, int size, int (*cmp)()) void ft_sstrsort(char **list, int size, int (*cmp)())
{ {
int i; int i;
char *tmp; char *tmp;

View file

@ -0,0 +1,14 @@
#include "libft.h"
char *ft_str3join(char const *s1, char const *s2, char const *s3)
{
char *join;
int size;
size = ft_strlen(s1) + ft_strlen(s2) + ft_strlen(s3);
join = ft_strnew(size + 1);
ft_strcpy(join, s1);
ft_strcat(join, s2);
ft_strcat(join, s3);
return (join);
}

View file

@ -19,7 +19,7 @@ char *ft_strcat(char *s1, const char *s2)
size = ft_strlen(s1); size = ft_strlen(s1);
j = 0; j = 0;
while (s2[j] != '\0') while (s2 && s2[j] != '\0')
{ {
s1[size + j] = s2[j]; s1[size + j] = s2[j];
j++; j++;

View file

@ -1,10 +0,0 @@
#include "libft.h"
void ft_strlprint(char **strl, char sep)
{
int i;
i = 0;
while (strl[i])
ft_printf("%s%c", strl[i], sep);
}