Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- # define STDOUT (1)
- # define TRUE (1)
- # define FALSE (0)
- typedef struct
- {
- int fd_1;
- int fd_2;
- } t_fd;
- static int _redirect(t_fd *s_fd)
- {
- int save;
- save = dup(1);
- close(1);
- dup(s_fd->fd_1);
- close(s_fd->fd_1);
- printf("Hello, world!\n"); // Ceci doit etre dans le fichier test et pas s'afficher a l'écran
- dup2(save, 1);
- }
- static int _run(t_fd *s_fd)
- {
- _redirect(s_fd);
- return (TRUE);
- }
- int main(int ac, char **av)
- {
- t_fd s_fd;
- if ((s_fd.fd_1 = open("test",O_WRONLY | O_CREAT, S_IREAD | S_IWRITE )) < 0)
- exit(1);
- s_fd.fd_2 = STDOUT;
- if (!(_run(&s_fd)))
- return (FALSE);
- printf("AAAAAA\n"); // Ceci doit s'afficher a l'écran mais n'est pas dans le fichier "test"
- return (TRUE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement