From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7867 invoked by alias); 8 Mar 2011 11:25:45 -0000 Received: (qmail 7808 invoked by uid 22791); 8 Mar 2011 11:25:43 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST X-Spam-Check-By: sourceware.org Received: from mail-qw0-f41.google.com (HELO mail-qw0-f41.google.com) (209.85.216.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 08 Mar 2011 11:25:39 +0000 Received: by qwd7 with SMTP id 7so4942359qwd.0 for ; Tue, 08 Mar 2011 03:25:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.141.71 with SMTP id l7mr3892018qcu.44.1299583537441; Tue, 08 Mar 2011 03:25:37 -0800 (PST) Received: by 10.229.89.197 with HTTP; Tue, 8 Mar 2011 03:25:37 -0800 (PST) In-Reply-To: References: Date: Tue, 08 Mar 2011 11:25:00 -0000 Message-ID: Subject: Re: [patch libiberty include]: Add additional helper functions for directory-separator searching From: Kai Tietz To: Eli Zaretskii Cc: binutils@sourceware.org, gdb-patches@sourceware.org, gcc-patches@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2011-03/txt/msg00110.txt.bz2 2011/3/8 Eli Zaretskii : >> Date: Tue, 8 Mar 2011 11:56:45 +0100 >> From: Kai Tietz >> >> +@deftypefn Extension int filename_dirchr (const char *@var{p}) >> + >> +The returned value is similar to what @code{strchr} would return for >> +searching for a directory separator. >> + >> +This function does not normalize file name. =A0However, it does handle >> +the fact that on DOS-like file systems, forward and backward slashes >> +are directory separators. > > This is very mysterious. =A0The documentation should explain how this is > "handled", or else the user will have no choice but to look in the > sources. =A0And description "by similarity" doesn't help, because this > function is obviously different from strchr in _some_ ways, but you > don't say how. > > While at that, explain the problem this solves, or else the raison > d'etre of this function will not be understood. =A0We do want this > function to be used instead of just strchr, don't we? =A0For it to be > used, its purpose and advantages should be well understood. > > Btw, why do we need filename_dirchr? =A0The use case for > filename_dirrchr is clear, but in what situations will we need the > other one? As the comment notes. strchr/strrchr searches for one character. This is for unix-file-system normally slash. On DOS based file-systems there are two characters representing a directory-separator. Slash and Backslash. Therefore this routine takes care that both are handled similiar to a single character searching. >> + =A0if (!r || (r2 && r2 < r)) > > Why do you test for r2 being non-NULL? =A0You are not going to > dereference it in the next comparison, and NULL is comparable as any > other value. As if we found slash, we don't want to override function's result by backslash not found. If the null-check wouldn't be present condition would be always true for r2 =3D=3D NULL as, NULL is always less then a pointer. But r shall be modified only if r2 (backslash) was found before r (slash). (same logic but here from right to left for the strrchr-case) Regards, Kai