From owner-freebsd-hackers Sun Jan 14 22:16:48 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from harmony.village.org (rover.village.org [204.144.255.66]) by hub.freebsd.org (Postfix) with ESMTP id 880B437B400; Sun, 14 Jan 2001 22:16:30 -0800 (PST) Received: from harmony.village.org (localhost.village.org [127.0.0.1]) by harmony.village.org (8.11.1/8.11.1) with ESMTP id f0F6GTs15360; Sun, 14 Jan 2001 23:16:29 -0700 (MST) (envelope-from imp@harmony.village.org) Message-Id: <200101150616.f0F6GTs15360@harmony.village.org> To: Ben Smithurst Subject: Re: pppd & mkdir diff Cc: "W.H.Scholten" , Alfred Perlstein , freebsd-hackers@FreeBSD.ORG In-reply-to: Your message of "Sun, 14 Jan 2001 06:11:20 GMT." <20010114061120.K35575@strontium.scientia.demon.co.uk> References: <20010114061120.K35575@strontium.scientia.demon.co.uk> <3A6025F1.794BDF32@xs4all.nl> <3A5C843C.794BDF32@xs4all.nl> <20010111132509.J7240@fw.wintelcom.net> <3A5EE6B1.41C67EA6@xs4all.nl> <20010112081422.U7240@fw.wintelcom.net> <3A6025F1.794BDF32@xs4all.nl> <200101140355.f0E3tIs95857@harmony.village.org> Date: Sun, 14 Jan 2001 23:16:29 -0700 From: Warner Losh Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In message <20010114061120.K35575@strontium.scientia.demon.co.uk> Ben Smithurst writes: : while (path[strlen(path) - 1] == '/') : path[strlen(path) - 1] = 0; : : :-) Preferably '\0' too of course like you say later. Yes. Actually, I'd do this like: cp = path + strlen(path) - 1; while (cp > path && *cp == '/') *cp-- = '\0'; Since it doesn't have the buffer overflow the above code does in the '////' case. It also gets that case right (if my mental walkthrough can be truested). A nice side effect is that it doesn't call strlen N times making it a O(N) algorythm, rather than an O(N^2) algorythm. Likely only of secondary importance since most strings don't contain lots of // in them :-). Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message