<repo_name>juanmarcoscabezas/simple_shell<file_sep>/get_commands.c
#include "shell.h"

/**
 * get_commands - Gets the commands
 * Description: This function gets commands & break them in tokens
 * @argv: arguments passed to the shell
 * @cmds: commands passed to the shell
 * @envp: enviroment variables passed to the shell
 * @n_cmds: the number of commands given until this point.
 * @lo: Last output from a command
 * Return: Always 0
 */
int get_commands(char *argv[], char *cmds, char *envp[], int *n_cmds, int *lo)
{
	char *token;
	char **tokens;
	int pos = 0;
	int execute;

	tokens = malloc(sizeof(char *) * 64);

	if (!tokens)
	{
		perror("Error on allocation");
		exit(0);
	}
	token = strtok(cmds, " \t\r\n\a");

	while (token)
	{
		tokens[pos] = token;
		pos++;
		token = strtok(NULL, " \t\r\n\a");
	}
	tokens[pos] = NULL;
	execute = exec_cmds(argv, tokens, envp, n_cmds, lo);
	free(tokens);
	return (execute);
}
<file_sep>/execute_commands.c
#include "shell.h"

/**
 * print_parameters - Function to print parameters becouse of betty
 * Description: Function to print parameters becouse of betty
 * @argv_param: Name of file
 * @n_com: Number of commands inserted
 * @com_cpy: Command that was executed
 * @errnd: Error end of the message
 * Return:
 */
void print_parameters(char *argv_param, int *n_com, char *com_cpy, char *errnd)
{
	_puts(argv_param);
	_puts(": ");
	print_number(n_com);
	_puts(": ");
	_puts(com_cpy);
	_puts(errnd);
}

/**
 * check_directory - Function that checks if the path is a directory
 * @filename: path to check
 * @n_com: number of commands
 * @token: token to find
 * Return: 126 if filename is a directory, 0 otherwise
 */
int check_directory(char *filename, int *n_com, char *token)
{
	struct stat st;

	st.st_mode = 0;
	stat(token, &st);
	if ((st.st_mode & S_IFMT) == S_IFDIR)
	{
		print_parameters(filename, n_com, token, ": Permission denied\n");
		(*n_com)++;
		return (126);
	}
	if (access(token, X_OK) == -1 && token[0] == '.' && token[1] == '/')
	{
		print_parameters(filename, n_com, token, ": Permission denied\n");
		(*n_com)++;
		return (126);
	}
	return (0);
}

/**
 * exec_cmds -  Execute commands
 * Description: Function that execute commands
 * @argv: arguments passed to the shell
 * @tokens: Options tokenized from a command
 * @envp: enviroment variables passed to the shell
 * @n_com: the number of commands given until this point.
 * @lo: last output from a command
 * Return: 1
 */
int exec_cmds(char *argv[], char *tokens[], char *envp[], int *n_com, int *lo)
{
	int status, is_accessible, built_in_result;
	pid_t pid;
	char *path = NULL, *com_cpy;

	/* Check built-in functions */
	built_in_result = built_in(argv, tokens, envp, n_com, lo);
	if (built_in_result != 1)
		return (built_in_result);
	/* Check if the file exists */
	if (check_directory(argv[0], n_com, tokens[0]) != 0)
		return (126);
	is_accessible = access(tokens[0], F_OK | X_OK | R_OK);
	/* If not accessible try to find in PATH */
	if (is_accessible == -1)
	{path = _getenv(envp, "PATH");
		com_cpy = tokens[0];
		tokens[0] = check_access(path, tokens[0]);
		if (tokens[0] == NULL)
		{
			print_parameters(argv[0], n_com, com_cpy, ": not found\n");
			(*n_com)++;
			if (path)
				free(path);
			return (127);
		}
	}
	if (path && is_accessible == -1)
		free(path);
	(*n_com)++;
	pid = fork();
	if (pid == 0)
	{
		execve(tokens[0], tokens, envp);
		exit(0);
	}
	else
		wait(&status);
	if (is_accessible == -1)
		free(tokens[0]);
	return (0);
}
<file_sep>/check_access.c
#include "shell.h"

/**
 * _strlen_two_strings - len of two strings.
 * @s1: frist char *
 * @s2: second char *
 * Description: Calculate the len of a string
 * include +1 for an extra '/' and +1 for '\0'
 * Return: len of the two strings
 */
