Date: Sun, 14 Jan 2001 23:16:29 -0700 From: Warner Losh <imp@harmony.village.org> To: Ben Smithurst <ben@FreeBSD.ORG> Cc: "W.H.Scholten" <whs@xs4all.nl>, Alfred Perlstein <bright@wintelcom.net>, freebsd-hackers@FreeBSD.ORG Subject: Re: pppd & mkdir diff Message-ID: <200101150616.f0F6GTs15360@harmony.village.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>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200101150616.f0F6GTs15360>