From nobody Wed Oct 19 08:01:32 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 4MsjqJ5Cpwz4gDM0; Wed, 19 Oct 2022 08:01:32 +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 4MsjqJ4WDbz3y8F; Wed, 19 Oct 2022 08:01:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666166492; 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=WBag85taKeudMtLZkqBETgshiY0InH3K2barero7ack=; b=aCH1r/exaxOH2lOW0ZbhsA0mSJeLjRch2+az38+FICNPzhv2N89wY6gThz5N7Y55lwaOvj qNQor6xYyju3VyumlhcsWsjfGWefMZmV0GT2ctXHAJSZywV7x2U2IpYP0YuxUQ1CTri2YZ ffr5gCd9Yu8pBAovMU3aaY0aGx2R16LtCfPdoKPcOg8yzt7QKNgMz/pj0yGOCv4AQXRSzy BRkrN8FwR6aM1W5iH8VzgkD+2NkIz+c1bo0WF0jknshX6lELKwAtBDfh/cmhdI8bB9QN/z E19D0ctnpIVPrKdNaXdxZPFcesQaLrOmKCBVD+WDxtxHxEYvFHGZskC9qm/WZw== 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 4MsjqJ3dMyzSZx; Wed, 19 Oct 2022 08:01:32 +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 29J81W4F061316; Wed, 19 Oct 2022 08:01:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29J81WbL061315; Wed, 19 Oct 2022 08:01:32 GMT (envelope-from git) Date: Wed, 19 Oct 2022 08:01:32 GMT Message-Id: <202210190801.29J81WbL061315@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: 2afc73005cb2 - stable/13 - sort: unify the code to read from FILE * 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: bapt X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2afc73005cb2c288a2445af6be10484e14ea7409 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666166492; 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=WBag85taKeudMtLZkqBETgshiY0InH3K2barero7ack=; b=lTlvjf6XL9emVUTpYkYe8Stxjza6OrzvwvY3W4JlJcK5ie929B4JzMaVadykpTUItBDT0p xrjKyAa/naNdQ3qfh5FLtNhlnwbh7vn7pFkIo/2BXobgp0oaub9YFTSZ25pObM+nIQMPoM oHVGmfZPGwwi3YlZcbbxr4xeE2bNClB2LZh4lo6rGIqcaK/+0STGYvKeReFbJyg0FSC1DV 8Tp1ZpRg2+L69Xf+E5pQkFCX9z7FCHuWpyDVI+8+YQvHJAB2WoKaEbU4RZYqRsgYOOlCUW r3Ijtl1Q5NrHmBqdIrAfKGsvD8MZMhK/344q0lMCefw+wExABBWUbIY3fnGnIg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666166492; a=rsa-sha256; cv=none; b=UF7x5tbQhrG+gZZ2HOZEr54KH6xE4Yq/zSjltR4Mg8qwyuVEW3Wt8ygl04vUaZ6hO0SGTh 9dGO0HuTGgP7e7NX4bHpxSyl5rhbTyrE+/e0+JsqOhEBclb9JAmraBobqfq2PfSQolJy6t goAmb4SiphDrSXx0kuFz0HygsRrm0Eaa/BSEIZBpTrTu403tWmBocPdPst6FcsEQ+jVGlY jz+dxIv5jup38ghhN3bDVcN3E2pTqYkFRQIqHUpJNqOuYWL9KQtaS8AMVYdxzgFqoZrvrr ppX78/m5fQIWGgoBHmVggaZz1ZuzARAXklqty2DZoJZMCxKhKfngvvSj70BJrA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=2afc73005cb2c288a2445af6be10484e14ea7409 commit 2afc73005cb2c288a2445af6be10484e14ea7409 Author: Baptiste Daroussin AuthorDate: 2022-10-13 07:36:48 +0000 Commit: Baptiste Daroussin CommitDate: 2022-10-19 07:59:29 +0000 sort: unify the code to read from FILE * Previously the code to read from a local file or stdin was sperarated After the change to remove the home made line reader used for stdin (replaced by getdelim) it apprears that the rest of the code which is used to read from any FILE * but stdin can benefit from the exact same change. (cherry picked from commit 8b9071360a312f2bb2104864af0b9905acac87bc) --- usr.bin/sort/file.c | 94 ----------------------------------------------------- 1 file changed, 94 deletions(-) diff --git a/usr.bin/sort/file.c b/usr.bin/sort/file.c index b48948e1edee..437be09819b5 100644 --- a/usr.bin/sort/file.c +++ b/usr.bin/sort/file.c @@ -62,26 +62,18 @@ const char *compress_program; size_t max_open_files = 16; -/* - * How much space we read from file at once - */ -#define READ_CHUNK (4096) - /* * File reader structure */ struct file_reader { - struct reader_buffer rb; FILE *file; char *fname; char *buffer; unsigned char *mmapaddr; unsigned char *mmapptr; size_t bsz; - size_t cbsz; size_t mmapsize; - size_t strbeg; int fd; char elsymb; }; @@ -663,19 +655,6 @@ file_reader_init(const char *fsrc) ret->file = openfile(fsrc, "r"); if (ret->file == NULL) err(2, NULL); - - if (strcmp(fsrc, "-")) { - ret->cbsz = READ_CHUNK; - ret->buffer = sort_malloc(ret->cbsz); - ret->bsz = 0; - ret->strbeg = 0; - - ret->bsz = fread(ret->buffer, 1, ret->cbsz, ret->file); - if (ret->bsz == 0) { - if (ferror(ret->file)) - err(2, NULL); - } - } } return (ret); @@ -708,79 +687,6 @@ file_reader_readline(struct file_reader *fr) fr->mmapptr = strend + 1; } } - - } else if (fr->file != stdin) { - char *strend; - size_t bsz1, remsz, search_start; - - search_start = 0; - remsz = 0; - strend = NULL; - - if (fr->bsz > fr->strbeg) - remsz = fr->bsz - fr->strbeg; - - /* line read cycle */ - for (;;) { - if (remsz > search_start) - strend = memchr(fr->buffer + fr->strbeg + - search_start, fr->elsymb, remsz - - search_start); - else - strend = NULL; - - if (strend) - break; - if (feof(fr->file)) - break; - - if (fr->bsz != fr->cbsz) - /* NOTREACHED */ - err(2, "File read software error 1"); - - if (remsz > (READ_CHUNK >> 1)) { - search_start = fr->cbsz - fr->strbeg; - fr->cbsz += READ_CHUNK; - fr->buffer = sort_realloc(fr->buffer, - fr->cbsz); - bsz1 = fread(fr->buffer + fr->bsz, 1, - READ_CHUNK, fr->file); - if (bsz1 == 0) { - if (ferror(fr->file)) - err(2, NULL); - break; - } - fr->bsz += bsz1; - remsz += bsz1; - } else { - if (remsz > 0 && fr->strbeg>0) - bcopy(fr->buffer + fr->strbeg, - fr->buffer, remsz); - - fr->strbeg = 0; - search_start = remsz; - bsz1 = fread(fr->buffer + remsz, 1, - fr->cbsz - remsz, fr->file); - if (bsz1 == 0) { - if (ferror(fr->file)) - err(2, NULL); - break; - } - fr->bsz = remsz + bsz1; - remsz = fr->bsz; - } - } - - if (strend == NULL) - strend = fr->buffer + fr->bsz; - - if ((fr->buffer + fr->strbeg <= strend) && - (fr->strbeg < fr->bsz) && (remsz>0)) - ret = bwscsbdup(fr->buffer + fr->strbeg, strend - - fr->buffer - fr->strbeg); - - fr->strbeg = (strend - fr->buffer) + 1; - } else { ssize_t len;