summaryrefslogtreecommitdiffstats
path: root/usr.bin/sort/sort.c
diff options
context:
space:
mode:
authortobias <tobias@openbsd.org>2015-04-03 10:37:24 +0000
committertobias <tobias@openbsd.org>2015-04-03 10:37:24 +0000
commitdf33caa0c17fa34e689abe848c4775c200c72a06 (patch)
tree799d50b25f2e9f0adb896f3aaff2291a7b78bf79 /usr.bin/sort/sort.c
parentx11/gnome/gvfs is actually a better and simpler example. (diff)
downloadwireguard-openbsd-df33caa0c17fa34e689abe848c4775c200c72a06.tar.xz
wireguard-openbsd-df33caa0c17fa34e689abe848c4775c200c72a06.zip
The combination of -c and -o is not specified by POSIX. In fact, the call
"sort -o file -c file" has unspecified behavior and would leave an empty file behind if it was sorted, the original file it was not. If -c (or -C) has been specified, only perform that action and ignore -o among other arguments. While at it, clean up check() internals. with input by and ok millert@
Diffstat (limited to 'usr.bin/sort/sort.c')
-rw-r--r--usr.bin/sort/sort.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c
index 2a959198770..49ea740f426 100644
--- a/usr.bin/sort/sort.c
+++ b/usr.bin/sort/sort.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sort.c,v 1.75 2015/04/03 10:07:25 tobias Exp $ */
+/* $OpenBSD: sort.c,v 1.76 2015/04/03 10:37:24 tobias Exp $ */
/*-
* Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org>
@@ -857,12 +857,11 @@ int
main(int argc, char *argv[])
{
char *outfile, *real_outfile, *sflag;
- int c, result;
+ int c;
size_t i;
bool mef_flags[NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS] =
{ false, false, false, false, false, false };
- result = 0;
outfile = "-";
real_outfile = NULL;
sflag = NULL;
@@ -1094,6 +1093,9 @@ main(int argc, char *argv[])
}
}
+ if (sort_opts_vals.cflag)
+ return check(argc ? *argv : "-");
+
set_random_seed();
/* Case when the outfile equals one of the input files: */
@@ -1120,7 +1122,7 @@ main(int argc, char *argv[])
}
}
- if (!sort_opts_vals.cflag && !sort_opts_vals.mflag) {
+ if (!sort_opts_vals.mflag) {
struct file_list fl;
struct sort_list list;
@@ -1158,9 +1160,7 @@ main(int argc, char *argv[])
* sort_list_clean(&list);
*/
- } else if (sort_opts_vals.cflag) {
- result = (argc == 0) ? (check("-")) : (check(*argv));
- } else if (sort_opts_vals.mflag) {
+ } else {
struct file_list fl;
file_list_init(&fl, false);
@@ -1175,5 +1175,5 @@ main(int argc, char *argv[])
sort_free(outfile);
}
- return result;
+ return 0;
}