summaryrefslogtreecommitdiff
path: root/src/tail.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1998-04-26 19:53:54 +0000
committerJim Meyering <jim@meyering.net>1998-04-26 19:53:54 +0000
commitb7d50ca523182a80cca2452553f35360a269d557 (patch)
treecd68f845bbc43bf296e4ebae1e6143c97cf02c33 /src/tail.c
parentfe18d63a652131056ca198d087dcdc411cc7895c (diff)
downloadcoreutils-b7d50ca523182a80cca2452553f35360a269d557.tar.xz
(xwrite): New function -- converted from macro.
Diffstat (limited to 'src/tail.c')
-rw-r--r--src/tail.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/tail.c b/src/tail.c
index 7a089637b..6991badf6 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -63,16 +63,6 @@
# define OFF_T_MAX TYPE_MAXIMUM (off_t)
#endif
-#define XWRITE(fd, buffer, n_bytes) \
- do \
- { \
- assert ((fd) == 1); \
- assert ((n_bytes) >= 0); \
- if (n_bytes > 0 && fwrite ((buffer), 1, (n_bytes), stdout) == 0) \
- error (EXIT_FAILURE, errno, _("write error")); \
- } \
- while (0)
-
/* Number of items to tail. */
#define DEFAULT_N_LINES 10
@@ -219,7 +209,16 @@ or -c +VALUE.\n\
exit (status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
-static __inline__ void
+static void
+xwrite (int fd, char *const buffer, size_t n_bytes)
+{
+ assert (fd == 1);
+ assert (n_bytes >= 0);
+ if (n_bytes > 0 && fwrite (buffer, 1, n_bytes, stdout) == 0)
+ error (EXIT_FAILURE, errno, _("write error"));
+}
+
+static void
close_fd (int fd, const char *filename)
{
if (fd != -1 && fd != STDIN_FILENO && close (fd))
@@ -289,7 +288,7 @@ file_lines (const char *pretty_filename, int fd, long int n_lines, off_t pos)
/* If this newline wasn't the last character in the buffer,
print the text after it. */
if (i != bytes_read - 1)
- XWRITE (STDOUT_FILENO, &buffer[i + 1], bytes_read - (i + 1));
+ xwrite (STDOUT_FILENO, &buffer[i + 1], bytes_read - (i + 1));
return 0;
}
}
@@ -419,10 +418,10 @@ pipe_lines (const char *pretty_filename, int fd, long int n_lines)
}
else
i = 0;
- XWRITE (STDOUT_FILENO, &tmp->buffer[i], tmp->nbytes - i);
+ xwrite (STDOUT_FILENO, &tmp->buffer[i], tmp->nbytes - i);
for (tmp = tmp->next; tmp; tmp = tmp->next)
- XWRITE (STDOUT_FILENO, tmp->buffer, tmp->nbytes);
+ xwrite (STDOUT_FILENO, tmp->buffer, tmp->nbytes);
free_lbuffers:
while (first)
@@ -513,10 +512,10 @@ pipe_bytes (const char *pretty_filename, int fd, off_t n_bytes)
i = total_bytes - n_bytes;
else
i = 0;
- XWRITE (STDOUT_FILENO, &tmp->buffer[i], tmp->nbytes - i);
+ xwrite (STDOUT_FILENO, &tmp->buffer[i], tmp->nbytes - i);
for (tmp = tmp->next; tmp; tmp = tmp->next)
- XWRITE (STDOUT_FILENO, tmp->buffer, tmp->nbytes);
+ xwrite (STDOUT_FILENO, tmp->buffer, tmp->nbytes);
free_cbuffers:
while (first)
@@ -546,7 +545,7 @@ start_bytes (const char *pretty_filename, int fd, off_t n_bytes)
return 1;
}
else if (n_bytes < 0)
- XWRITE (STDOUT_FILENO, &buffer[bytes_read + n_bytes], -n_bytes);
+ xwrite (STDOUT_FILENO, &buffer[bytes_read + n_bytes], -n_bytes);
return 0;
}
@@ -575,7 +574,7 @@ start_lines (const char *pretty_filename, int fd, long int n_lines)
}
else if (bytes_to_skip < bytes_read)
{
- XWRITE (STDOUT_FILENO, &buffer[bytes_to_skip],
+ xwrite (STDOUT_FILENO, &buffer[bytes_to_skip],
bytes_read - bytes_to_skip);
}
return 0;
@@ -594,7 +593,7 @@ dump_remainder (const char *pretty_filename, int fd)
total = 0;
while ((bytes_read = safe_read (fd, buffer, BUFSIZ)) > 0)
{
- XWRITE (STDOUT_FILENO, buffer, bytes_read);
+ xwrite (STDOUT_FILENO, buffer, bytes_read);
total += bytes_read;
}
if (bytes_read == -1)