Date: Sun, 12 Aug 2001 16:48:43 -0400 From: Mike Barcroft <mike@FreeBSD.org> To: Akinori MUSHA <knu@iDaemons.org> Cc: audit@FreeBSD.org Subject: Re: adding -P option to pkg_delete(1) Message-ID: <20010812164843.A29363@coffee.q9media.com> In-Reply-To: <86snex15o4.wl@archon.local.idaemons.org>; from knu@iDaemons.org on Mon, Aug 13, 2001 at 03:42:19AM %2B0900 References: <86elqphctp.wl@archon.local.idaemons.org> <86d761hijs.wl@archon.local.idaemons.org> <20010812140750.B29132@coffee.q9media.com> <86snex15o4.wl@archon.local.idaemons.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010812164843.A29363>