summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-10-29 21:59:33 +0000
committerJim Meyering <jim@meyering.net>2004-10-29 21:59:33 +0000
commit0c1c5b483d2268e11928a796e5d1a1aabf64f714 (patch)
tree5b710a5569bf4cea1405af2e3faa65a55b75ce3b /src
parentbbda05b8eee4988b1f822b534e1091880bc833d7 (diff)
downloadcoreutils-0c1c5b483d2268e11928a796e5d1a1aabf64f714.tar.xz
* src/tac.c (tac_file): Remove temporary prototype and move this
function `down' so that it precedes definition of tac_nonseekable.
Diffstat (limited to 'src')
-rw-r--r--src/tac.c105
1 files changed, 51 insertions, 54 deletions
diff --git a/src/tac.c b/src/tac.c
index ca172d291..4c73a7422 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. */