Backport `uniq` fopen patch
This commit is contained in:
parent
87e9d7db9d
commit
a8752029f6
|
@ -45,7 +45,7 @@ e2683f200a8c14eef6d92d6ee3b4fdbc48b4f1cf5ea58ccab57259f6b8a315d5 /usr/bin/tee
|
||||||
ff9492d8e088acf1a689e907c9550ba78029a778bd2818674d4989cddbc28853 /usr/bin/tr
|
ff9492d8e088acf1a689e907c9550ba78029a778bd2818674d4989cddbc28853 /usr/bin/tr
|
||||||
159651d7a72db3e4752ee184288c55a1fee0484443aa67e4f3a9984ad7320e78 /usr/bin/tsort
|
159651d7a72db3e4752ee184288c55a1fee0484443aa67e4f3a9984ad7320e78 /usr/bin/tsort
|
||||||
9f6f55239fa384564f78347b70c1287310283121446d63071045f6fd3eac90b1 /usr/bin/unexpand
|
9f6f55239fa384564f78347b70c1287310283121446d63071045f6fd3eac90b1 /usr/bin/unexpand
|
||||||
5c1e4bdda086d0e8ed79c35183f36ea1f223a07e0c723037a7efd3b46ac2228a /usr/bin/uniq
|
58b692ef7cc3f644eca0b21cd792ac6037202788e9bcee1204ba155a750e27ca /usr/bin/uniq
|
||||||
1c6c0306829c5c0695d9e5336682aac3494eb78b86b0806fb8b94b4edbe9e670 /usr/bin/unlink
|
1c6c0306829c5c0695d9e5336682aac3494eb78b86b0806fb8b94b4edbe9e670 /usr/bin/unlink
|
||||||
c601ba79b716d782bd8f01e2e3804bd2a66fdc6519c7c27dc709def51558ed53 /usr/bin/wc
|
c601ba79b716d782bd8f01e2e3804bd2a66fdc6519c7c27dc709def51558ed53 /usr/bin/wc
|
||||||
762c3ac63eeafd49de5f324b16b1895167110e2ddee553c6f5198c7d71880caf /usr/bin/whoami
|
762c3ac63eeafd49de5f324b16b1895167110e2ddee553c6f5198c7d71880caf /usr/bin/whoami
|
||||||
|
|
|
@ -42,6 +42,7 @@ patch -Np0 -i ../../patches/touch-dereference.patch
|
||||||
patch -Np0 -i ../../patches/tac-uint64.patch
|
patch -Np0 -i ../../patches/tac-uint64.patch
|
||||||
patch -Np0 -i ../../patches/expr-strcmp.patch
|
patch -Np0 -i ../../patches/expr-strcmp.patch
|
||||||
patch -Np0 -i ../../patches/sort-locale.patch
|
patch -Np0 -i ../../patches/sort-locale.patch
|
||||||
|
patch -Np0 -i ../../patches/uniq-fopen.patch
|
||||||
|
|
||||||
# Build and install
|
# Build and install
|
||||||
make -f Makefile PREFIX=${prefix}
|
make -f Makefile PREFIX=${prefix}
|
||||||
|
@ -61,12 +62,16 @@ if match x${UPDATE_CHECKSUMS} xTrue; then
|
||||||
/usr/bin/cp \
|
/usr/bin/cp \
|
||||||
/usr/bin/csplit \
|
/usr/bin/csplit \
|
||||||
/usr/bin/cut \
|
/usr/bin/cut \
|
||||||
|
/usr/bin/dirname \
|
||||||
/usr/bin/echo \
|
/usr/bin/echo \
|
||||||
/usr/bin/expand \
|
/usr/bin/expand \
|
||||||
|
/usr/bin/expr \
|
||||||
|
/usr/bin/factor \
|
||||||
/usr/bin/false \
|
/usr/bin/false \
|
||||||
/usr/bin/fmt \
|
/usr/bin/fmt \
|
||||||
/usr/bin/fold \
|
/usr/bin/fold \
|
||||||
/usr/bin/head \
|
/usr/bin/head \
|
||||||
|
/usr/bin/hostname \
|
||||||
/usr/bin/id \
|
/usr/bin/id \
|
||||||
/usr/bin/join \
|
/usr/bin/join \
|
||||||
/usr/bin/kill \
|
/usr/bin/kill \
|
||||||
|
@ -80,6 +85,7 @@ if match x${UPDATE_CHECKSUMS} xTrue; then
|
||||||
/usr/bin/od \
|
/usr/bin/od \
|
||||||
/usr/bin/paste \
|
/usr/bin/paste \
|
||||||
/usr/bin/pathchk \
|
/usr/bin/pathchk \
|
||||||
|
/usr/bin/pr \
|
||||||
/usr/bin/printf \
|
/usr/bin/printf \
|
||||||
/usr/bin/ptx \
|
/usr/bin/ptx \
|
||||||
/usr/bin/pwd \
|
/usr/bin/pwd \
|
||||||
|
@ -87,6 +93,7 @@ if match x${UPDATE_CHECKSUMS} xTrue; then
|
||||||
/usr/bin/rmdir \
|
/usr/bin/rmdir \
|
||||||
/usr/bin/seq \
|
/usr/bin/seq \
|
||||||
/usr/bin/sleep \
|
/usr/bin/sleep \
|
||||||
|
/usr/bin/sort \
|
||||||
/usr/bin/split \
|
/usr/bin/split \
|
||||||
/usr/bin/sum \
|
/usr/bin/sum \
|
||||||
/usr/bin/tail \
|
/usr/bin/tail \
|
||||||
|
@ -94,6 +101,7 @@ if match x${UPDATE_CHECKSUMS} xTrue; then
|
||||||
/usr/bin/tr \
|
/usr/bin/tr \
|
||||||
/usr/bin/tsort \
|
/usr/bin/tsort \
|
||||||
/usr/bin/unexpand \
|
/usr/bin/unexpand \
|
||||||
|
/usr/bin/uniq \
|
||||||
/usr/bin/unlink \
|
/usr/bin/unlink \
|
||||||
/usr/bin/wc \
|
/usr/bin/wc \
|
||||||
/usr/bin/whoami \
|
/usr/bin/whoami \
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
SPDX-FileCopyrightText: 2005 Paul Eggert <eggert@cs.ucla.edu>
|
||||||
|
SPDX-FileCopyrightText: 2023 Emily Trau <emily@downunderctf.com>
|
||||||
|
|
||||||
|
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);
|
Loading…
Reference in New Issue