xattr, ilen, uilen, etc
This commit is contained in:
parent
3280ed74b4
commit
d71c3f8b8a
18 changed files with 191 additions and 10 deletions
6
libft/includes/ftxattr.h
Normal file
6
libft/includes/ftxattr.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef FTXATTR_H
|
||||
# define FTXATTR_H
|
||||
# define FT_XATTR_SIZE 10000
|
||||
# include <sys/types.h>
|
||||
# include <sys/xattr.h>
|
||||
#endif
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
#ifndef LIBFT_H
|
||||
#define LIBFT_H
|
||||
#include "libftprintf.h"
|
||||
# include "ftprintf.h"
|
||||
# include "ftxattr.h"
|
||||
# include <string.h>
|
||||
# include <unistd.h>
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <time.h>
|
||||
# define FT_SEP(x) (x == ' ' || x == '\t' || x == '\n')
|
||||
# define FT_ABS(x) (((x) < 0) ? -(x) : (x))
|
||||
# define FT_NEG(x) (((x) < 0) ? 1 : 0)
|
||||
|
|
@ -110,4 +112,11 @@ char *ft_ulltoa_base(unsigned long long nbr, char *base);
|
|||
char *ft_uitoa_base(unsigned int nbr, char *base);
|
||||
|
||||
void ft_strlsort(char **list, int size, int (*cmp)());
|
||||
char *ft_convert_base(char *str, char *base_from, char *base_to, char *flags);
|
||||
size_t ft_ilen(int n);
|
||||
size_t ft_uilen(unsigned int n);
|
||||
|
||||
int ft_time_isrecent(time_t event);
|
||||
int ft_xattr_print(char *path);
|
||||
int ft_xattr_count(char *path);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "libftprintf.h"
|
||||
#include "ftprintf.h"
|
||||
|
||||
char *ft_signed_conversion(t_fmt *fmt, va_list ap)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "libftprintf.h"
|
||||
#include "ftprintf.h"
|
||||
|
||||
void ft_parse_flags(t_fmt *fmt, char **format)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "libftprintf.h"
|
||||
#include "ftprintf.h"
|
||||
|
||||
t_conv g_convs[] =
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "libftprintf.h"
|
||||
#include "ftprintf.h"
|
||||
|
||||
char *ft_transform(t_fmt *fmt, va_list ap)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "libftprintf.h"
|
||||
#include "ftprintf.h"
|
||||
|
||||
t_fmt *ft_fmt_init(void)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "libftprintf.h"
|
||||
#include "ftprintf.h"
|
||||
|
||||
void ft_fmt_error_conv(char conv)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "libftprintf.h"
|
||||
#include "ftprintf.h"
|
||||
|
||||
void ft_fmt_simplify(t_fmt *fmt)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "libftprintf.h"
|
||||
#include "ftprintf.h"
|
||||
|
||||
void ft_pad_right(char *str, t_fmt *fmt)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "libftprintf.h"
|
||||
#include "ftprintf.h"
|
||||
|
||||
void ft_pad_sharp_o(char *str)
|
||||
{
|
||||
|
|
|
|||
11
libft/src/math/ft_ilen.c
Normal file
11
libft/src/math/ft_ilen.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include "libft.h"
|
||||
|
||||
size_t ft_ilen(int n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 1;
|
||||
while (n /= 10)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
11
libft/src/math/ft_uilen.c
Normal file
11
libft/src/math/ft_uilen.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include "libft.h"
|
||||
|
||||
size_t ft_uilen(unsigned int n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 1;
|
||||
while (n /= 10)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
85
libft/src/str/ft_convert_base.c
Normal file
85
libft/src/str/ft_convert_base.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_convert_base.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/08/07 23:31:20 by jhalford #+# #+# */
|
||||
/* Updated: 2016/08/25 17:32:17 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int get_size(char *str)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
if (str[i] == '+' || str[i] == '-')
|
||||
return (0);
|
||||
if (str[i] < 32 || str[i] > 126)
|
||||
return (0);
|
||||
j = 0;
|
||||
while (j < i)
|
||||
{
|
||||
if (str[j] == str[i])
|
||||
return (0);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
static int get_pos(char c, char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (c != str[i] && str[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
static int ft_check_str(char *str, char *base, int base_size)
|
||||
{
|
||||
while (*str)
|
||||
{
|
||||
if (!(get_pos(*str, base) < base_size || *str == '-' || *str == '+'))
|
||||
return (0);
|
||||
str++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
char *ft_convert_base(char *str, char *base_from, char *base_to, char *flags)
|
||||
{
|
||||
int base_size;
|
||||
int res;
|
||||
int sign;
|
||||
|
||||
base_size = get_size(base_from);
|
||||
res = 0;
|
||||
sign = 1;
|
||||
if (!ft_check_str(str, base_from, base_size))
|
||||
return (ft_itoa_base(0, "0", flags));
|
||||
if (base_size > 1)
|
||||
{
|
||||
if (*str == '-' || *str == '+')
|
||||
{
|
||||
if (get_pos(*(str + 1), base_from) < base_size)
|
||||
sign = (*str == '+') ? 1 : -1;
|
||||
else
|
||||
return (ft_itoa_base(0, "0", flags));
|
||||
str++;
|
||||
}
|
||||
while (get_pos(*str, base_from) < base_size)
|
||||
res = res * base_size + sign * get_pos(*str++, base_from);
|
||||
}
|
||||
return (ft_itoa_base(res, base_to, flags));
|
||||
}
|
||||
12
libft/src/time/ft_time_isrecent.c
Normal file
12
libft/src/time/ft_time_isrecent.c
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include "libft.h"
|
||||
|
||||
int ft_time_isrecent(time_t event)
|
||||
{
|
||||
time_t now;
|
||||
|
||||
now = time(&now);
|
||||
if (now - event > 0 && now - event < 6*365/12*24*60*60)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
21
libft/src/xattr/ft_xattr_count.c
Normal file
21
libft/src/xattr/ft_xattr_count.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include "libft.h"
|
||||
|
||||
int ft_xattr_count(char *path)
|
||||
{
|
||||
ssize_t listlen;
|
||||
char list[FT_XATTR_SIZE];
|
||||
int i;
|
||||
int count;
|
||||
|
||||
i = 0;
|
||||
listlen = listxattr(path, list, FT_XATTR_SIZE, XATTR_NOFOLLOW);
|
||||
if (listlen == -1)
|
||||
return (-1);
|
||||
count = 0;
|
||||
while (i < listlen)
|
||||
{
|
||||
i += ft_strlen(list) + 1;
|
||||
count++;
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
26
libft/src/xattr/ft_xattr_print.c
Normal file
26
libft/src/xattr/ft_xattr_print.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include "libft.h"
|
||||
|
||||
int ft_xattr_print(char *path)
|
||||
{
|
||||
ssize_t listlen;
|
||||
ssize_t valuelen;
|
||||
char list[FT_XATTR_SIZE];
|
||||
char value[FT_XATTR_SIZE];
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
listlen = listxattr(path, list, FT_XATTR_SIZE, XATTR_NOFOLLOW);
|
||||
if (listlen == -1)
|
||||
return (1);
|
||||
while (i < listlen)
|
||||
{
|
||||
valuelen = getxattr(path, list + i, value,
|
||||
FT_XATTR_SIZE, 0, XATTR_NOFOLLOW);
|
||||
if (valuelen == -1)
|
||||
ft_printf("couldn't get value\n");
|
||||
else
|
||||
printf("%s:\n%s\n", list + i, value);
|
||||
i += ft_strlen(list) + 1;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
Loading…
Reference in a new issue