From 0c1c5b483d2268e11928a796e5d1a1aabf64f714 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 29 Oct 2004 21:59:33 +0000 Subject: [PATCH] * src/tac.c (tac_file): Remove temporary prototype and move this function `down' so that it precedes definition of tac_nonseekable. --- src/tac.c | 105 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 51 insertions(+), 54 deletions(-) diff --git a/src/tac.c b/src/tac.c index ca172d2..4c73a74 100644 --- a/src/tac.c +++ b/src/tac.c @@ -372,60 +372,6 @@ tac_seekable (int input_fd, const char *file) } } -/* Temporary prototype -- I'm about to reorder functions. */ -static bool tac_nonseekable (int input_fd, const char *file); - -/* Print FILE in reverse, copying it to a temporary - file first if it is not seekable. - Return true if successful. */ - -static bool -tac_file (const char *filename) -{ - bool ok; - off_t file_size; - int fd; - - if (STREQ (filename, "-")) - { - have_read_stdin = true; - fd = STDIN_FILENO; - filename = _("standard input"); - } - else - { - fd = open (filename, O_RDONLY); - if (fd < 0) - { - error (0, errno, _("cannot open %s for reading"), quote (filename)); - return false; - } - } - - /* We need binary I/O, since `tac' relies - on `lseek' and byte counts. - - Binary output will leave the lines' ends (NL or - CR/LF) intact when the output is a disk file. - Writing a file with CR/LF pairs at end of lines in - text mode has no visible effect on console output, - since two CRs in a row are just like one CR. */ - SET_BINARY2 (fd, STDOUT_FILENO); - - file_size = lseek (fd, (off_t) 0, SEEK_END); - - ok = (0 <= file_size - ? tac_seekable (fd, filename) - : tac_nonseekable (fd, filename)); - - if (fd != STDIN_FILENO && close (fd) == -1) - { - error (0, errno, _("closing %s"), quote (filename)); - ok = false; - } - return ok; -} - #if DONT_UNLINK_WHILE_OPEN static const char *file_to_remove; @@ -520,6 +466,57 @@ tac_nonseekable (int input_fd, const char *file) return tac_seekable (fileno (tmp_stream), tmp_file); } +/* Print FILE in reverse, copying it to a temporary + file first if it is not seekable. + Return true if successful. */ + +static bool +tac_file (const char *filename) +{ + bool ok; + off_t file_size; + int fd; + + if (STREQ (filename, "-")) + { + have_read_stdin = true; + fd = STDIN_FILENO; + filename = _("standard input"); + } + else + { + fd = open (filename, O_RDONLY); + if (fd < 0) + { + error (0, errno, _("cannot open %s for reading"), quote (filename)); + return false; + } + } + + /* We need binary I/O, since `tac' relies + on `lseek' and byte counts. + + Binary output will leave the lines' ends (NL or + CR/LF) intact when the output is a disk file. + Writing a file with CR/LF pairs at end of lines in + text mode has no visible effect on console output, + since two CRs in a row are just like one CR. */ + SET_BINARY2 (fd, STDOUT_FILENO); + + file_size = lseek (fd, (off_t) 0, SEEK_END); + + ok = (0 <= file_size + ? tac_seekable (fd, filename) + : tac_nonseekable (fd, filename)); + + if (fd != STDIN_FILENO && close (fd) == -1) + { + error (0, errno, _("closing %s"), quote (filename)); + ok = false; + } + return ok; +} + #if 0 /* BUF_END points one byte past the end of the buffer to be searched. */ -- 2.7.4