summaryrefslogtreecommitdiff
path: root/simpletail.c
diff options
context:
space:
mode:
Diffstat (limited to 'simpletail.c')
-rw-r--r--simpletail.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/simpletail.c b/simpletail.c
index 4016681..e8e8809 100644
--- a/simpletail.c
+++ b/simpletail.c
@@ -36,6 +36,7 @@
#include "inotail.h"
#define BUFFER_SIZE 4096
+#define DEFAULT_N_LINES 10
void usage(void)
{
@@ -53,6 +54,8 @@ off_t lines(int fd, int file_size, unsigned int n_lines)
if (offset < 0)
offset = 0;
+ n_lines += 1; /* We also count the last \n */
+
while (offset > 0 && n_lines > 0) {
int rc;
int block_size = BUFFER_SIZE; /* Size of the current block we're reading */
@@ -162,14 +165,14 @@ int watch_file(const char *filename, off_t offset)
int main(int argc, char **argv)
{
int i, fd;
- int n_lines = 0;
+ int n_lines = DEFAULT_N_LINES;
int ret = 0;
short forever = 0;
char buf[BUFFER_SIZE], *filename;
struct stat finfo;
off_t offset = 0;
- if (argc < 3)
+ if (argc < 2)
usage();
for (i = 1; (i + 1 < argc) && (argv[i][0] == '-'); i++) {
@@ -178,7 +181,7 @@ int main(int argc, char **argv)
forever = 1;
break;
case 'n':
- n_lines = strtol(argv[++i], NULL, 0) + 1;
+ n_lines = strtol(argv[++i], NULL, 0);
break;
default:
usage();