From a8752029f60217a5c41c548b16f5cdd2a1a0e0db Mon Sep 17 00:00:00 2001 From: Emily Trau Date: Mon, 22 May 2023 21:30:22 +1000 Subject: [PATCH] Backport `uniq` fopen patch --- sysa/coreutils-5.0/coreutils-5.0.checksums | 2 +- sysa/coreutils-5.0/coreutils-5.0.kaem | 8 +++ sysa/coreutils-5.0/patches/uniq-fopen.patch | 68 +++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 sysa/coreutils-5.0/patches/uniq-fopen.patch diff --git a/sysa/coreutils-5.0/coreutils-5.0.checksums b/sysa/coreutils-5.0/coreutils-5.0.checksums index 4814bf7..bdf8ab6 100644 --- a/sysa/coreutils-5.0/coreutils-5.0.checksums +++ b/sysa/coreutils-5.0/coreutils-5.0.checksums @@ -45,7 +45,7 @@ e2683f200a8c14eef6d92d6ee3b4fdbc48b4f1cf5ea58ccab57259f6b8a315d5 /usr/bin/tee ff9492d8e088acf1a689e907c9550ba78029a778bd2818674d4989cddbc28853 /usr/bin/tr 159651d7a72db3e4752ee184288c55a1fee0484443aa67e4f3a9984ad7320e78 /usr/bin/tsort 9f6f55239fa384564f78347b70c1287310283121446d63071045f6fd3eac90b1 /usr/bin/unexpand -5c1e4bdda086d0e8ed79c35183f36ea1f223a07e0c723037a7efd3b46ac2228a /usr/bin/uniq +58b692ef7cc3f644eca0b21cd792ac6037202788e9bcee1204ba155a750e27ca /usr/bin/uniq 1c6c0306829c5c0695d9e5336682aac3494eb78b86b0806fb8b94b4edbe9e670 /usr/bin/unlink c601ba79b716d782bd8f01e2e3804bd2a66fdc6519c7c27dc709def51558ed53 /usr/bin/wc 762c3ac63eeafd49de5f324b16b1895167110e2ddee553c6f5198c7d71880caf /usr/bin/whoami diff --git a/sysa/coreutils-5.0/coreutils-5.0.kaem b/sysa/coreutils-5.0/coreutils-5.0.kaem index efb83fd..4e9c626 100755 --- a/sysa/coreutils-5.0/coreutils-5.0.kaem +++ b/sysa/coreutils-5.0/coreutils-5.0.kaem @@ -42,6 +42,7 @@ patch -Np0 -i ../../patches/touch-dereference.patch patch -Np0 -i ../../patches/tac-uint64.patch patch -Np0 -i ../../patches/expr-strcmp.patch patch -Np0 -i ../../patches/sort-locale.patch +patch -Np0 -i ../../patches/uniq-fopen.patch # Build and install make -f Makefile PREFIX=${prefix} @@ -61,12 +62,16 @@ if match x${UPDATE_CHECKSUMS} xTrue; then /usr/bin/cp \ /usr/bin/csplit \ /usr/bin/cut \ + /usr/bin/dirname \ /usr/bin/echo \ /usr/bin/expand \ + /usr/bin/expr \ + /usr/bin/factor \ /usr/bin/false \ /usr/bin/fmt \ /usr/bin/fold \ /usr/bin/head \ + /usr/bin/hostname \ /usr/bin/id \ /usr/bin/join \ /usr/bin/kill \ @@ -80,6 +85,7 @@ if match x${UPDATE_CHECKSUMS} xTrue; then /usr/bin/od \ /usr/bin/paste \ /usr/bin/pathchk \ + /usr/bin/pr \ /usr/bin/printf \ /usr/bin/ptx \ /usr/bin/pwd \ @@ -87,6 +93,7 @@ if match x${UPDATE_CHECKSUMS} xTrue; then /usr/bin/rmdir \ /usr/bin/seq \ /usr/bin/sleep \ + /usr/bin/sort \ /usr/bin/split \ /usr/bin/sum \ /usr/bin/tail \ @@ -94,6 +101,7 @@ if match x${UPDATE_CHECKSUMS} xTrue; then /usr/bin/tr \ /usr/bin/tsort \ /usr/bin/unexpand \ + /usr/bin/uniq \ /usr/bin/unlink \ /usr/bin/wc \ /usr/bin/whoami \ diff --git a/sysa/coreutils-5.0/patches/uniq-fopen.patch b/sysa/coreutils-5.0/patches/uniq-fopen.patch new file mode 100644 index 0000000..8a393f4 --- /dev/null +++ b/sysa/coreutils-5.0/patches/uniq-fopen.patch @@ -0,0 +1,68 @@ +SPDX-FileCopyrightText: 2005 Paul Eggert +SPDX-FileCopyrightText: 2023 Emily Trau + +SPDX-License-Identifier: GPL-2.0-or-later + +uniq: don't assume fopen cannot return stdin or stdout. +Backport of https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=786ebb2ceca72f69aa2de701671fb41f53cb1489 + +--- src/uniq.c ++++ src/uniq.c +@@ -30,6 +30,7 @@ + #include "error.h" + #include "hard-locale.h" + #include "posixver.h" ++#include "stdio-safer.h" + #include "xmemcoll.h" + #include "xstrtol.h" + #include "memcasecmp.h" +@@ -267,20 +268,26 @@ check_file (const char *infile, const char *outfile) + FILE *ostream; + struct linebuffer lb1, lb2; + struct linebuffer *thisline, *prevline; ++ bool is_stdin = STREQ (infile, "-"); ++ bool is_stdout = STREQ (outfile, "-"); + +- if (STREQ (infile, "-")) ++ if (is_stdin) + istream = stdin; + else +- istream = fopen (infile, "r"); +- if (istream == NULL) +- error (EXIT_FAILURE, errno, "%s", infile); ++ { ++ istream = fopen_safer (infile, "r"); ++ if (! istream) ++ error (EXIT_FAILURE, errno, "%s", infile); ++ } + +- if (STREQ (outfile, "-")) ++ if (is_stdout) + ostream = stdout; + else +- ostream = fopen (outfile, "w"); +- if (ostream == NULL) +- error (EXIT_FAILURE, errno, "%s", outfile); ++ { ++ ostream = fopen_safer (outfile, "w"); ++ if (! ostream) ++ error (EXIT_FAILURE, errno, "%s", outfile); ++ } + + thisline = &lb1; + prevline = &lb2; +@@ -377,12 +384,12 @@ check_file (const char *infile, const char *outfile) + } + + closefiles: +- if (ferror (istream) || fclose (istream) == EOF) ++ if (!is_stdin && (ferror (istream) || fclose (istream) != 0)) + error (EXIT_FAILURE, errno, _("error reading %s"), infile); + + /* Close ostream only if it's not stdout -- the latter is closed + via the atexit-invoked close_stdout. */ +- if (ostream != stdout && (ferror (ostream) || fclose (ostream) == EOF)) ++ if (!is_stdout && (ferror (ostream) || fclose (ostream) != 0)) + error (EXIT_FAILURE, errno, _("error writing %s"), outfile); + + free (lb1.buffer);