FAQ
This adds a warning when the 3-arg form of open is used
to open a reference. open() then dies and $! == EINVAL.

There are 3 points to be checked :
* is the VMS error value (LIB$_INVARG) OK ?
* the case
open FOO, '>&', \*STDOUT
is specifically skipped -- the patch tests the
presence of '&' in the 2d argument. Is it OK ?
* Phrasing of the perldiag patch ?


--- pod/perldiag.pod.orig Wed Apr 10 21:25:02 2002
+++ pod/perldiag.pod Thu Apr 18 22:37:31 2002
@@ -862,6 +862,16 @@ =head1 DESCRIPTION
is because you don't have read permission for a file which you named on
the command line.

+=item Can't open a reference
+
+(W io) You tried to open a scalar reference for reading or writing,
+using the 3-arg open() syntax :
+
+ open FH, '>', $ref;
+
+but your version of perl is compiled without perlio, and this form of
+open is not supported.
+
=item Can't open bidirectional pipe

(W pipe) You tried to say C<open(CMD, "|cmd|")>, which is not supported.
--- t/lib/warnings/doio.orig Sun Feb 3 17:37:05 2002
+++ t/lib/warnings/doio Thu Apr 18 23:12:46 2002
@@ -228,3 +228,22 @@
$a = eof STDOUT ;
EXPECT
Filehandle STDOUT opened only for output at - line 3.
+########
+# doio.c [Perl_do_openn]
+use Config;
+BEGIN {
+ if ($Config{useperlio}) {
+ print <<EOM;
+SKIPPED
+warns only without perlio
+EOM
+ exit;
+ }
+}
+use warnings 'io';
+my $x = "foo";
+open FOO, '>', \$x;
+no warnings 'io';
+open FOO, '>', \$x;
+EXPECT
+Can't open a reference at - line 14.
--- doio.c.orig Tue Mar 26 22:03:32 2002
+++ doio.c Thu Apr 18 23:05:21 2002
@@ -213,6 +213,15 @@ Perl_do_openn(pTHX_ GV *gv, register cha
if (num_svs) {
/* New style explict name, type is just mode and discipline/layer info */
STRLEN l = 0;
+#ifdef USE_STDIO
+ if (SvROK(*svp) && !strchr(name,'&')) {
+ if (ckWARN(WARN_IO))
+ Perl_warner(aTHX_ packWARN(WARN_IO),
+ "Can't open a reference");
+ SETERRNO(EINVAL, LIB$_INVARG);
+ goto say_false;
+ }
+#endif /* USE_STDIO */
name = SvOK(*svp) ? SvPV(*svp, l) : "";
len = (I32)l;
name = savepvn(name, len);

Search Discussions

  • Jarkko Hietaniemi at Apr 19, 2002 at 1:56 pm

    On Thu, Apr 18, 2002 at 11:17:44PM +0200, Rafael Garcia-Suarez wrote:
    This adds a warning when the 3-arg form of open is used
    to open a reference. open() then dies and $! == EINVAL.

    There are 3 points to be checked :
    * is the VMS error value (LIB$_INVARG) OK ?
    * the case
    open FOO, '>&', \*STDOUT
    is specifically skipped -- the patch tests the
    presence of '&' in the 2d argument. Is it OK ?
    * Phrasing of the perldiag patch ?
    Looks good to me. (I assume some earlier logic has already sanity
    checked the syntax of the second argument.)

    --
    $jhi++; # http://www.iki.fi/jhi/
    # There is this special biologist word we use for 'stable'.
    # It is 'dead'. -- Jack Cohen
  • Rgarciasuarez at Apr 19, 2002 at 2:53 pm

    Quoting Jarkko Hietaniemi <jhi@iki.fi>:
    There are 3 points to be checked :
    * is the VMS error value (LIB$_INVARG) OK ?
    * the case
    open FOO, '>&', \*STDOUT
    is specifically skipped -- the patch tests the
    presence of '&' in the 2d argument. Is it OK ?
    * Phrasing of the perldiag patch ?
    Looks good to me. (I assume some earlier logic has already sanity
    checked the syntax of the second argument.)
    If the 2nd argument is meaningless, perl dies with
    "Unknown open() mode '%s'". But I don't know [yet] the exact
    list of valid modes. The list given by perldiag is incomplete.

    OK, I'll look a bit more at this this evening.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedApr 18, '02 at 9:18p
activeApr 19, '02 at 2:53p
posts3
users2
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase