From nobody Thu Oct 13 08:42:56 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 4Mp31r5Qwfz4fRsx; Thu, 13 Oct 2022 08:42:56 +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 4Mp31r4sY3z3v23; Thu, 13 Oct 2022 08:42:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665650576; 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=r3UTSTOY3cFq53ye45NYVQ/HsC2Qu5b7YlldhDgH/oU=; b=FWYiKnu5DINmAlkfYfHsKfgbFE7I5dDatKCS7KATnV2PTvcKEU+DN2aIzpeb5bRPU1Q57o mHTmlvSpHtPHtbLb+Gsdwy+J/Ngkg12ubtJDDkXavW0VAhkMWvoFxJFZHsAT79boK37yyX 9xNY0xNoVN9oDsj/hDGs1a89myq9NQeWekdHBXyROkh4c8f3c4HMrIG8uOjdW5l2AqKh7m gNbHBR8pnw3DBTJRjY43YTaN47G+/7QNPvh/eoPbFTaDEzjjwNUqtmyGwuAmbe5AUbUaWF wwLiuAVp0sU7eTEgrYeKa2yGMFSu0mKM0kmUng3G3dxh59nb0wNIoGUT6wkoow== 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 4Mp31r3z5CzMfs; Thu, 13 Oct 2022 08:42:56 +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 29D8gu4G001291; Thu, 13 Oct 2022 08:42:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29D8guF3001290; Thu, 13 Oct 2022 08:42:56 GMT (envelope-from git) Date: Thu, 13 Oct 2022 08:42:56 GMT Message-Id: <202210130842.29D8guF3001290@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: ffd41d39c660 - main - sort: simplify file_reader_clean 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/main X-Git-Reftype: branch X-Git-Commit: ffd41d39c660ca1c80b77707238e8e5ef26d7d7a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665650576; 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=r3UTSTOY3cFq53ye45NYVQ/HsC2Qu5b7YlldhDgH/oU=; b=BbfEQrTe2XA0MFfjOcwJw2IcMp98JMKHDIKdo28tySuLjQlGjvNJT6/axZYQ40eMiiLSjs et8/MtRQxMwtEMwEGn/s5DoiHWdmtwt1SiWodkC4jVzG4BwGuALt3Pu68CUc0H/eDPFQpx JxdRfiezVLkLAH/4HWFfS+nc0ky0VyM/Y3z6dHVHA8L8UR7lUaKwmwhSgAnPWNHEYmQ5OG d+Q7/T+Uwc6S9EaOSoLKoWi+9kmu2FXnQEXh9+E9J4hmxCmHtebzPQatFxXo3WbSQmc7kh Y8wQJ0PhBaU5IT5UYCIAfI42TcgwLAJsjQUqtupXjGXTtd4arndH4f5hRss+aw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665650576; a=rsa-sha256; cv=none; b=NgunzTizTVk5XXFmL2Zb8RA2EyYov87h+knWYX1C024B/3VCEy+8croa1338H5mODNHPSl prL6lqH6bEYCBlJmngJRxhQrfc+1ze1uN/9tLSU8SJYmRZYsFIf/sdhYCO3ToFb20jFRvF 1JcYLdiEmvs14AftPxJS01fyOmrU2ljGlSq25f0+Yx7yL6o1wL/clt7nwvKL0rvDPOM3L6 Z0C1d8QT6bIkE4ccYorUGXvqi/4BbD7/nzwLfeYfEw/ZjcSK5SjdHDjl4emOp8C4avh1Fc XzRSm0L4OYWbgV3wlQ1r1VGcQqgGLdcE9Q0+CHbf/qh84kmXd43UuJEMFeJPLw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=ffd41d39c660ca1c80b77707238e8e5ef26d7d7a commit ffd41d39c660ca1c80b77707238e8e5ef26d7d7a Author: Baptiste Daroussin AuthorDate: 2022-10-13 08:40:21 +0000 Commit: Baptiste Daroussin CommitDate: 2022-10-13 08:42:23 +0000 sort: simplify file_reader_clean Deindent the function, remove useless tests: - free already test if argument is NULL - closefile already test if the input is stdin or null --- usr.bin/sort/file.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/usr.bin/sort/file.c b/usr.bin/sort/file.c index 8f9d8ac89b5b..0f1a9e6bad4d 100644 --- a/usr.bin/sort/file.c +++ b/usr.bin/sort/file.c @@ -574,7 +574,7 @@ openfile(const char *fn, const char *mode) void closefile(FILE *f, const char *fn) { - if (f == NULL || f = stdin) + if (f == NULL || f == stdin) return; if (f == stdout) { fflush(f); @@ -699,25 +699,18 @@ static void file_reader_clean(struct file_reader *fr) { - if (fr) { - if (fr->mmapaddr) - munmap(fr->mmapaddr, fr->mmapsize); - - if (fr->fd) - close(fr->fd); - - if (fr->buffer) - sort_free(fr->buffer); - - if (fr->file) - if (fr->file != stdin) - closefile(fr->file, fr->fname); + if (fr == NULL) + return; - if(fr->fname) - sort_free(fr->fname); + if (fr->mmapaddr) + munmap(fr->mmapaddr, fr->mmapsize); + if (fr->fd) + close(fr->fd); - memset(fr, 0, sizeof(struct file_reader)); - } + free(fr->buffer); + closefile(fr->file, fr->fname); + free(fr->fname); + memset(fr, 0, sizeof(struct file_reader)); } void