Paul Eggert <egg...@cs.ucla.edu> wrote:

> This sped up 'seq 10000000000 | grep . >/dev/null' by a factor of
> 380,000 on my platform (Fedora 23, x86-64, AMD Phenom II X4 910e,
> en_US.UTF-8 locale).
> +      else if (S_ISCHR (tmp_stat.st_mode))
> +        {
> +          struct stat null_stat;
> +          if (stat ("/dev/null", &null_stat) == 0
> +              && SAME_INODE (tmp_stat, null_stat))

Testing for same inode is likely to work but not guaranteed. I think
it'd be better to compare the major and minor device numbers on the two
stat buffers. If they're equal then you know for sure you have a null
device in hand.

(Consider someone who is root and does a 'mknod MA MI /tmp/null' where
MA and MI are the major and minor device numbers for /dev/null. grep
into such a /tmp/null would not enjoy the speedup as you've coded it.
And I know that practically speaking this is unlikely, I'm coming at it
more from a perspectgive of bullet-proofing the code.)

My two cents worth, of course.

Thanks,

Arnold



Reply via email to