Module Name: src
Committed By: dholland
Date: Thu May 27 05:52:29 UTC 2010
Modified Files:
src/usr.bin/sort: init.c
Log Message:
Don't recognize "+3" after -- or after the first non-option argument.
This prevents converting "+3" into "-k4.1" in places where getopt
won't recognize it, which in turn prevents silly error messages and
lossage trying to sort files whose names begin with +. PR 43358.
To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/sort/init.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/sort/init.c
diff -u src/usr.bin/sort/init.c:1.24 src/usr.bin/sort/init.c:1.25
--- src/usr.bin/sort/init.c:1.24 Fri Nov 6 18:34:22 2009
+++ src/usr.bin/sort/init.c Thu May 27 05:52:29 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.24 2009/11/06 18:34:22 joerg Exp $ */
+/* $NetBSD: init.c,v 1.25 2010/05/27 05:52:29 dholland Exp $ */
/*-
* Copyright (c) 2000-2003 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
#include "sort.h"
-__RCSID("$NetBSD: init.c,v 1.24 2009/11/06 18:34:22 joerg Exp $");
+__RCSID("$NetBSD: init.c,v 1.25 2010/05/27 05:52:29 dholland Exp $");
#include <ctype.h>
#include <string.h>
@@ -249,6 +249,16 @@
size_t sz;
for (i = 1; i < *argc; i++) {
+ /*
+ * Stop where getopt will stop, to avoid turning e.g.
+ * "sort x +3" into "sort x -k4.1" which will croak if
+ * +3 was in fact really a file name.
+ */
+ if (argv[i][0] == '-' && argv[i][1] == '-')
+ break;
+ if (argv[i][0] != '-' && argv[i][0] != '+')
+ break;
+
if (argv[i][0] != '+' && !fplus)
continue;