removed many sys/ stuff because the design was bad and doesnt compile easily on linux!
This commit is contained in:
parent
4ca02be6eb
commit
3bf0fbd3cd
17 changed files with 60 additions and 353 deletions
|
|
@ -131,7 +131,6 @@ mem/ft_realloc.c\
|
|||
net/create_client.c\
|
||||
net/create_server.c\
|
||||
net/net_get.c\
|
||||
net/net_get_fd.c\
|
||||
net/net_send.c\
|
||||
path/ft_path_notdir.c\
|
||||
printing/ft_putchar.c\
|
||||
|
|
@ -193,23 +192,16 @@ str/ft_strstr.c\
|
|||
str/ft_strsub.c\
|
||||
str/ft_strtok.c\
|
||||
str/ft_strtrim.c\
|
||||
sys/create_directory.c\
|
||||
sys/dup2_close.c\
|
||||
sys/fd_replace.c\
|
||||
sys/ft_getenv.c\
|
||||
sys/ft_xattr_count.c\
|
||||
sys/ft_xattr_print.c\
|
||||
sys/is_directory.c\
|
||||
sys/open_access.c\
|
||||
sys/open_new.c\
|
||||
time/ft_mytime_free.c\
|
||||
time/ft_mytime_get.c\
|
||||
time/ft_time_isrecent.c
|
||||
time/ft_time_isrecent.c\
|
||||
sys/open_new.c
|
||||
|
||||
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
||||
NB = $(words $(SRC_BASE))
|
||||
INDEX = 0
|
||||
SHELL := bash
|
||||
|
||||
all :
|
||||
@$(MAKE) -j $(NAME)
|
||||
|
|
|
|||
|
|
@ -73,18 +73,18 @@ void *ft_memalloc(size_t size);
|
|||
void ft_memdel(void **ap);
|
||||
|
||||
int ft_putchar(int c);
|
||||
void ft_putstr(char const *s);
|
||||
void ft_putendl(char const *s);
|
||||
void ft_putnbr(long n);
|
||||
void ft_putnbr_hex(long n);
|
||||
int ft_putstr(char const *s);
|
||||
int ft_putendl(char const *s);
|
||||
int ft_putnbr(long n);
|
||||
int ft_putnbr_hex(long n);
|
||||
|
||||
int ft_error_message(char *message);
|
||||
|
||||
int ft_putchar_fd(int c, int fd);
|
||||
void ft_putstr_fd(char const *s, int fd);
|
||||
void ft_putendl_fd(char const *s, int fd);
|
||||
void ft_putnbr_fd(long n, int fd);
|
||||
void ft_putnbr_hex_fd(long n, int fd);
|
||||
int ft_putstr_fd(char const *s, int fd);
|
||||
int ft_putendl_fd(char const *s, int fd);
|
||||
int ft_putnbr_fd(long n, int fd);
|
||||
int ft_putnbr_hex_fd(long n, int fd);
|
||||
|
||||
void *ft_realloc(void *data, int size);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,21 +24,23 @@
|
|||
|
||||
# include <sys/types.h>
|
||||
# include <sys/xattr.h>
|
||||
# include <sys/acl.h>
|
||||
/* # if HAVE_SYS_ACL_H */
|
||||
/* # include <sys/acl.h> */
|
||||
/* # endif */
|
||||
# include <sys/stat.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
int ft_xattr_print(char *path);
|
||||
int ft_xattr_count(char *path);
|
||||
/* int ft_xattr_print(char *path); */
|
||||
/* int ft_xattr_count(char *path); */
|
||||
|
||||
char *ft_getenv(char **env, char *key);
|
||||
/* char *ft_getenv(char **env, char *key); */
|
||||
|
||||
int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm);
|
||||
/* int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm); */
|
||||
int open_new(char *filename, int oflag);
|
||||
int is_directory(const char *path);
|
||||
char *create_directory(const char *path, const char *old_pathnames);
|
||||
/* int is_directory(const char *path); */
|
||||
/* char *create_directory(const char *path, const char *old_pathnames); */
|
||||
|
||||
int dup2_close(int fd1, int fd2);
|
||||
int fd_replace(int fd1, int fd2);
|
||||
/* int dup2_close(int fd1, int fd2); */
|
||||
/* int fd_replace(int fd1, int fd2); */
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -11,3 +11,18 @@ int net_get(int sock, char *msg, int size)
|
|||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int net_get_fd(int sock, int fd, int size)
|
||||
{
|
||||
int ack;
|
||||
char msg[size];
|
||||
|
||||
ack = htons(ACK);
|
||||
if (read(sock, msg, size) < 0)
|
||||
return (-1);
|
||||
if (write(sock, (char*)&ack, sizeof(ack)) < 0)
|
||||
return (-1);
|
||||
if (write(fd, msg, size) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
#include "libft.h"
|
||||
|
||||
int net_get_fd(int sock, int fd, int size)
|
||||
{
|
||||
int ack;
|
||||
char msg[size];
|
||||
|
||||
ack = htons(ACK);
|
||||
if (read(sock, msg, size) < 0)
|
||||
return (-1);
|
||||
if (write(sock, (char*)&ack, sizeof(ack)) < 0)
|
||||
return (-1);
|
||||
if (write(fd, msg, size) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -14,12 +14,10 @@
|
|||
|
||||
int ft_putchar_fd(int c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
return (0);
|
||||
return (write(fd, &c, 1));
|
||||
}
|
||||
|
||||
int ft_putchar(int c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
return (0);
|
||||
return (write(1, &c, 1));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,16 +12,18 @@
|
|||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char const *s, int fd)
|
||||
int ft_putendl_fd(char const *s, int fd)
|
||||
{
|
||||
char nl;
|
||||
int ret;
|
||||
|
||||
nl = '\n';
|
||||
write(fd, s, ft_strlen(s));
|
||||
write(fd, &nl, 1);
|
||||
if ((ret = write(fd, s, ft_strlen(s))))
|
||||
return (ret);
|
||||
return (write(fd, &nl, 1));
|
||||
}
|
||||
|
||||
void ft_putendl(char const *s)
|
||||
int ft_putendl(char const *s)
|
||||
{
|
||||
ft_putendl_fd(s, 1);
|
||||
return (ft_putendl_fd(s, 1));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,33 +12,33 @@
|
|||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr_loop(long n, int base, int fd)
|
||||
int ft_putnbr_loop(long n, int base, int fd)
|
||||
{
|
||||
if (n >= base)
|
||||
ft_putnbr_loop(n / base, base, fd);
|
||||
ft_putchar_fd("0123456789abcdef"[n % base], fd);
|
||||
return (ft_putchar_fd("0123456789abcdef"[n % base], fd));
|
||||
}
|
||||
|
||||
void ft_putnbr_hex_fd(long n, int fd)
|
||||
int ft_putnbr_hex_fd(long n, int fd)
|
||||
{
|
||||
ft_putstr_fd("0x", fd);
|
||||
ft_putnbr_loop(n, 16, fd);
|
||||
return (ft_putnbr_loop(n, 16, fd));
|
||||
}
|
||||
|
||||
void ft_putnbr_fd(long n, int fd)
|
||||
int ft_putnbr_fd(long n, int fd)
|
||||
{
|
||||
if (n < 0)
|
||||
ft_putchar_fd('-', fd);
|
||||
n = FT_ABS(n);
|
||||
ft_putnbr_loop(n, 10, fd);
|
||||
return (ft_putnbr_loop(n, 10, fd));
|
||||
}
|
||||
|
||||
void ft_putnbr_hex(long n)
|
||||
int ft_putnbr_hex(long n)
|
||||
{
|
||||
ft_putnbr_hex_fd(n, 1);
|
||||
return (ft_putnbr_hex_fd(n, 1));
|
||||
}
|
||||
|
||||
void ft_putnbr(long n)
|
||||
int ft_putnbr(long n)
|
||||
{
|
||||
ft_putnbr_fd(n, 1);
|
||||
return (ft_putnbr_fd(n, 1));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@
|
|||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char const *s, int fd)
|
||||
int ft_putstr_fd(char const *s, int fd)
|
||||
{
|
||||
write(fd, s, ft_strlen(s));
|
||||
return (write(fd, s, ft_strlen(s)));
|
||||
}
|
||||
|
||||
void ft_putstr(char const *s)
|
||||
int ft_putstr(char const *s)
|
||||
{
|
||||
write(1, s, ft_strlen(s));
|
||||
return (write(1, s, ft_strlen(s)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* create_directory.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/25 03:18:18 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/25 15:12:34 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *create_directory(const char *path, const char *old_pathnames)
|
||||
{
|
||||
char *new_pathnames;
|
||||
char *newdir;
|
||||
char *temp;
|
||||
char *semi;
|
||||
|
||||
new_pathnames = ft_strdup(old_pathnames);
|
||||
temp = new_pathnames;
|
||||
while (new_pathnames)
|
||||
{
|
||||
if ((semi = ft_strchr(new_pathnames, ':')))
|
||||
*semi = 0;
|
||||
if (!is_directory(newdir = ft_str3join(new_pathnames, "/", path)))
|
||||
ft_strdel(&newdir);
|
||||
else
|
||||
break ;
|
||||
new_pathnames += ft_strlen(new_pathnames) + 1;
|
||||
}
|
||||
ft_strdel(&temp);
|
||||
return (newdir);
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dup2_close.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/07 16:07:28 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/24 19:33:48 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int dup2_close(int fd1, int fd2)
|
||||
{
|
||||
if (dup2(fd1, fd2) < 0)
|
||||
return (-1);
|
||||
if (close(fd1) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fd_replace.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/21 16:32:26 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/24 22:59:28 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int fd_replace(int fd1, int fd2)
|
||||
{
|
||||
if (fd1 != fd2)
|
||||
return (dup2_close(fd1, fd2));
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_getenv.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/18 03:09:57 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_getenv(char **env, char *key)
|
||||
{
|
||||
if (!env)
|
||||
return (NULL);
|
||||
while (*env)
|
||||
{
|
||||
if (ft_strcmp(*env, key) == '='
|
||||
&& ft_strlen(key) == ft_strlenchr(*env, '='))
|
||||
return (*env + ft_strlen(key) + 1);
|
||||
env++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_xattr_count.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 18:00:52 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 16:48:29 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
#if defined __APPLE__
|
||||
|
||||
int ft_xattr_count(char *path)
|
||||
{
|
||||
ssize_t listlen;
|
||||
char list[FT_XATTR_SIZE];
|
||||
int i;
|
||||
int count;
|
||||
|
||||
i = 0;
|
||||
ft_bzero(list, FT_XATTR_SIZE);
|
||||
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);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int ft_xattr_count(char *path)
|
||||
{
|
||||
ssize_t listlen;
|
||||
char list[FT_XATTR_SIZE];
|
||||
int i;
|
||||
int count;
|
||||
|
||||
i = 0;
|
||||
ft_bzero(list, FT_XATTR_SIZE);
|
||||
listlen = listxattr(path, list, FT_XATTR_SIZE);
|
||||
if (listlen == -1)
|
||||
return (-1);
|
||||
count = 0;
|
||||
while (i < listlen)
|
||||
{
|
||||
i += ft_strlen(list) + 1;
|
||||
count++;
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_xattr_print.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/03 18:00:43 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 16:48:20 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
#if defined __APPLE__
|
||||
|
||||
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
|
||||
ft_printf("%s:\n%s\n", list + i, value);
|
||||
i += ft_strlen(list) + 1;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
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);
|
||||
if (listlen == -1)
|
||||
return (1);
|
||||
while (i < listlen)
|
||||
{
|
||||
valuelen = getxattr(path, list + i, value,
|
||||
FT_XATTR_SIZE);
|
||||
if (valuelen == -1)
|
||||
ft_printf("couldn't get value\n");
|
||||
else
|
||||
ft_printf("%s:\n%s\n", list + i, value);
|
||||
i += ft_strlen(list) + 1;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* is_directory.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/25 01:40:31 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/25 01:42:02 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int is_directory(const char *path)
|
||||
{
|
||||
struct stat path_stat;
|
||||
|
||||
stat(path, &path_stat);
|
||||
return (S_ISDIR(path_stat.st_mode));
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* open_access.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/25 01:10:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/25 15:07:42 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (a_flag & F_OK && access(file, F_OK) != 0)
|
||||
return (-ERR_SET(E_SYS_NOFILE, file));
|
||||
if (is_directory(file))
|
||||
return (-ERR_SET(E_SYS_ISDIR, file));
|
||||
if (access(file, F_OK) == 0 && access(file, a_flag) != 0)
|
||||
return (-ERR_SET(E_SYS_NOPERM, file));
|
||||
if ((fd = open(file, o_flag, o_perm)) < 0)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
return (fd);
|
||||
}
|
||||
Loading…
Reference in a new issue