int _strlen_two_strings(char *s1, char *s2)
{
	int len, i;

	for (len = 0, i = 0; s1[i] != '\0'; len++, i++)
		;
	for (i = 0; s2[i] != '\0'; len++, i++)
		;
	/* Add 2 for '/' and '\0' */
	return (len + 2);
}
/**
 * _strcat - concat 2 strings.
 * @dest: destination string
 * @src: source string
 * Return: char*
 */
void _strcat(char *dest, char *src)
{
	int i, j;

	for (j = 0; dest[j] != '\0'; j++)
		;

	for (i = 0 ; src[i] != '\0' ; i++)
		dest[j + i] = src[i];
	dest[j + i] = '\0';
}

/**
 * check_access - check if have access to the bin.
 * @path: get the PATH of the enviroment
 * @command: the name of the command
 * Description: Check if the command exist in one of the $PATH
 * Return: char*
 */
char *check_access(char *path, char *command)
{
	char *single_path;
	char *cat_command;
	int status, len_two;

	single_path = strtok(path, ":\n");
	while (single_path)
	{
		len_two = _strlen_two_strings(single_path, command);
		cat_command = malloc(sizeof(char) * len_two);
		if (cat_command == NULL)
			return (NULL);
		cat_command[0] = '\0';
		_strcat(cat_command, single_path);
		_strcat(cat_command, "/");
		_strcat(cat_command, command);

		status = access(cat_command, F_OK | X_OK | R_OK);
		if (status == 0)
		{
			return (cat_command);
		}

		free(cat_command);
		single_path = strtok(NULL, ":\n");
	}
	return (NULL);
}
<file_sep>/main.c
#include "shell.h"

/**
 * main - function main entry.
 * Description: main function for our shell
 * @argc: number of arguments passed to the shell
 * @argv: arguments passed to the shell
 * @envp: enviroment variables passed to the shell
 * Return: 0 on success
 **/
int main(int argc, char *argv[], char *envp[])
{
	int number_commands = 1;

	if (argc == 1)
	{
		if (isatty(STDIN_FILENO))
		{
			interactive_mode(argv, envp, &number_commands);
		}
		else
		{
			get_stdin(argv, envp, &number_commands);
		}
	}
	else
	{
		read_file(argv, envp, &number_commands);
	}
	return (0);
}
<file_sep>/README.md
# Simple Shell

The simple shell project is the largest and most difficult project we have worked on at Holberton School.
This project consists of creating a shell so that it behaves very similar to the Bourne Shell "sh".

This project was built by <NAME> and <NAME>

# Table of Contents
1. [Authors](#Authors)
2. [Features](#Features)
3. [How Use](#How-Use)
3. [Tasks](#Tasks)
4. [General Test Cases](#general-Test-Cases)

# Authors
 👤 **<NAME>**

- Twitter: [@batmanesfriki](https://twitter.com/batmanesfriki)
- Github: [@hb4y](https://github.com/hb4y)

👤 **<NAME>**

- Twitter: [@juanmarcab](https://twitter.com/juanmarcab)
- Github: [@juanmarcoscabezas](https://github.com/juanmarcoscabezas)

# Features
- Display a prompt and wait for the user to type a command.
- The prompt is displayed again each time a command has been executed.
- The command lines are simple, no semicolons, no pipes, no redirections or any other advanced features.
- The commands lines handle arguments.
- If an executable cannot be found, print an error message and display the prompt again.
- Handle the “end of file” condition (Ctrl+D) and the signal (Ctrl+C).
- Print the enviroment with 'env'.
- exit with a status
- cd can check the current directory.

# How Use

## How to compile

gcc -Wall -Werror -Wextra -pedantic *.c -o hsh

### Requirements

 - compile on Ubuntu 14.04 LTS
 - compile with gcc 4.8.4

### Examples

```bash
$ ./hsh
#cisfun$ echo "interactive mode"
"interactive mode"
#cisfun$
#cisfun$ exit
$
```
```bash
$ echo "/bin/ls" | ./hsh
AUTHORS         execute_commands.c  get_stdin.c         lib.c               _print.c     shell.h
built_in.c      get_commands.c      hsh                 main.c              read_file.c  _string.c
check_access.c  _getenv.c           interactive_mode.c  man_1_simple_shell  README.md
$
```


# General Test Cases

- [x] ./hsh;
- [x] echo "/bin/ls" | ./hsh
- [x] echo "asdfaas" | ./hsh
- [x] #cisfun$ ls
- [x] #cisfun$ ls -l
- [x] #cisfun$ cd folder/
- [x] #cisfun$ pwd
<file_sep>/_print.c
#include "shell.h"

/**
 * _putchar - writes the character c to stdout
 * @c: The character to print
 * Return: On success 1.
 * On error, -1 is returned, and errno is set appropriately.
 */
int _putchar(char c)
{
	return (write(1, &c, 1));
}

/**
 * _puts - writes a string
 * @s: String to print
 * Return:
 */
void _puts(char *s)
{
	int counter = 0;

	while (s[counter] != '\0')
	{
		_putchar(s[counter]);
		counter++;
	}
}

/**
 * print_number - prints integers
 * Description - This function prints an integer
 * @n: number of # and lines, size of triangle
 * Return:
 */
void print_number(int *n)
{
	int n_copy = *n;
	int divisor = 1;

	if (*n < 0)
	{
		divisor = -divisor;
		_putchar('-');
		while (n_copy < -9)
		{
			n_copy = n_copy / 10;
			divisor = divisor * 10;
		}
		while (divisor < -1)
		{
			_putchar((*n / divisor) % 10 + '0');
			divisor = divisor / 10;
		}
		_putchar((*n % 10) * -1 + '0');
	}
	if (*n >= 0)
	{
		while (n_copy > 9)
		{
			n_copy = n_copy / 10;
			divisor = divisor * 10;
		}
		while (divisor > 1)
		{
			_putchar((*n / divisor) % 10 + '0');
			divisor = divisor / 10;
		}
	_putchar(*n % 10 + '0');
	}
}
<file_sep>/shell.h
#ifndef SHELL_FILE
#define SHELL_FILE

#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>

void get_stdin(char *argv[], char *envp[], int *number_commands);
int read_file(char *argv[], char *envp[], int *number_commands);
int get_commands(char *argv[], char *buf, char *en[], int *n_cmds, int *lo);
char *_getenv(char *envp[], char *request_path);
char *check_access(char *path, char *command);
int _strlen(char *s);
char *_strcpy(char *dest, char *src);
void str_replace(char *dest, char *src);
void interactive_mode(char *argv[], char *envp[], int *number_commands);
int exec_cmds(char *argv[], char *tokens[], char *envp[], int *n_com, int *lo);
void _memset(char *s, char b, unsigned int n);
int built_in(char *argv[], char *tokens[], char *envp[], int *n_com, int *lo);
int _strcmp(char *string1, char *string2);
int _atoi(char *s);
void _puts(char *s);
int _putchar(char c);
void print_number(int *n);
int verify_tab(char *command, ssize_t command_len);
void *_realloc(void *ptr, unsigned int old_size, unsigned int new_size);

#endif
<file_sep>/_getenv.c
#include "shell.h"

/**
 * _getpath - get only the value of PATH form the env
 * Description:
 * @path: enviroment variable to check if it's equals to @request_path
 * @request_path: variable to check
 * Return: 0 if the line contains "PATH" - -1 on failure
 */
int _getpath(char *path, char *request_path)
{
	int counter;

	for (counter = 0; request_path[counter] != '\0'; counter++)
	{
		if (request_path[counter] != path[counter])
			return (-1);
	}
	return (0);
}

/**
 * _getenv - get the entire envp
 * Description:
 * @envp: enviroment variables passed to the shell
 * @request_path: path to find in @envp
 * Return: the PATH (NULL if not found)
 */
char *_getenv(char *envp[], char *request_path)
{
	char *envp_aux = NULL, *path = NULL, *path_return = NULL;
	int counter, getpath_result;

	for (counter = 0; envp != NULL && envp[counter] != NULL; counter++)
	{
		getpath_result = _getpath(envp[counter], request_path);

		if (getpath_result == 0)
		{
			if (_strlen(envp[counter]) == _strlen(request_path) + 1)
				return (NULL);
			envp_aux = malloc(sizeof(char) * _strlen(envp[counter]));
			if (!envp_aux)
				return (NULL);
			envp_aux = _strcpy(envp_aux, envp[counter]);
			path = strtok(envp_aux, "=");
			path = strtok(NULL, "");
			path_return = malloc(_strlen(path));
			if (!path_return)
			{
				free(envp_aux);
				return (NULL);
			}
			str_replace(path_return, path);
			free(envp_aux);
			break;
		}
	}
	return (path_return);
}
<file_sep>/get_stdin.c
#include "shell.h"

/**
 * process_command - Process every command
 * Description: THis function proccesses all the commands and execute it
 * @argv: arguments passed to the shell
 * @envp: enviroment variables passed to the shell
 * @n_com: the number of commands given until this point.
 * @command: Command to proccess
 * Return: the value of execute_commands
 */
int process_command(char *argv[], char *envp[], int *n_com, char *command)
{
	char *token = NULL;
	char **tokens = NULL;
	char *command_cpy = command;
	int pos = 0;
	int execute = 0;

	tokens = malloc(sizeof(char *) * 64);

	token = strtok(command_cpy, " \t\r\n\a");
	while (token)
	{
		tokens[pos] = token;
		pos++;
		token = strtok(NULL, " \t\r\n\a");
	}
	tokens[pos] = NULL;
	execute = exec_cmds(argv, tokens, envp, n_com, NULL);
	free(tokens);
	return (execute);
}

/**
 * verify_tab2 - Function to verify tabs
 * @command: Command to verify
 * @command_len: Length of the command to verify
 * Return: 0 on success, -1 otherwise
 */
int verify_tab2(char *command, ssize_t command_len)
{
	ssize_t counter = 0;

	while (counter < command_len)
	{
		if (command[counter] != '\t' && command[counter] != '\n')
		{
			if (command[counter] != ' ' && command[counter] != '\0')
				return (0);
		}
		counter++;
	}
	return (-1);
}

/**
 * get_stdin - function to get stdin.
 * Description: main
 * @argv: arguments passed to the shell
 * @envp: enviroment variables passed to the shell
 * @number_commands: the number of commands given until this point.
 * Return: 0 on success
 **/
void get_stdin(char *argv[], char *envp[], int *number_commands)
{
	char *command;
	unsigned int pos = 0;
	char ch = '\0';
	int execute = 0;
	unsigned int buf_size = 64, buf_inc = 1;

	command = malloc(sizeof(char) * buf_size);
	if (!command)
		exit(0);
	while (read(STDIN_FILENO, &ch, 1) > 0)
	{
		command[pos] = ch;
		if (ch == '\0' || ch == '\n')
		{
			command[pos + 1] = '\0';
			if (verify_tab2(command, _strlen(command)) == 0)
				execute = process_command(argv, envp, number_commands, command);
			pos = -1;
			free(command);
			buf_inc = 1;
			command = malloc(sizeof(char) * buf_size * buf_inc);
			if (!command)
				exit(0);
		}
		if (pos == (buf_size * buf_inc) - 2)
		{
			command[pos + 1] = '\0';
			command = _realloc(command, buf_size * buf_inc, buf_size * (buf_inc + 1));
			buf_inc++;
		}
		pos++;
	}
	free(command);
	exit(execute);
}
<file_sep>/_string.c
#include "shell.h"

/**
 * _strcpy - copy an array.
 * @dest: destiny
 * @src: source
 * Return: void.
 */
char *_strcpy(char *dest, char *src)
{
	int i, n;

	n = 0;
	while (src[n] != '\0')
	{
		n++;
	}

	for (i = 0; src[i] != '\0'; i++)
		dest[i] = src[i];
	dest[i++] = '\0';
	return (dest);
}

/**
 * _strlen - len of char *
 * @s: String to know the length
 * Return: return 1 more to count the null byte.
 */
int _strlen(char *s)
{
	int i;

	for (i = 0; s[i] != '\0'; i++)
		;
	return (i + 1);
}

/**
 * str_replace - replace a str with a second content
 * @dest: Destination str
 * @src: Source str
 * Return: void
 */
void str_replace(char *dest, char *src)
{
	int i;

	for (i = 0; src[i] != '\0'; i++)
		dest[i] = src[i];
	dest[i] = '\0';
}

/**
 * _strcmp - Compare strings
 * Description: This function compare two strings
 * @string1: First string to compare
 * @string2: Second string to compare
 * Return: @n bytes of @src
 */
int _strcmp(char *string1, char *string2)
{
	char *s1 = string1;
	char *s2 = string2;

	while (*s1 != '\0' && *s2 != '\0')
	{
		if (*s1 > *s2)
			return (*s1 - *s2);
		else if (*s2 > *s1)
			return ((*s2 - *s1) * -1);
		s1++;
		s2++;
	}
	return (0);
}

<file_sep>/interactive_mode.c
#include "shell.h"

/**
 * verify_tab - Function to verify tabs
 * @command: Command to verify
 * @command_len: Length of the command to verify
 * Return: 0 on success, -1 otherwise
 */
int verify_tab(char *command, ssize_t command_len)
{
	ssize_t counter = 0;

	while (counter < command_len)
	{
		if (command[counter] != '\t' && command[counter] != '\n')
		{
			if (command[counter] != ' ' && command[counter] != '\0')
				return (0);
		}
		counter++;
	}
	return (-1);
}
/**
 * handle_sig - function that take care of the interrupt signals.
 * @sig: signal integer
 * Return: void
 **/
void handle_sig(int sig)
{
	(void) sig;
	_puts("\n#cisfun$ ");
}
/**
 * interactive_mode - function in charge of shell interactive mode.
 * @argv: arguments passed to the shell
 * @envp: enviroment variables passed to the shell
 * @n_com: the number of commands given until this point
 * Return: void
 **/
void interactive_mode(char *argv[], char *envp[], int *n_com)
{
	char *buffer;
	size_t bufsize = 32;
	ssize_t getline_len;
	int last_out = 0;

	signal(SIGINT, handle_sig);
	while (1)
	{
		buffer = (char *) malloc(bufsize * sizeof(char));
		if (!buffer)
		{
			perror("Error on allocation");
			exit(0);
		}

		_puts("#cisfun$ ");
		getline_len = getline(&buffer, &bufsize, stdin);
		if (getline_len == EOF)
		{
			free(buffer);
			_putchar('\n');
			exit(last_out);
		}
		if (getline_len > 1)
		{
			if (verify_tab(buffer, getline_len) == 0)
				last_out = get_commands(argv, buffer, envp, n_com, &last_out);
			else
				(*n_com)++;
		}
		else
			(*n_com)++;

		free(buffer);
	}
}
<file_sep>/built_in.c
#include "shell.h"

/**
 * check_exit - Look for the flag of exit
 * Description: This function checks the flag of exit
 * @argv: arguments passed to the shell
 * @num: Number to check if is an integer
 * @n_com: the number of commands given until this point.
 * Return: 0 if success, -1 otherwise
 */
int check_exit(char *argv[], char *num, int *n_com)
{
	int counter = 0;
	char *err_msg;

	while (num[counter] != '\0')
	{
		if (num[counter] < 48 || num[counter] > 57)
		{
			err_msg = "exit: Illegal number";

			_puts(argv[0]);
			_puts(": ");
			print_number(n_com);
			_puts(": ");
			_puts(err_msg);
			_puts(": ");
			_puts(num);
			_putchar('\n');
			return (127);
		}
		counter++;
	}
	return (0);
}

/**
 * check_env - Look for the flag of env
 * Description: This function checks the flag of env
 * @tokens: optiones tokenized from a command
 * @envp: enviroment variables passed to the shell
 * @n_com: the number of commands given until this point.
 * Return: 0 if success, -1 otherwise
 */
int check_env(char *tokens[], char *envp[], int *n_com)
{
	int counter = 0;

	if (tokens[1])
	{
		_puts("env: ");
		_puts(tokens[1]);
		_puts(": No such file or directory\n");
		(*n_com)++;
		return (127);
	}
	while (envp[counter])
	{
		_puts(envp[counter]);
		_putchar('\n');
		counter++;
	}
	(*n_com)++;
	return (0);
}

/**
 * check_cd - Look for the flag of cd
 * Description: This function checks the flag of cd
 * @argv: arguments passed to the shell
 * @tokens: optiones tokenized from a command
 * @envp: enviroment variables passed to the shell
 * @n_com: the number of commands given until this point.
 * Return: 0 if success, -1 otherwise
 */
int check_cd(char *argv[], char *tokens[], char *envp[], int *n_com)
{
	int chdir_exec;
	char *home;
	char *er_m; /* Error message variable */

	if (tokens[1])
	{
		chdir_exec = chdir(tokens[1]);
		if (chdir_exec != 0)
		{
			er_m = "cd: can't cd to";

			_puts(argv[0]);
			_puts(": ");
			print_number(n_com);
			_puts(": ");
			_puts(er_m);
			_puts(" ");
			_puts(tokens[1]);
			_putchar('\n');
			(*n_com)++;
			return (2);
		}
		(*n_com)++;
		return (0);
	}
	(*n_com)++;
	home = _getenv(envp, "HOME");
	chdir(home);
	free(home);
	return (0);
}

/**
 * built_in - Built-ins
 * Description: This function is to check the built-ins
 * @argv: arguments passed to the shell
 * @tokens: optiones tokenized from a command
 * @envp: enviroment variables passed to the shell
 * @n_com: the number of commands given until this point.
 * @lo: last output
 * Return: the flag passed to exit, -1 otherwise
 */
int built_in(char *argv[], char *tokens[], char *envp[], int *n_com, int *lo)
{
	if (tokens != NULL)
	{
		if (tokens[0])
		{
			if (_strcmp(tokens[0], "exit") == 0)
			{
				if (tokens[1])
				{
					if (check_exit(argv, tokens[1], n_com) == 0)
						exit(_atoi(tokens[1]));
					(*n_com)++;
					return (127);
				}
				if (lo)
					exit(*lo);
				exit(0);
			}
			if (_strcmp(tokens[0], "env") == 0)
			{
				return (check_env(tokens, envp, n_com));
			}
			if (_strcmp(tokens[0], "cd") == 0)
			{
				return (check_cd(argv, tokens, envp, n_com));
			}
		}
	}
	return (1);
}
<file_sep>/read_file.c
#include "shell.h"

/**
 * process_command2 - Process every command
 * Description: THis function proccesses all the commands and execute it
 * @argv: arguments passed to the shell
 * @envp: enviroment variables passed to the shell
 * @n_com: the number of commands given until this point.
 * @command: Command to proccess
 * Return: the value of execute_commands
 */
int process_command2(char *argv[], char *envp[], int *n_com, char *command)
{
	char *token;
	char **tokens = malloc(sizeof(char *) * 64);
	int pos = 0;
	int execute;

	token = strtok(command, " \t\r\n\a");
	while (token)
	{
		tokens[pos] = token;
		pos++;
		token = strtok(NULL, " \t\r\n\a");
	}
	tokens[pos] = NULL;
	execute = exec_cmds(argv, tokens, envp, n_com, NULL);
	free(tokens);
	return (execute);
}

/**
 * get_stdin2 - function to get stdin.
 * Description: main
 * @argv: arguments passed to the shell
 * @envp: enviroment variables passed to the shell
 * @number_commands: the number of commands given until this point.
 * Return: 0 on success
 **/
void get_stdin2(char *argv[], char *envp[], int *number_commands)
{
	char *command = malloc(sizeof(char) * 1024);
	int pos = 0;
	char ch;
	int execute;

	while (read(STDIN_FILENO, &ch, 1) > 0)
	{
		command[pos] = ch;
		if (ch == '\0' || ch == '\n')
		{
			execute = process_command2(argv, envp, number_commands, command);
			pos = -1;
			command = malloc(sizeof(char) * 1024);
			_memset(command, '\0', 1024);
		}
		pos++;
	}
	exit(execute);
}

/**
 * read_file - function
 * @argv: arguments passed to the shell
 * @envp: enviroment variables passed to the shell
 * @n_com: the number of commands given until this point.
 * Return: actual number of letters it could print
 */
int read_file(char *argv[], char *envp[], int *n_com)
{
	int file, letters = 1024;
	char *buffer, *filename = argv[0], n;

	file = open(filename, O_RDONLY);
	if (file == -1)
		return (0);
	buffer = malloc(sizeof(char) * letters);
	if (buffer == NULL)
	{
		close(file);
		return (0);
	}
	n = read(file, buffer, letters);
	if (n == -1)
	{
		free(buffer);
		close(file);
		return (-1);
	}
	n = write(1, buffer, n);
	/* (STDOUT_FILENO, "%s", buffer); */
	if (n == -1)
	{
		free(buffer);
		close(file);
		return (-1);
	}
	get_stdin2(argv, envp, n_com);
	free(buffer);
	close(file);
	return (n);
}
