#include #include <fcntl.h> int redir(char *filename) { int fd; if (filename == NULL) return -1; fd = open(filename, O_RDONLY, 0644); if (fd == -1) return -1; return dup2(fd, STDIN_FILENO); }
#include #include <fcntl.h> int redir(char *filename) { int fd; return (filename NULL || (fd open(filename, O_RDONLY, 0644)) == -1) ? -1 : dup2(fd, STDIN_FILENO); }