Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ft_putstr(char *str, int output)
- {
- while (*str)
- {
- write(output, str, 1);
- str++;
- }
- }
- int ft_strlen(char *str)
- {
- int count;
- count = 0;
- while (*str)
- {
- count++;
- str++;
- }
- return (count);
- }
- void ft_puterror(int err, char *filename, char *basename)
- {
- ft_putstr(basename, 2);
- ft_putstr(": ", 2);
- ft_putstr(filename, 2);
- ft_putstr(": ", 2);
- ft_putstr(strerror(err), 2);
- ft_putstr("\n", 2);
- }
- int ft_check_numbers(char *str)
- {
- while (*str)
- {
- if (!(*str >= '0' && *str <= '9'))
- return (0);
- str++;
- }
- return (1);
- }
- void ft_print_header(char *filename, int success)
- {
- if (success > 1)
- ft_putstr("\n", 1);
- ft_putstr("==> ", 1);
- ft_putstr(filename,
- char *ft_copy_and_concat(char *dest, char *buff, int size, int read)
- {
- char *cpy;
- int i;
- int j;
- cpy = dest;
- dest = malloc(sizeof(char) * (size + read));
- i = -1;
- while (++i < size)
- dest[i] = cpy[i];
- j = -1;
- while (++j < read)
- dest[i++] = buff[j];
- free(cpy);
- return (dest);
- }
- void ft_readstdin(int nb)
- {
- char buffer[BUFF_SIZE];
- int rd;
- char *dest;
- int total;
- total = 0;
- dest = NULL;
- while ((rd = read(0, buffer, BUFF_SIZE)) > 0)
- {
- total += rd;
- dest = ft_copy_and_concat(dest, buffer, total - rd, rd);
- }
- if (rd == -1)
- return ;
- write(1, dest + (total - nb < 0 ? 0 : total - nb), nb > total ? total : nb);
- free(dest);
- return ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement