exec.c
static void redir_std_flow(struct cmd* cmd,
		struct file f, int redir_fd) {

	int fd;
	char buf[BUFLEN];

	if (strlen(f.name) > 0) {
		if (strcmp(f.name, "&1") == 0)
			fd = STDOUT_FILENO;
		else if ((fd = open_redir_fd(f.name, f.flags)) < 0) {
			memset(buf, 0, BUFLEN);
			snprintf(buf, sizeof buf, "cannot open file: %s ", f.name);
			perror(buf);
			free(ss.ss_sp);
			free_command(cmd);
			_exit(EXIT_FAILURE);
		}
		if (dup2(fd, redir_fd) < 0) {
			memset(buf, 0, BUFLEN);
			snprintf(buf, sizeof buf, "cannot dup file: %s ", f.name);
			perror(buf);
			free(ss.ss_sp);
			free_command(cmd);
			_exit(EXIT_FAILURE);
		}
	}
}
// opens the file and redirects it
// to the appropiate standar flow
opens the file and redirects it
to the appropiate standar flow
opens the file and redirects it to the appropiate standar flow
static void redir_std_flow(struct cmd* cmd,
		struct file f, int redir_fd) {
	int fd;
	char buf[BUFLEN];
	if (strlen(f.name) > 0) {
		if (strcmp(f.name, "&1") == 0)
			fd = STDOUT_FILENO;
		else if ((fd = open_redir_fd(f.name, f.flags)) < 0) {
			memset(buf, 0, BUFLEN);
			snprintf(buf, sizeof buf, "cannot open file: %s ", f.name);
			perror(buf);
			free(ss.ss_sp);
			free_command(cmd);
			_exit(EXIT_FAILURE);
		}
		if (dup2(fd, redir_fd) < 0) {
			memset(buf, 0, BUFLEN);
			snprintf(buf, sizeof buf, "cannot dup file: %s ", f.name);
			perror(buf);
			free(ss.ss_sp);
			free_command(cmd);
			_exit(EXIT_FAILURE);
		}
	}
}
static void redir_std_flow ( struct cmd * cmd , struct file f , int redir_fd ) { int fd ; char buf [ BUFLEN ] ; if ( strlen ( f . name ) > 0 ) { if ( strcmp ( f . name , " " ) == 0 ) fd = STDOUT_FILENO ; else if ( ( fd = open_redir_fd ( f . name , f . flags ) ) < 0 ) { memset ( buf , 0 , BUFLEN ) ; snprintf ( buf , sizeof buf , " " , f . name ) ; perror ( buf ) ; free ( ss . ss_sp ) ; free_command ( cmd ) ; _exit ( EXIT_FAILURE ) ; } if ( dup2 ( fd , redir_fd ) < 0 ) { memset ( buf , 0 , BUFLEN ) ; snprintf ( buf , sizeof buf , " " , f . name ) ; perror ( buf ) ; free ( ss . ss_sp ) ; free_command ( cmd ) ; _exit ( EXIT_FAILURE ) ; } } }
opens the file and redirects it
to the appropiate standar flow
opens the file and redirects it to the appropiate standar flow