From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20087 invoked by alias); 2 Jun 2014 16:41:54 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18872 Received: (qmail 28389 invoked from network); 2 Jun 2014 16:41:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 Date: Mon, 2 Jun 2014 18:34:46 +0200 From: Roman Neuhauser To: zsh-users@zsh.org Subject: cmp(1) as a builtin Message-ID: <20140602163446.GB1629@isis.sigpipe.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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