From nobody Thu Sep 15 05:31:31 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MSm5v6X9Zz4c4Y9; Thu, 15 Sep 2022 05:31:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MSm5v5yDBz3Clj; Thu, 15 Sep 2022 05:31:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663219891; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=blb8KoiPKb9c/gDZ64E/+wTiu57sgvWQus97iiYOmTg=; b=UtDhaQ6ioGgfddcN8BQZ4ElvQ5FAwKTjji4G73Pm4Y+k6J95F7MhpyxoAfrWim/coVOrY9 m3b16KkJ+bt8/rM2Vyh2O7ZOLy46nFm6gWWFLEnyVfgNk8n4ks7oFOFhcBDZiHcxHIKJ9W m4SeuArbNGRoeMz1k/FJy61bYAsKhq4XIZ3UGJuNwJF5lfS3TJnA8VX3azAw8PORhBhoF8 LBZ91HAx2kjCsKZbvIidvSwOqvlR7e9zkaTOwZHENOXK+ZFnLvOiszuvcyKBRkJp1JnpAh uoU5E5KC4jINNbl8ita+dIMpPItJEv6zgtkf8gP1fYueuGrUk9V36e5z0zBZrA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MSm5v50nbzvf3; Thu, 15 Sep 2022 05:31:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 28F5VVrA024963; Thu, 15 Sep 2022 05:31:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28F5VVA8024962; Thu, 15 Sep 2022 05:31:31 GMT (envelope-from git) Date: Thu, 15 Sep 2022 05:31:31 GMT Message-Id: <202209150531.28F5VVA8024962@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Xin LI Subject: git: df4d33ecaac4 - stable/13 - MFV: cherry-pick "PR/358: Fix width for -f - (jpalus)" List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: delphij X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: df4d33ecaac46330250472c096714f717950879c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663219891; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=blb8KoiPKb9c/gDZ64E/+wTiu57sgvWQus97iiYOmTg=; b=G/UvZaT05U9VIJ48O1TDUA/Wh+Zv/CDKn3Z49kRGk6XxpdO6rIICoKk1YiXuAVbsSFhNzI ALr2IvaO+PcqovIM8+2Z9aBVO58iStgv4NojAWXUwxdDy47JF2gtLIXeDup2l96tkAjlqT nnKXcdz9pB/dwJDZhBH2g/o9cUv7lauwFWwGWZTumjnkn0uHWfgJB1PJVibf4esnFWtJb6 Kzrh3Fu1vWwd3qMsUYQK4hpjykXaHk2cTq56JvHwZaGUxTsbjeeCsASyYpeLHerLCth3oi JCHgvUmKOzbluSMTPx2MsBWZBzUEYzWUy8HdEux+sLQzmN+lmvfonyNI7ThqGw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663219891; a=rsa-sha256; cv=none; b=oCWr2TXrlh4MvTZLrXBMcdFHMIkpITYl2V620txSA4Pf1sM67Ui4P8DG8Pkqgh+yk1B3PR +Phmcak9CxZfrym4gxh0DYMdOvXPC0kjqjRKcQMlrBojFx+ZG5S+7Nvayfn26Ip1ZfjiKl y9ljv+XlWIH02hMFiEPNPL2Bj8t7NrNQ5JA1+QP/TmPGnZC0JasGm+U3PDs5bExXRJ9vvk K7w9bDRgprxsajPJFp7vMR0d+47AONFOj0jPlFHWG3mVmQ0yPcqKHHvh7e2HUVgRVYtYlq Fy2eu8aBB2iyUDERbGohW0F9FlvZlf2c+ioa7DF434nmxfdppWiC2Y339WSgLg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by delphij: URL: https://cgit.FreeBSD.org/src/commit/?id=df4d33ecaac46330250472c096714f717950879c commit df4d33ecaac46330250472c096714f717950879c Author: Xin LI AuthorDate: 2022-09-07 06:31:20 +0000 Commit: Xin LI CommitDate: 2022-09-15 05:31:13 +0000 MFV: cherry-pick "PR/358: Fix width for -f - (jpalus)" PR: bin/266264 (cherry picked from commit bced4d8b3e99efd46b5496c83e11755b25913c90) --- contrib/file/src/file.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/contrib/file/src/file.c b/contrib/file/src/file.c index 5300e5af8edf..bb058ce1e008 100644 --- a/contrib/file/src/file.c +++ b/contrib/file/src/file.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: file.c,v 1.195 2022/06/02 15:45:43 christos Exp $") +FILE_RCSID("@(#)$File: file.c,v 1.196 2022/07/04 17:00:51 christos Exp $") #endif /* lint */ #include "magic.h" @@ -506,35 +506,47 @@ unwrap(struct magic_set *ms, const char *fn) size_t llen = 0; int wid = 0, cwid; int e = 0; + size_t fi = 0, fimax = 100; + char **flist = malloc(sizeof(*flist) * fimax); - if (strcmp("-", fn) == 0) { + if (flist == NULL) +out: file_err(EXIT_FAILURE, "Cannot allocate memory for file list"); + + if (strcmp("-", fn) == 0) f = stdin; - wid = 1; - } else { + else { if ((f = fopen(fn, "r")) == NULL) { file_warn("Cannot open `%s'", fn); return 1; } - - while ((len = getline(&line, &llen, f)) > 0) { - if (line[len - 1] == '\n') - line[len - 1] = '\0'; - cwid = file_mbswidth(ms, line); - if (cwid > wid) - wid = cwid; - } - - rewind(f); } while ((len = getline(&line, &llen, f)) > 0) { if (line[len - 1] == '\n') line[len - 1] = '\0'; - e |= process(ms, line, wid); + if (fi >= fimax) { + fimax += 100; + char **nf = realloc(flist, fimax * sizeof(*flist)); + if (nf == NULL) + goto out; + } + flist[fi++] = line; + cwid = file_mbswidth(ms, line); + if (cwid > wid) + wid = cwid; + line = NULL; + llen = 0; + } + + fimax = fi; + for (fi = 0; fi < fimax; fi++) { + e |= process(ms, flist[fi], wid); + free(flist[fi]); } + free(flist); - free(line); - (void)fclose(f); + if (f != stdin) + (void)fclose(f); return e; }