Code

IO API: replace init_io_fd with io_open which calls fopen(3)
authorJonas Fonseca <fonseca@diku.dk>
Fri, 9 Jan 2009 14:11:48 +0000 (09:11 -0500)
committerJonas Fonseca <fonseca@diku.dk>
Tue, 13 Jan 2009 21:55:19 +0000 (22:55 +0100)
tig.c

diff --git a/tig.c b/tig.c
index fdf1dc6c56b01b96118058a7dda67facea50ddbc..12c385ad27c3bf5a5b9acf1f026e04734c454822 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -35,6 +35,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <time.h>
+#include <fcntl.h>
 
 #include <regex.h>
 
@@ -391,10 +392,10 @@ init_io_rd(struct io *io, const char *argv[], const char *dir,
 }
 
 static bool
-init_io_fd(struct io *io, FILE *pipe)
+io_open(struct io *io, const char *name)
 {
        init_io(io, NULL, IO_FD);
-       io->pipe = pipe;
+       io->pipe = *name ? fopen(name, "r") : stdin;
        return io->pipe != NULL;
 }
 
@@ -1558,7 +1559,7 @@ load_option_file(const char *path)
        struct io io = {};
 
        /* It's ok that the file doesn't exist. */
-       if (!init_io_fd(&io, fopen(path, "r")))
+       if (!io_open(&io, path))
                return;
 
        config_lineno = 0;
@@ -2567,7 +2568,7 @@ prepare_update_file(struct view *view, const char *name)
 {
        if (view->pipe)
                end_update(view, TRUE);
-       return init_io_fd(&view->io, fopen(name, "r"));
+       return io_open(&view->io, name);
 }
 
 static bool
@@ -3807,7 +3808,7 @@ struct blame {
 static bool
 blame_open(struct view *view)
 {
-       if (*opt_ref || !init_io_fd(&view->io, fopen(opt_file, "r"))) {
+       if (*opt_ref || !io_open(&view->io, opt_file)) {
                if (!run_io_rd(&view->io, blame_cat_file_argv, FORMAT_ALL))
                        return FALSE;
        }
@@ -6409,7 +6410,7 @@ main(int argc, const char *argv[])
 
        if (request == REQ_VIEW_PAGER || run_argv) {
                if (request == REQ_VIEW_PAGER)
-                       init_io_fd(&VIEW(request)->io, stdin);
+                       io_open(&VIEW(request)->io, "");
                else if (!prepare_update(VIEW(request), run_argv, NULL, FORMAT_NONE))
                        die("Failed to format arguments");
                open_view(NULL, request, OPEN_PREPARED);