From owner-freebsd-audit Sun Aug 12 13:27:57 2001 Delivered-To: freebsd-audit@freebsd.org Received: from coffee.q9media.com (coffee.q9media.com [216.94.229.19]) by hub.freebsd.org (Postfix) with ESMTP id E2C2D37B408 for ; Sun, 12 Aug 2001 13:27:53 -0700 (PDT) (envelope-from mike@coffee.q9media.com) Received: (from mike@localhost) by coffee.q9media.com (8.11.2/8.11.2) id f7CKmhS29533; Sun, 12 Aug 2001 16:48:43 -0400 (EDT) (envelope-from mike) Date: Sun, 12 Aug 2001 16:48:43 -0400 From: Mike Barcroft To: Akinori MUSHA Cc: audit@FreeBSD.org Subject: Re: adding -P option to pkg_delete(1) Message-ID: <20010812164843.A29363@coffee.q9media.com> Mail-Followup-To: Mike Barcroft , Akinori MUSHA , audit@FreeBSD.org References: <86elqphctp.wl@archon.local.idaemons.org> <86d761hijs.wl@archon.local.idaemons.org> <20010812140750.B29132@coffee.q9media.com> <86snex15o4.wl@archon.local.idaemons.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <86snex15o4.wl@archon.local.idaemons.org>; from knu@iDaemons.org on Mon, Aug 13, 2001 at 03:42:19AM +0900 Organization: The FreeBSD Project Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Mon, Aug 13, 2001 at 03:42:19AM +0900, Akinori MUSHA wrote: > > This could probably be written better, so that you don't have to walk > > filename so many times. > > Yes, alternatively you could write it as follows, for example: > > /* [^\/]\.so(\.\d+)*$ */ > static Boolean > is_shlib(char *filename) > { > char *p; > > p = strrchr(filename, 's'); > > if (p == NULL || p[1] != 'o' || > p - filename < 2 || p[-1] != '.' || p[-2] == '/') > return FALSE; > > p += 2; > > /* skip version numbers */ > while (*p) { > if (*p != '.' || !isdigit(*++p)) > return FALSE; > while (isdigit(*++p)) > ; > } > > return TRUE; > } > > (But I don't like this ;) Neither do I. Mostly because you could be accessing memory before filename starts. I was thinking more along the lines of: /* * Returns TRUE if filename matches /\.so$/ or /\.so\.\d+$/, otherwise FALSE. */ static Boolean is_shlib(const char *filename) { int digit; char *p; digit = 0; p = (char *)filename + strlen(filename); while (--p > filename && isdigit(*p)) digit = 1; if (p - 1 <= filename) return FALSE; if (digit && *p == '.') p--; if (p - 2 > filename && strncmp(p - 2, ".so", 3) == 0) return TRUE; else return FALSE; } Best regards, Mike Barcroft To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message