From patchwork Sat Aug 17 15:38:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jordi Sanfeliu X-Patchwork-Id: 96033 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8614D3861012 for ; Sat, 17 Aug 2024 15:39:44 +0000 (GMT) X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mail.fibranet.cat (www.fibranet.cat [88.99.13.26]) by sourceware.org (Postfix) with ESMTPS id 8EE0B3860761 for ; Sat, 17 Aug 2024 15:39:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EE0B3860761 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=fibranet.cat Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=fibranet.cat ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8EE0B3860761 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=88.99.13.26 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723909169; cv=none; b=Q2vLrmAz4mjG6Woqd+aASeS6gpUBQ2jnlHe7hDtPvJWfTjVag8kKWVXWU2vLYr0VlLT2qjlcriMxnw9NvJBHOYpJd2fUUtCp8abSjNflETWh4TgQPYFN8TV65J86YFFjtg2YIyRBzwEG9ikrpCVNtIN6kiLPDEzEQyyPcCCDB0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723909169; c=relaxed/simple; bh=wMmsniOfN5D6KpMCC5RxN5gqF8HvlcVn2NirxxqOUjo=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=cXhIUtKOW3obZOvQePVGkWnSjNsAzWN3F/Po3T2HOWB4uL4Izsb5pfnyVWk3yJwu25CBgkb3K5GUDloJYiKK00gqVYv2IfCSaR6yQWoSxBwqAuJfHa5piGJTbi0WGfAFBgwg6OD5Ve6tye7Xjfbkd93ZIfTNsZcN1TEL1lXeTo4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from linux.home.lan (194.red-83-41-46.dynamicip.rima-tde.net [83.41.46.194]) (authenticated bits=0) by mail.fibranet.cat (8.15.2/8.15.2) with ESMTPSA id 47HFcNj33100363 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Sat, 17 Aug 2024 17:39:24 +0200 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.fibranet.cat 47HFcNj33100363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fibranet.cat; s=default; t=1723909164; bh=wMmsniOfN5D6KpMCC5RxN5gqF8HvlcVn2NirxxqOUjo=; h=Date:From:To:Subject:From; b=khlk7/femquHCezhW6MMmSIYOwjOf0/CQ7sFfJ5zPOJHjPTtMmj1U/pLDqITMzEBl zoQQ4zB5weAuJBhflpovWf7BQsPltpMBMT5d/M91YCD2IdxsAGJJZ7ncXvCBFRNbxF K+CIOmFx04UrrIedmweBr6+wUsKnf6jM/V32Dogw= Date: Sat, 17 Aug 2024 17:38:22 +0200 (CEST) From: Jordi Sanfeliu To: newlib@sourceware.org Subject: [PATCH] Fix glob() function Message-ID: <9fe43c91-5dae-0806-d245-b1bcf4014057@fibranet.cat> MIME-Version: 1.0 X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.2 (mail.fibranet.cat [88.99.13.26]); Sat, 17 Aug 2024 17:39:24 +0200 (CEST) X-FibraNet-MailScanner-Information: FibraNet E-Mail Virus Protection Service X-FibraNet-MailScanner-ID: 47HFcNj33100363 X-FibraNet-MailScanner: Found to be clean X-FibraNet-MailScanner-SpamCheck: X-FibraNet-MailScanner-From: jordi@fibranet.cat X-FibraNet-MailScanner-Watermark: 1724513965.67727@HCXgnWzcnZUstEGSXB6Ysg X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org Hello, While porting 'mandoc' [1] to my hobbyOS FiwixOS, I've discovered that the glob() function in Newlib always returns zero (success) even when the pathname was not found. I was comparing the file 'libc/posix/glob.c' with the one from Apple [2] and then I applied the following patch: The following is a simple test program: # cat glob.c #include #include int main(void) { int globres; glob_t globinfo; char *ok1 = "/usr/share/man/man1/ls.[01-9]*"; char *ko1 = "/usr/share/man/man1/lsx.[01-9]*"; char *ok2 = "glob.c"; char *ko2 = "glob.x"; globres = glob(ok1, 0, NULL, &globinfo); printf("globres = %d (%s)\n", globres, ok1); globres = glob(ko1, 0, NULL, &globinfo); printf("globres = %d (%s)\n", globres, ko1); globres = glob(ok2, 0, NULL, &globinfo); printf("globres = %d (%s)\n", globres, ok2); globres = glob(ko2, 0, NULL, &globinfo); printf("globres = %d (%s)\n", globres, ko2); return 0; } The results before applying the patch were: # ./glob globres = 0 (/usr/share/man/man1/ls.[01-9]*) globres = 0 (/usr/share/man/man1/lsx.[01-9]*) globres = 0 (glob.c) globres = 0 (glob.x) The results after applying the patch are: # ./glob globres = 0 (/usr/share/man/man1/ls.[01-9]*) globres = 3 (/usr/share/man/man1/lsx.[01-9]*) globres = 0 (glob.c) globres = 3 (glob.x) Thanks. [1] https://mandoc.bsd.lv/ [2] https://opensource.apple.com/source/Libinfo/Libinfo-129/util.subproj/glob.c --- Jordi Sanfeliu FIBRANET Network Services Provider https://www.fibranet.cat diff --git a/newlib/libc/posix/glob.c b/newlib/libc/posix/glob.c index 5e6c2fcba..0347979de 100644 --- a/newlib/libc/posix/glob.c +++ b/newlib/libc/posix/glob.c @@ -502,11 +502,14 @@ glob0(pattern, pglob, limit) * and the pattern did not contain any magic characters * GLOB_NOMAGIC is there just for compatibility with csh. */ - if (pglob->gl_pathc == oldpathc && - ((pglob->gl_flags & GLOB_NOCHECK) || - ((pglob->gl_flags & GLOB_NOMAGIC) && - !(pglob->gl_flags & GLOB_MAGCHAR)))) - return(globextend(pattern, pglob, limit)); + if (pglob->gl_pathc == oldpathc) { + if (((pglob->gl_flags & GLOB_NOCHECK) || + ((pglob->gl_flags & GLOB_NOMAGIC) && + !(pglob->gl_flags & GLOB_MAGCHAR)))) + return(globextend(pattern, pglob, limit)); + else + return(3); /* GLOB_NOMATCH */ + } else if (!(pglob->gl_flags & GLOB_NOSORT)) qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, pglob->gl_pathc - oldpathc, sizeof(char *), compare);