* cmp(1) as a builtin
@ 2014-06-02 16:34 Roman Neuhauser
2014-06-03 4:28 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Roman Neuhauser @ 2014-06-02 16:34 UTC (permalink / raw)
To: zsh-users
hello,
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.
questions:
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?
--
roman
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: cmp(1) as a builtin
2014-06-02 16:34 cmp(1) as a builtin Roman Neuhauser
@ 2014-06-03 4:28 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2014-06-03 4:28 UTC (permalink / raw)
To: zsh-users
On Jun 2, 6:34pm, Roman Neuhauser wrote:
}
} 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?
Zsh does not have any special API or cache for stat data. The closest
thing is cond.c:getstat() which has some special handling for /dev/fd/
files, but is currently declared static.
} 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...?
You can use stdin. SHIN is the command input stream (e.g., terminal or
script file), so don't use that.
} do_cmp() passes the cond_str() results to fopen(). am i using
} cond_str() correctly?
I believe so, yes. Compare to Src/Modules/example.c cond_i_ex().
You may want to put these in your own module rather than modifying the
zsh/files module. Editing copies of Src/Modules/example.* works well
for this.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-06-03 4:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-02 16:34 cmp(1) as a builtin Roman Neuhauser
2014-06-03 4:28 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).