summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMartijn van Duren <martijn@cvs.openbsd.org>2017-12-08 18:42:00 +0000
committerMartijn van Duren <martijn@cvs.openbsd.org>2017-12-08 18:42:00 +0000
commit979e8005668683554b987d772216f59381a6bb19 (patch)
treef10b61505f6218d22a50ad63a1de615d0e79b087 /usr.bin
parenta7d48a3649b8b1ad6eb592be08777cbc2d003cfb (diff)
Make the r command filename obligatory, similar to what FreeBSD and NetBSD
do for several years. While here make corresponding error message for missing read and write file consistent between commands/flag, and shrink the the code of the w flag of the s command by making it use the same code as the w command. Prompted by a larger diff by kshe59 <at> zoho <dot> eu OK millert@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sed/compile.c32
-rw-r--r--usr.bin/sed/sed.16
2 files changed, 12 insertions, 26 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index 0671805865e..f994049ac1b 100644
--- a/usr.bin/sed/compile.c
+++ b/usr.bin/sed/compile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: compile.c,v 1.42 2017/08/01 18:05:53 martijn Exp $ */
+/* $OpenBSD: compile.c,v 1.43 2017/12/08 18:41:59 martijn Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -277,6 +277,8 @@ nonsel: /* Now parse the command */
pledge_rpath = 1;
p++;
EATSPACE();
+ if (*p == '\0')
+ error(COMPILE, "filename expected");
cmd->t = duptoeol(p, "read command", NULL);
break;
case BRANCH: /* b t */
@@ -539,7 +541,6 @@ compile_flags(char *p, struct s_subst *s)
{
int gn; /* True if we have seen g or n */
long l;
- char wfile[PATH_MAX], *q, *eq;
s->n = 1; /* Default */
s->p = 0;
@@ -577,32 +578,17 @@ compile_flags(char *p, struct s_subst *s)
continue;
case 'w':
p++;
-#ifdef HISTORIC_PRACTICE
- if (*p != ' ') {
- warning("space missing before w wfile");
- return (p);
- }
-#endif
EATSPACE();
- q = wfile;
- eq = wfile + sizeof(wfile) - 1;
- while (*p) {
- if (*p == '\n')
- break;
- if (q >= eq)
- error(COMPILE, "wfile too long");
- *q++ = *p++;
- }
- *q = '\0';
- if (q == wfile)
- error(COMPILE, "no wfile specified");
- s->wfile = strdup(wfile);
+ if (*p == '\0')
+ error(COMPILE, "filename expected");
+ s->wfile = duptoeol(p, "s command w flag", NULL);
+ *p = '\0';
if (aflag)
pledge_wpath = 1;
- else if ((s->wfd = open(wfile,
+ else if ((s->wfd = open(s->wfile,
O_WRONLY|O_APPEND|O_CREAT|O_TRUNC,
DEFFILEMODE)) == -1)
- error(FATAL, "%s: %s", wfile, strerror(errno));
+ error(FATAL, "%s: %s", s->wfile, strerror(errno));
return (p);
default:
error(COMPILE,
diff --git a/usr.bin/sed/sed.1 b/usr.bin/sed/sed.1
index aa765281bba..5e91484f217 100644
--- a/usr.bin/sed/sed.1
+++ b/usr.bin/sed/sed.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sed.1,v 1.51 2017/12/07 09:52:26 martijn Exp $
+.\" $OpenBSD: sed.1,v 1.52 2017/12/08 18:41:59 martijn Exp $
.\"
.\" Copyright (c) 1992, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -32,7 +32,7 @@
.\"
.\" from: @(#)sed.1 8.2 (Berkeley) 12/30/93
.\"
-.Dd $Mdocdate: December 7 2017 $
+.Dd $Mdocdate: December 8 2017 $
.Dt SED 1
.Os
.Sh NAME
@@ -255,7 +255,7 @@ as well as the
flag to the
.Ic s
function,
-take an optional
+take a
.Ar file
parameter,
which should be separated from the function or flag by whitespace.