public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Cygwin 3.3.6: PHP's SplFileObject::fwrite seems broken
  2022-10-02  5:16 ` Hans Henrik Bergan
@ 2022-10-02  0:39   ` Ken Brown
  2022-10-02 13:58     ` Andrey Repin
  2022-10-02 13:49   ` Andrey Repin
  1 sibling, 1 reply; 7+ messages in thread
From: Ken Brown @ 2022-10-02  0:39 UTC (permalink / raw)
  To: cygwin

On 10/2/2022 1:16 AM, Hans Henrik Bergan wrote:
> ... actually i forgot that the default fopen mode is "rb"
[...]
> changing the code to SplFileObject("bug.txt", "rb");
> makes the code work

I don't think you wrote what you meant.  You're not saying that explicitly 
specifying the default value changes the behavior, are you?  Maybe you meant to 
say that the default mode is "r"?

Ken

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Cygwin 3.3.6: PHP's SplFileObject::fwrite seems broken
@ 2022-10-02  1:47 Hans Henrik Bergan
  2022-10-02  5:16 ` Hans Henrik Bergan
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Henrik Bergan @ 2022-10-02  1:47 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 578 bytes --]

running PHP 7.3.7 in Cygwin 3.3.6, and SplFileObject::fwrite seems
completely broken.
to reproduce:
$ touch bug.txt; chmod 0777 bug.txt; php -r '$o=new
SplFileObject("bug.txt");var_dump($o->fwrite("test"));var_dump(error_get_last());'
int(0)
NULL

so both fwrite() and error_get_last() failed to pick up that there was an
error,
but strace reveals:
67 487251 [main] php 1693 __set_errno: ssize_t write(int, const void*,
size_t):1350 setting errno 9
60 487311 [main] php 1693 write: -1 = write(3, 0x6FFFFFE65BF8, 4), errno 9

errno 9 probably means: 9 EBADF Bad file descriptor.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin 3.3.6: PHP's SplFileObject::fwrite seems broken
  2022-10-02  1:47 Cygwin 3.3.6: PHP's SplFileObject::fwrite seems broken Hans Henrik Bergan
@ 2022-10-02  5:16 ` Hans Henrik Bergan
  2022-10-02  0:39   ` Ken Brown
  2022-10-02 13:49   ` Andrey Repin
  0 siblings, 2 replies; 7+ messages in thread
From: Hans Henrik Bergan @ 2022-10-02  5:16 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1460 bytes --]

... actually i forgot that the default fopen mode is "rb" ... anyhow, here
is what's supposed to happen:
$ touch bug.txt; chmod 0777 bug.txt; php -r '$o=new
SplFileObject("bug.txt");var_dump($o->fwrite("test"));var_dump(error_get_last());'
PHP Notice:  SplFileObject::fwrite(): Write of 4 bytes failed with errno=9
Bad file descriptor in Command line code on line 1
bool(false)
array(4) {
  ["type"]=>
  int(8)
  ["message"]=>
  string(81) "SplFileObject::fwrite(): Write of 4 bytes failed with errno=9
Bad file descriptor"
  ["file"]=>
  string(17) "Command line code"
  ["line"]=>
  int(1)
}

changing the code to SplFileObject("bug.txt", "rb");
makes the code work, but there's still the issue with cygwin's php's
SplFileObject::fwrite() not noticing the write error

On Sat, 1 Oct 2022 at 18:47, Hans Henrik Bergan <divinity76@gmail.com>
wrote:

> running PHP 7.3.7 in Cygwin 3.3.6, and SplFileObject::fwrite seems
> completely broken.
> to reproduce:
> $ touch bug.txt; chmod 0777 bug.txt; php -r '$o=new
> SplFileObject("bug.txt");var_dump($o->fwrite("test"));var_dump(error_get_last());'
> int(0)
> NULL
>
> so both fwrite() and error_get_last() failed to pick up that there was an
> error,
> but strace reveals:
> 67 487251 [main] php 1693 __set_errno: ssize_t write(int, const void*,
> size_t):1350 setting errno 9
> 60 487311 [main] php 1693 write: -1 = write(3, 0x6FFFFFE65BF8, 4), errno 9
>
> errno 9 probably means: 9 EBADF Bad file descriptor.
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin 3.3.6: PHP's SplFileObject::fwrite seems broken
  2022-10-02  5:16 ` Hans Henrik Bergan
  2022-10-02  0:39   ` Ken Brown
