Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/redir/redir.c

    r1c635d6 r9c4cf0d  
    3737#include <sys/types.h>
    3838#include <stdlib.h>
    39 #include <fcntl.h>
    4039#include <unistd.h>
    4140#include <str.h>
     
    4443#include <str_error.h>
    4544#include <errno.h>
     45#include <vfs/vfs.h>
    4646
    4747#define NAME  "redir"
     
    5353}
    5454
    55 static void reopen(FILE **stream, int fd, const char *path, int flags, const char *mode)
     55static void reopen(FILE **stream, int fd, const char *path, int flags, int mode,
     56    const char *fmode)
    5657{
    5758        if (fclose(*stream))
     
    6061        *stream = NULL;
    6162       
    62         int oldfd = open(path, flags);
     63        int oldfd = vfs_lookup_open(path, WALK_REGULAR | flags, mode);
    6364        if (oldfd < 0)
    6465                return;
    6566       
    6667        if (oldfd != fd) {
    67                 if (dup2(oldfd, fd) != fd)
     68                if (vfs_clone(oldfd, fd, false) != fd)
    6869                        return;
    6970               
    70                 if (close(oldfd))
     71                if (vfs_put(oldfd))
    7172                        return;
    7273        }
    7374       
    74         *stream = fdopen(fd, mode);
     75        *stream = fdopen(fd, fmode);
    7576}
    7677
     
    121122                                return -2;
    122123                        }
    123                         reopen(&stdin, 0, argv[i], O_RDONLY, "r");
     124                        reopen(&stdin, 0, argv[i], 0, MODE_READ, "r");
    124125                } else if (str_cmp(argv[i], "-o") == 0) {
    125126                        i++;
     
    128129                                return -3;
    129130                        }
    130                         reopen(&stdout, 1, argv[i], O_WRONLY | O_CREAT, "w");
     131                        reopen(&stdout, 1, argv[i], WALK_MAY_CREATE, MODE_WRITE,
     132                            "w");
    131133                } else if (str_cmp(argv[i], "-e") == 0) {
    132134                        i++;
     
    135137                                return -4;
    136138                        }
    137                         reopen(&stderr, 2, argv[i], O_WRONLY | O_CREAT, "w");
     139                        reopen(&stderr, 2, argv[i], WALK_MAY_CREATE, MODE_WRITE,
     140                            "w");
    138141                } else if (str_cmp(argv[i], "--") == 0) {
    139142                        i++;
Note: See TracChangeset for help on using the changeset viewer.