[prev in list] [next in list] [prev in thread] [next in thread] 

List:       util-linux-ng
Subject:    Re: [PATCH 12/16] tailf: count last lines correctly at initial print out
From:       Karel Zak <kzak () redhat ! com>
Date:       2015-02-24 12:12:41
Message-ID: 20150224121241.GN19430 () ws ! net ! home
[Download RAW message or body]

On Sun, Feb 22, 2015 at 02:41:42PM +0000, Sami Kerola wrote:
> When last lines happen to be greater than string buffer size for fgets()
> the number of printed lines resulted to too few.

 Maybe add a note about mmap() to commit message ?!

> -	if (!(str = fopen(filename, "r")))
> +	if (!(fd = open(filename, O_RDONLY)))
>  		err(EXIT_FAILURE, _("cannot open %s"), filename);
> -
> -	buf = xmalloc((lines ? lines : 1) * BUFSIZ);
> -	p = buf;
> -	while (fgets(p, BUFSIZ, str)) {
> -		if (++tail >= lines) {
> -			tail = 0;
> -			head = 1;
> +	data = mmap(0, old->st_size, PROT_READ, MAP_SHARED, fd, 0);

 It would be nice to compare this it with original implementation on
 large files. I guess mmap will be more effective and faster.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic