libupdate

This commit is contained in:
djonker 2023-03-07 04:33:27 +01:00
parent 5da295673c
commit ffee823f3e
3 changed files with 21 additions and 21 deletions

View File

@ -33,10 +33,10 @@ int findnewline(struct s_gnl *strct);
int newline(struct s_gnl *strct, char **line); int newline(struct s_gnl *strct, char **line);
int blimit(int l, struct s_gnl *strct, char **line, char *t);; int blimit(int l, struct s_gnl *strct, char **line, char *t);;
int nonewline(int l, struct s_gnl *strct, char **line); int nonewline(int l, struct s_gnl *strct, char **line);
char *ft_substr(char const *s, unsigned int start, size_t len); char *gnl_substr(char const *s, unsigned int start, size_t len);
void *ft_memcpy(void *dst, const void *src, size_t n); void *gnl_memcpy(void *dst, const void *src, size_t n);
size_t ft_strlen(char *str); size_t gnl_strlen(char *str);
void ft_bzero(void *s, size_t n); void gnl_bzero(void *s, size_t n);
char *ft_strjoin(char const *s1, char const *s2); char *gnl_strjoin(char const *s1, char const *s2);
#endif #endif

View File

@ -32,17 +32,17 @@ int newline(struct s_gnl *strct, char **line)
char *t; char *t;
l = findnewline(strct); l = findnewline(strct);
line[0] = ft_substr((const char *)strct->b, 0, l - 1); line[0] = gnl_substr((const char *)strct->b, 0, l - 1);
if (line[0] == NULL) if (line[0] == NULL)
return (-1); return (-1);
t = ft_substr((const char *)strct->b, l, BUFFER_SIZE - l); t = gnl_substr((const char *)strct->b, l, BUFFER_SIZE - l);
if (t == NULL) if (t == NULL)
{ {
free(line[0]); free(line[0]);
return (-1); return (-1);
} }
ft_memcpy(strct->b, t, ft_strlen(t)); gnl_memcpy(strct->b, t, gnl_strlen(t));
ft_bzero(&strct->b[ft_strlen(t)], BUFFER_SIZE - ft_strlen(t)); gnl_bzero(&strct->b[gnl_strlen(t)], BUFFER_SIZE - gnl_strlen(t));
free(t); free(t);
return (1); return (1);
} }
@ -55,7 +55,7 @@ int blimit(int l, struct s_gnl *strct, char **line, char *t)
if (l == 1 || l == 0) if (l == 1 || l == 0)
{ {
f = line[0]; f = line[0];
line[0] = ft_strjoin(t, line[0]); line[0] = gnl_strjoin(t, line[0]);
free (f); free (f);
} }
free(t); free(t);
@ -68,8 +68,8 @@ int nonewline(int l, struct s_gnl *strct, char **line)
{ {
char *t; char *t;
t = ft_substr((const char *)strct->b, 0, ft_strlen(strct->b)); t = gnl_substr((const char *)strct->b, 0, gnl_strlen(strct->b));
ft_bzero(&strct->b[0], BUFFER_SIZE); gnl_bzero(&strct->b[0], BUFFER_SIZE);
l = read(strct->fd, strct->b, BUFFER_SIZE); l = read(strct->fd, strct->b, BUFFER_SIZE);
if (l == -1 || t == NULL) if (l == -1 || t == NULL)
{ {
@ -78,8 +78,8 @@ int nonewline(int l, struct s_gnl *strct, char **line)
} }
if (l == BUFFER_SIZE || findnewline(strct) > -1) if (l == BUFFER_SIZE || findnewline(strct) > -1)
return (blimit(l, strct, line, t)); return (blimit(l, strct, line, t));
line[0] = ft_strjoin(t, strct->b); line[0] = gnl_strjoin(t, strct->b);
ft_bzero(&strct->b, BUFFER_SIZE); gnl_bzero(&strct->b, BUFFER_SIZE);
free(t); free(t);
if (line[0] == NULL) if (line[0] == NULL)
return (-1); return (-1);

View File

@ -12,7 +12,7 @@
#include "../get_next_line.h" #include "../get_next_line.h"
size_t ft_strlen(char *str) size_t gnl_strlen(char *str)
{ {
size_t a; size_t a;
@ -25,7 +25,7 @@ size_t ft_strlen(char *str)
return (a); return (a);
} }
void ft_bzero(void *s, size_t n) void gnl_bzero(void *s, size_t n)
{ {
char *p; char *p;
@ -38,7 +38,7 @@ void ft_bzero(void *s, size_t n)
} }
} }
void *ft_memcpy(void *dst, const void *src, size_t n) void *gnl_memcpy(void *dst, const void *src, size_t n)
{ {
char *d; char *d;
const char *s; const char *s;
@ -55,7 +55,7 @@ void *ft_memcpy(void *dst, const void *src, size_t n)
return (dst); return (dst);
} }
char *ft_strjoin(char const *s1, char const *s2) char *gnl_strjoin(char const *s1, char const *s2)
{ {
int c1; int c1;
int c2; int c2;
@ -65,8 +65,8 @@ char *ft_strjoin(char const *s1, char const *s2)
c1 = 0; c1 = 0;
c2 = 0; c2 = 0;
l1 = ft_strlen((char *)s1); l1 = gnl_strlen((char *)s1);
l2 = ft_strlen((char *)s2); l2 = gnl_strlen((char *)s2);
r = malloc(l1 + l2 + 1); r = malloc(l1 + l2 + 1);
if (r == NULL) if (r == NULL)
return (r); return (r);
@ -84,7 +84,7 @@ char *ft_strjoin(char const *s1, char const *s2)
return (r); return (r);
} }
char *ft_substr(char const *s, unsigned int start, size_t len) char *gnl_substr(char const *s, unsigned int start, size_t len)
{ {
char *r; char *r;
long unsigned int i; long unsigned int i;