From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10286 invoked by alias); 8 Mar 2011 12:01:32 -0000 Received: (qmail 10263 invoked by uid 22791); 8 Mar 2011 12:01:31 -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-qy0-f169.google.com (HELO mail-qy0-f169.google.com) (209.85.216.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 08 Mar 2011 12:01:26 +0000 Received: by qyk2 with SMTP id 2so2974023qyk.0 for ; Tue, 08 Mar 2011 04:01:25 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.102.165 with SMTP id g37mr3901623qco.120.1299585684861; Tue, 08 Mar 2011 04:01:24 -0800 (PST) Received: by 10.229.89.197 with HTTP; Tue, 8 Mar 2011 04:01:24 -0800 (PST) In-Reply-To: References: Date: Tue, 08 Mar 2011 12:48: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 gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-03/txt/msg00530.txt.bz2 2011/3/8 Eli Zaretskii : >> Date: Tue, 8 Mar 2011 12:25:37 +0100 >> From: Kai Tietz >> Cc: binutils@sourceware.org, gdb-patches@sourceware.org, >> =A0 =A0 =A0 gcc-patches@gcc.gnu.org >> >> > 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. > > We are miscommunicating. =A0I was asking when would a program want to > find the _first_ directory separator character in a file name. > Searching for the last one is a frequent use case: when you want to > create a file in the same directory as another, or when you are > looking for a basename of a file. =A0But when do you need the first > slash? See for example remote-fileio.c in remote_fileio_extract_ptr_w_len() as an example. There is more then one use-case. >> >> + =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) > > But in strrchr-case, r2 cannot be greater than r1 if it is NULL, > right? It can. It is a matter of signness of pointer comparision. Regards, Kai