@ 2022-10-02 13:49   ` Andrey Repin
  2022-10-03 16:59     ` Hans Henrik Bergan
  1 sibling, 1 reply; 7+ messages in thread
From: Andrey Repin @ 2022-10-02 13:49 UTC (permalink / raw)
  To: Hans Henrik Bergan, cygwin

Greetings, Hans Henrik Bergan!

> ... actually i forgot that the default fopen mode is "rb" ... anyhow, here
> is what's supposed to happen:
> $ touch bug.txt; chmod 0777 bug.txt; php -r '$o=new
> SplFileObject("bug.txt");var_dump($o->fwrite("test"));var_dump(error_get_last());'
> PHP Notice:  SplFileObject::fwrite(): Write of 4 bytes failed with errno=9
> Bad file descriptor in Command line code on line 1
> bool(false)
> array(4) {
>   ["type"]=>
>   int(8)
>   ["message"]=>
>   string(81) "SplFileObject::fwrite(): Write of 4 bytes failed with errno=9
> Bad file descriptor"
>   ["file"]=>
>   string(17) "Command line code"
>   ["line"]=>
>   int(1)
> }

> changing the code to SplFileObject("bug.txt", "rb");
> makes the code work, but there's still the issue with cygwin's php's
> SplFileObject::fwrite() not noticing the write error

php -d 'display_errors=stderr'
?

> On Sat, 1 Oct 2022 at 18:47, Hans Henrik Bergan <divinity76@gmail.com>
> wrote:

>> running PHP 7.3.7 in Cygwin 3.3.6, and SplFileObject::fwrite seems
>> completely broken.
>> to reproduce:
>> $ touch bug.txt; chmod 0777 bug.txt; php -r '$o=new
>> SplFileObject("bug.txt");var_dump($o->fwrite("test"));var_dump(error_get_last());'
>> int(0)
>> NULL
>>
>> so both fwrite() and error_get_last() failed to pick up that there was an
>> error,
>> but strace reveals:
>> 67 487251 [main] php 1693 __set_errno: ssize_t write(int, const void*,
>> size_t):1350 setting errno 9
>> 60 487311 [main] php 1693 write: -1 = write(3, 0x6FFFFFE65BF8, 4), errno 9
>>
>> errno 9 probably means: 9 EBADF Bad file descriptor.
>>



-- 
With best regards,
Andrey Repin
Sunday, October 2, 2022 16:49:02

Sorry for my terrible english...


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin 3.3.6: PHP's SplFileObject::fwrite seems broken
  2022-10-02  0:39   ` Ken Brown
@ 2022-10-02 13:58     ` Andrey Repin
  0 siblings, 0 replies; 7+ messages in thread
From: Andrey Repin @ 2022-10-02 13:58 UTC (permalink / raw)
  To: Ken Brown, cygwin

Greetings, Ken Brown!

> On 10/2/2022 1:16 AM, Hans Henrik Bergan wrote:
>> ... actually i forgot that the default fopen mode is "rb"
> [...]
>> changing the code to SplFileObject("bug.txt", "rb");
>> makes the code work

> I don't think you wrote what you meant.  You're not saying that explicitly
> specifying the default value changes the behavior, are you?  Maybe you meant to say that the default mode is "r"?

"b" is always assumed, unless "t" is explicitly given.

I just checked and I can't get the code to work even if I manually specify the
open mode.

While Windows PHP version displays the notice as it should:

$ php -d "error_reporting=-1" -d "display_errors=stderr" -r '(new SplFileObject("test.txt"))->fwrite("test");'
PHP Notice:  SplFileObject::fwrite(): write of 4 bytes failed with errno=9 Bad file descriptor in Command line code on line 1


-- 
With best regards,
Andrey Repin
Sunday, October 2, 2022 16:49:51

Sorry for my terrible english...


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin 3.3.6: PHP's SplFileObject::fwrite seems broken
  2022-10-02 13:49   ` Andrey Repin
@ 2022-10-03 16:59     ` Hans Henrik Bergan
  2022-10-08 17:21       ` Ken Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Henrik Bergan @ 2022-10-03 16:59 UTC (permalink / raw)
  To: cygwin

@Ken Brown
>I don't think you wrote what you meant. You're not saying that explicitly specifying the default value changes the behavior, are you? Maybe you meant to say that the default mode is "r"?

sorry about that, i meant "ab" makes the code work.

@Andrey Repin
>php -d 'display_errors=stderr'
>?

adding -d 'display_errors=stderr'  does not make any difference. still
int(0) NULL


On Sun, 2 Oct 2022 at 15:50, Andrey Repin <anrdaemon@yandex.ru> wrote:
>
> Greetings, Hans Henrik Bergan!
>
> > ... actually i forgot that the default fopen mode is "rb" ... anyhow, here
> > is what's supposed to happen:
> > $ touch bug.txt; chmod 0777 bug.txt; php -r '$o=new
> > SplFileObject("bug.txt");var_dump($o->fwrite("test"));var_dump(error_get_last());'
> > PHP Notice:  SplFileObject::fwrite(): Write of 4 bytes failed with errno=9
> > Bad file descriptor in Command line code on line 1
> > bool(false)
> > array(4) {
> >   ["type"]=>
> >   int(8)
> >   ["message"]=>
> >   string(81) "SplFileObject::fwrite(): Write of 4 bytes failed with errno=9
> > Bad file descriptor"
> >   ["file"]=>
> >   string(17) "Command line code"
> >   ["line"]=>
> >   int(1)
> > }
>
> > changing the code to SplFileObject("bug.txt", "rb");
> > makes the code work, but there's still the issue with cygwin's php's
> > SplFileObject::fwrite() not noticing the write error
>
> php -d 'display_errors=stderr'
> ?
>
> > On Sat, 1 Oct 2022 at 18:47, Hans Henrik Bergan <divinity76@gmail.com>
> > wrote:
>
> >> running PHP 7.3.7 in Cygwin 3.3.6, and SplFileObject::fwrite seems
> >> completely broken.
> >> to reproduce:
> >> $ touch bug.txt; chmod 0777 bug.txt; php -r '$o=new
> >> SplFileObject("bug.txt");var_dump($o->fwrite("test"));var_dump(error_get_last());'
> >> int(0)
> >> NULL
> >>
> >> so both fwrite() and error_get_last() failed to pick up that there was an
> >> error,
> >> but strace reveals:
> >> 67 487251 [main] php 1693 __set_errno: ssize_t write(int, const void*,
> >> size_t):1350 setting errno 9
> >> 60 487311 [main] php 1693 write: -1 = write(3, 0x6FFFFFE65BF8, 4), errno 9
> >>
> >> errno 9 probably means: 9 EBADF Bad file descriptor.
> >>
>
>
>
> --
> With best regards,
> Andrey Repin
> Sunday, October 2, 2022 16:49:02
>
> Sorry for my terrible english...
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin 3.3.6: PHP's SplFileObject::fwrite seems broken
  2022-10-03 16:59     ` Hans Henrik Bergan
@ 2022-10-08 17:21       ` Ken Brown
  0 siblings, 0 replies; 7+ messages in thread
From: Ken Brown @ 2022-10-08 17:21 UTC (permalink / raw)
  To: cygwin

On 10/3/2022 12:59 PM, Hans Henrik Bergan wrote:
> @Ken Brown
>> I don't think you wrote what you meant. You're not saying that explicitly specifying the default value changes the behavior, are you? Maybe you meant to say that the default mode is "r"?
> 
> sorry about that, i meant "ab" makes the code work.
> 
> @Andrey Repin
>> php -d 'display_errors=stderr'
>> ?
> 
> adding -d 'display_errors=stderr'  does not make any difference. still
> int(0) NULL

Someone needs to debug this.  Unfortunately, php currently has no Cygwin 
maintainer.  Are you able to run php under gdb to see what's going on?  Even 
better, are you interested in taking over as the php maintainer?

If not, I might try debugging this at some point.  But I have quite a bit of 
Real Life going on at the moment, so I don't know when I'll get to it.

Ken

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-10-08 17:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-02  1:47 Cygwin 3.3.6: PHP's SplFileObject::fwrite seems broken Hans Henrik Bergan
2022-10-02  5:16 ` Hans Henrik Bergan
2022-10-02  0:39   ` Ken Brown
2022-10-02 13:58     ` Andrey Repin
2022-10-02 13:49   ` Andrey Repin
2022-10-03 16:59     ` Hans Henrik Bergan
2022-10-08 17:21       ` Ken Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).