zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayned@users.sourceforge.net>
To: Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Cc: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: Re: PATCH: Re: Globbing for Empty Directories?
Date: Tue, 6 Apr 2004 10:27:58 -0700	[thread overview]
Message-ID: <20040406172758.GB10632@blorf.net> (raw)
In-Reply-To: <20040401184336.DC34B8646@pwstephenson.fsnet.co.uk>

[-- Attachment #1: Type: text/plain, Size: 517 bytes --]

On Thu, Apr 01, 2004 at 07:43:35PM +0100, Peter Stephenson wrote:
> +qualnonemptydir(char *name, struct stat *buf, off_t days, char *str)

Here's a minor optimization for this function.  It avoids reading the
directory if the st_nlink count is greater than 2 (since this must mean
that it has subdirs, and hence is not empty).  I decided to move the
opendir() call down below this nlink test, so I had to pre-qualify the
name using S_ISDIR().

I believe that this is portable.  Any objections/hesitations?

..wayne..

[-- Attachment #2: emptydir.patch --]
[-- Type: text/plain, Size: 507 bytes --]

--- Src/glob.c	1 Apr 2004 18:33:22 -0000	1.32
+++ Src/glob.c	6 Apr 2004 17:04:48 -0000
@@ -2807,10 +2807,16 @@ qualsheval(char *name, struct stat *buf,
 static int
 qualnonemptydir(char *name, struct stat *buf, off_t days, char *str)
 {
-    DIR *dirh = opendir(name);
+    DIR *dirh;
     struct dirent *de;
 
-    if (dirh == NULL)
+    if (!S_ISDIR(buf->st_mode))
+	return 0;
+
+    if (buf->st_nlink > 2)
+	return 1;
+
+    if (!(dirh = opendir(name)))
 	return 0;
 
     while ((de = readdir(dirh))) {

  parent reply	other threads:[~2004-04-06 17:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <9E7AF602-8085-11D8-AA68-000502631FBD@louisville.edu>
2004-04-01 18:43 ` Peter Stephenson
2004-04-01 19:26   ` DervishD
2004-04-01 22:49   ` Geoff Wing
2004-04-02  2:02     ` Geoff Wing
2004-04-06 17:27   ` Wayne Davison [this message]
2004-04-06 17:41     ` Peter Stephenson
2004-04-06 17:55   ` Wayne Davison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040406172758.GB10632@blorf.net \
    --to=wayned@users.sourceforge.net \
    --cc=pws@pwstephenson.fsnet.co.uk \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).