Bug 32657

Summary: sed file handing is non-standard
Product: Base System Reporter: ihaka <ihaka>
Component: binAssignee: Ceri Davies <ceri>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.2-RELEASE   
Hardware: Any   
OS: Any   

Description ihaka 2001-12-09 23:10:02 UTC
        The sed manual entry says:

          The ``r'' and ``w'' functions take an optional file parameter,
          which should be separated from the function letter by white
          space.  Each file given as an argument to sed is created
          (or its contents truncated) before any input processing
          begins.

        Under FreeBSD (and possibly other BSD systems) the file parameter
        is mandatory -- sed terminates with an error message if an
        editing command of one of the forms
                /pattern/r
                /pattern/w
        is encountered.  Other sed versions (e.g. GNU and Solaris) silently
        ignore such constructions.

        This kind constructions appears in scripts generated by autoconf
        which work on other platforms, but not FreeBSD.

Fix: 

In /usr/src/usr.bin/sed/compile.c in the function compile_stream,
        (cases WFILE and RFILE) there are lines

                        if (*p == '\0')
                                errx(1, "%lu: %s: filename expected", linenum, fname);
                        else
                                cmd->t = duptoeol(p, "read command");

        removing the first three of these lines will cause the filename
        "" to be passed on for later processing.  This will produce
        the same effect as specifying a file which does not exist
        (the problem is silently ignored).

        This change would produce a warning message from duptoeol about
        trailing white space.  This message does not seem to occur in
        other sed variants.
How-To-Repeat: 
        Utter the command:
                sed '/pattern/r'
Comment 1 Sheldon Hearn freebsd_committer freebsd_triage 2001-12-10 12:11:02 UTC
State Changed
From-To: open->feedback

FreeBSD's sed(1) demands a file parameter because it's not optional for 
the w flag in POSIX.2 ('92 edition).  The semantics for the r flag are 
taken from the w flag. 

This change would meet with less resistence if you could find a more 
recent standard that prescribes optional arguments to the w flag (and 
possible the r flag). 

If you need help getting such information, try the freebsd-standards 
mailing list.
Comment 2 Ceri Davies freebsd_committer freebsd_triage 2003-06-08 19:02:24 UTC
State Changed
From-To: feedback->closed

Feedback timeout (6 months or more). 
I will handle any feedback that this closure generates. 


Comment 3 Ceri Davies freebsd_committer freebsd_triage 2003-06-08 19:02:24 UTC
Responsible Changed
From-To: freebsd-bugs->ceri

Feedback timeout (6 months or more). 
I will handle any feedback that this closure generates.