Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

cmp(1) as a builtin


i need to run cmp(1) on a heap of mostly small files, and the forking
overhead is killing me.  i added a PoC bit to zsh/files to expose b:cmp
and C:qf (eQual Files).  it seems to work, but i'm pretty sure it has
issues as i don't know what i'm doing here, on several levels.


the cmp builtin currently always reads the file data.  it should stat
both operands to see if that can be skipped.  what api do i use for
that?  does zsh have some kind of stat cache i should hook into?

if either operand is "-", it should read from stdin.  how do i get hold
of standard input in the builtin?  can i use the standard FILE* handle
(stdin), do i need fdopen(SHIN, "r") (or use SHIN directly), or...?

the condexpr operator ([[ x -qf y ]]) is implemented like this:

    static int
    cond_cmp(char **args, UNUSED(int func))
        return 0 == do_cmp(
            "cond_qf", 1,
            cond_str(args, 0, 0),
            cond_str(args, 1, 0)

do_cmp() passes the cond_str() results to fopen().  am i using
cond_str() correctly?


Messages sorted by: Reverse Date, Date, Thread, Author