Code

get_author_initials: various fixes
[tig.git] / io.c
diff --git a/io.c b/io.c
index 685ffb6cfeb77d7573156f4cec6332fc0cabdce7..901a3817065e32a46d623363b82be529840945a2 100644 (file)
--- a/io.c
+++ b/io.c
@@ -97,6 +97,7 @@ argv_copy(const char ***dst, const char *src[])
 {
        int argc;
 
+       argv_free(*dst);
        for (argc = 0; src[argc]; argc++)
                if (!argv_append(dst, src[argc]))
                        return FALSE;
@@ -182,6 +183,9 @@ io_run(struct io *io, enum io_type type, const char *dir, const char *argv[], ..
 
        io_init(io);
 
+       if (dir && !strcmp(dir, argv[0]))
+               return io_open(io, "%s%s", dir, argv[1]);
+
        if ((type == IO_RD || type == IO_WR) && pipe(pipefds) < 0) {
                io->error = errno;
                return FALSE;
@@ -276,7 +280,7 @@ io_strerror(struct io *io)
 }
 
 bool
-io_can_read(struct io *io)
+io_can_read(struct io *io, bool can_block)
 {
        struct timeval tv = { 0, 500 };
        fd_set fds;
@@ -284,7 +288,7 @@ io_can_read(struct io *io)
        FD_ZERO(&fds);
        FD_SET(io->pipe, &fds);
 
-       return select(io->pipe + 1, &fds, NULL, NULL, &tv) > 0;
+       return select(io->pipe + 1, &fds, NULL, NULL, can_block ? NULL : &tv) > 0;
 }
 
 ssize_t