summaryrefslogtreecommitdiff
path: root/usr.bin/sort/fsort.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2007-08-21 20:29:26 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2007-08-21 20:29:26 +0000
commit0df3625d865331b4ff1bf7380d5f4d559c3b4a00 (patch)
treebbd7955675441a044c881fc75a092861e1c4a730 /usr.bin/sort/fsort.c
parentdfb00039258dd8343fd60b3699f5f75209e74662 (diff)
Add a -s option to make the radix sort be a stable sort. Based on
a diff from Eric Gouyer. Closes PR 5553. OK deraadt@
Diffstat (limited to 'usr.bin/sort/fsort.c')
-rw-r--r--usr.bin/sort/fsort.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/usr.bin/sort/fsort.c b/usr.bin/sort/fsort.c
index d706dd44ab5..e9811471088 100644
--- a/usr.bin/sort/fsort.c
+++ b/usr.bin/sort/fsort.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fsort.c,v 1.18 2007/03/13 17:33:58 millert Exp $ */
+/* $OpenBSD: fsort.c,v 1.19 2007/08/21 20:29:25 millert Exp $ */
/*-
* Copyright (c) 1993
@@ -36,7 +36,7 @@
#if 0
static char sccsid[] = "@(#)fsort.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: fsort.c,v 1.18 2007/03/13 17:33:58 millert Exp $";
+static char rcsid[] = "$OpenBSD: fsort.c,v 1.19 2007/08/21 20:29:25 millert Exp $";
#endif
#endif /* not lint */
@@ -173,9 +173,17 @@ fsort(int binno, int depth, union f_handle infiles, int nfiles, FILE *outfp,
}
get = getnext;
if (!ntfiles && !mfct) { /* everything in memory--pop */
- if (nelem > 1 && radixsort((const u_char **)keylist,
- nelem, weights, REC_D))
- err(2, NULL);
+ if (nelem > 1) {
+ if (STABLE) {
+ i = sradixsort((const u_char **)keylist,
+ nelem, weights, REC_D);
+ } else {
+ i = radixsort((const u_char **)keylist,
+ nelem, weights, REC_D);
+ }
+ if (i)
+ err(2, NULL);
+ }
append(keylist, nelem, depth, outfp, putline, ftbl);
break; /* pop */
}