From 3bf0fbd3cd4a25877d5c0db9c46d0eee4a72d506 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 15 Jun 2017 09:48:40 +0200 Subject: [PATCH] removed many sys/ stuff because the design was bad and doesnt compile easily on linux! --- libftasm/Makefile | 14 ++---- libftasm/includes/libft.h | 16 +++---- libftasm/includes/sys.h | 20 ++++---- libftasm/srcs/net/net_get.c | 15 ++++++ libftasm/srcs/net/net_get_fd.c | 16 ------- libftasm/srcs/printing/ft_putchar.c | 6 +-- libftasm/srcs/printing/ft_putendl.c | 12 +++-- libftasm/srcs/printing/ft_putnbr.c | 20 ++++---- libftasm/srcs/printing/ft_putstr.c | 8 ++-- libftasm/srcs/sys/create_directory.c | 36 --------------- libftasm/srcs/sys/dup2_close.c | 22 --------- libftasm/srcs/sys/fd_replace.c | 20 -------- libftasm/srcs/sys/ft_getenv.c | 27 ----------- libftasm/srcs/sys/ft_xattr_count.c | 61 ------------------------ libftasm/srcs/sys/ft_xattr_print.c | 69 ---------------------------- libftasm/srcs/sys/is_directory.c | 21 --------- libftasm/srcs/sys/open_access.c | 30 ------------ 17 files changed, 60 insertions(+), 353 deletions(-) delete mode 100644 libftasm/srcs/net/net_get_fd.c delete mode 100644 libftasm/srcs/sys/create_directory.c delete mode 100644 libftasm/srcs/sys/dup2_close.c delete mode 100644 libftasm/srcs/sys/fd_replace.c delete mode 100644 libftasm/srcs/sys/ft_getenv.c delete mode 100644 libftasm/srcs/sys/ft_xattr_count.c delete mode 100644 libftasm/srcs/sys/ft_xattr_print.c delete mode 100644 libftasm/srcs/sys/is_directory.c delete mode 100644 libftasm/srcs/sys/open_access.c diff --git a/libftasm/Makefile b/libftasm/Makefile index 3e8c47af..c4f01753 100644 --- a/libftasm/Makefile +++ b/libftasm/Makefile @@ -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) diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index 7e2bd5ed..d65698f6 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -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); diff --git a/libftasm/includes/sys.h b/libftasm/includes/sys.h index 93edda19..326e37b3 100644 --- a/libftasm/includes/sys.h +++ b/libftasm/includes/sys.h @@ -24,21 +24,23 @@ # include # include -# include +/* # if HAVE_SYS_ACL_H */ +/* # include */ +/* # endif */ # include # include -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 diff --git a/libftasm/srcs/net/net_get.c b/libftasm/srcs/net/net_get.c index 5be9fc5d..e09418c1 100644 --- a/libftasm/srcs/net/net_get.c +++ b/libftasm/srcs/net/net_get.c @@ -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); +} diff --git a/libftasm/srcs/net/net_get_fd.c b/libftasm/srcs/net/net_get_fd.c deleted file mode 100644 index ca3e4750..00000000 --- a/libftasm/srcs/net/net_get_fd.c +++ /dev/null @@ -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); -} diff --git a/libftasm/srcs/printing/ft_putchar.c b/libftasm/srcs/printing/ft_putchar.c index 400ebaaa..b607cf9a 100644 --- a/libftasm/srcs/printing/ft_putchar.c +++ b/libftasm/srcs/printing/ft_putchar.c @@ -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)); } diff --git a/libftasm/srcs/printing/ft_putendl.c b/libftasm/srcs/printing/ft_putendl.c index f54881d8..615c929f 100644 --- a/libftasm/srcs/printing/ft_putendl.c +++ b/libftasm/srcs/printing/ft_putendl.c @@ -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)); } diff --git a/libftasm/srcs/printing/ft_putnbr.c b/libftasm/srcs/printing/ft_putnbr.c index 6d46a4de..e0850ba8 100644 --- a/libftasm/srcs/printing/ft_putnbr.c +++ b/libftasm/srcs/printing/ft_putnbr.c @@ -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)); } diff --git a/libftasm/srcs/printing/ft_putstr.c b/libftasm/srcs/printing/ft_putstr.c index d937668e..985f1a99 100644 --- a/libftasm/srcs/printing/ft_putstr.c +++ b/libftasm/srcs/printing/ft_putstr.c @@ -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))); } diff --git a/libftasm/srcs/sys/create_directory.c b/libftasm/srcs/sys/create_directory.c deleted file mode 100644 index 6a8967ca..00000000 --- a/libftasm/srcs/sys/create_directory.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* create_directory.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libftasm/srcs/sys/dup2_close.c b/libftasm/srcs/sys/dup2_close.c deleted file mode 100644 index c1c10bcd..00000000 --- a/libftasm/srcs/sys/dup2_close.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* dup2_close.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libftasm/srcs/sys/fd_replace.c b/libftasm/srcs/sys/fd_replace.c deleted file mode 100644 index 495ae484..00000000 --- a/libftasm/srcs/sys/fd_replace.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* fd_replace.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libftasm/srcs/sys/ft_getenv.c b/libftasm/srcs/sys/ft_getenv.c deleted file mode 100644 index 83cebdaa..00000000 --- a/libftasm/srcs/sys/ft_getenv.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_getenv.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libftasm/srcs/sys/ft_xattr_count.c b/libftasm/srcs/sys/ft_xattr_count.c deleted file mode 100644 index 62b274f7..00000000 --- a/libftasm/srcs/sys/ft_xattr_count.c +++ /dev/null @@ -1,61 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_xattr_count.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/libftasm/srcs/sys/ft_xattr_print.c b/libftasm/srcs/sys/ft_xattr_print.c deleted file mode 100644 index e4d7e1a7..00000000 --- a/libftasm/srcs/sys/ft_xattr_print.c +++ /dev/null @@ -1,69 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_xattr_print.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/libftasm/srcs/sys/is_directory.c b/libftasm/srcs/sys/is_directory.c deleted file mode 100644 index accd92a4..00000000 --- a/libftasm/srcs/sys/is_directory.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* is_directory.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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)); -} diff --git a/libftasm/srcs/sys/open_access.c b/libftasm/srcs/sys/open_access.c deleted file mode 100644 index 40811fe7..00000000 --- a/libftasm/srcs/sys/open_access.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* open_access.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -}