Changes in uspace/app/redir/redir.c [1c635d6:9c4cf0d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/redir/redir.c
r1c635d6 r9c4cf0d 37 37 #include <sys/types.h> 38 38 #include <stdlib.h> 39 #include <fcntl.h>40 39 #include <unistd.h> 41 40 #include <str.h> … … 44 43 #include <str_error.h> 45 44 #include <errno.h> 45 #include <vfs/vfs.h> 46 46 47 47 #define NAME "redir" … … 53 53 } 54 54 55 static void reopen(FILE **stream, int fd, const char *path, int flags, const char *mode) 55 static void reopen(FILE **stream, int fd, const char *path, int flags, int mode, 56 const char *fmode) 56 57 { 57 58 if (fclose(*stream)) … … 60 61 *stream = NULL; 61 62 62 int oldfd = open(path, flags);63 int oldfd = vfs_lookup_open(path, WALK_REGULAR | flags, mode); 63 64 if (oldfd < 0) 64 65 return; 65 66 66 67 if (oldfd != fd) { 67 if ( dup2(oldfd, fd) != fd)68 if (vfs_clone(oldfd, fd, false) != fd) 68 69 return; 69 70 70 if ( close(oldfd))71 if (vfs_put(oldfd)) 71 72 return; 72 73 } 73 74 74 *stream = fdopen(fd, mode);75 *stream = fdopen(fd, fmode); 75 76 } 76 77 … … 121 122 return -2; 122 123 } 123 reopen(&stdin, 0, argv[i], O_RDONLY, "r");124 reopen(&stdin, 0, argv[i], 0, MODE_READ, "r"); 124 125 } else if (str_cmp(argv[i], "-o") == 0) { 125 126 i++; … … 128 129 return -3; 129 130 } 130 reopen(&stdout, 1, argv[i], O_WRONLY | O_CREAT, "w"); 131 reopen(&stdout, 1, argv[i], WALK_MAY_CREATE, MODE_WRITE, 132 "w"); 131 133 } else if (str_cmp(argv[i], "-e") == 0) { 132 134 i++; … … 135 137 return -4; 136 138 } 137 reopen(&stderr, 2, argv[i], O_WRONLY | O_CREAT, "w"); 139 reopen(&stderr, 2, argv[i], WALK_MAY_CREATE, MODE_WRITE, 140 "w"); 138 141 } else if (str_cmp(argv[i], "--") == 0) { 139 142 i++;
Note:
See TracChangeset
for help on using the changeset viewer.