[hatari-devel] Possible bug in GEMDOS emulation: Failing write causes subsequent reads to fail |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: Hatari Development <hatari-devel@xxxxxxxxxxxxxxxxxxx>
- Subject: [hatari-devel] Possible bug in GEMDOS emulation: Failing write causes subsequent reads to fail
- From: Christian Zietz <czietz@xxxxxxx>
- Date: Fri, 8 Jan 2021 21:11:44 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1610136705; bh=XitlcheDiS7T5H7X6zNoRdiyukFPUOKFsWZgkJHfn2s=; h=X-UI-Sender-Class:To:From:Subject:Date; b=WRFn/vX+nd0N5Y87UxYuZ5vsBwNIzSxsE9qFtywODT7oy7Uk92oTBsBu5JXTJjPbI cV+7U6KMt5IuzTa+aU9tyV6hjp1lXsmx5SqaRNo2xWFg6Mq6P2iKjzcuI/S2c2F3VI LomkWj8RvLHWxBVuDUyGeviPeVfyzgrg3At1qjPw=
Hello,
consider the minimal example below, which opens a file in read-only
mode. It's acceptable that Fwrite fails -- even though at least some
Atari GEMDOS versions do not check the Fopen mode here and let the
Fwrite succeed.
However, under Hatari's GEMDOS emulation, the following Fread() also
fails, which is a bug, imho. I get the following trace output from Hatari:
GEMDOS 0x40 Fwrite(64, 16, 0x2e94c) at PC 0x12956
WARN : GEMDOS failed to write to '[...]'
-> ERROR (errno = 9)
.... and then...
GEMDOS 0x3F Fread(64, 16, 0x2e94c) at PC 0x1296E
WARN : GEMDOS failed to read from '[...]': No error
-> ERROR (errno = 0)
.... which causes Fread to return -1. Note how it says "failed [...] no
error [...] errno = 0". Possibly this is because Hatari relies on ferror():
https://git.tuxfamily.org/hatari/hatari.git/tree/src/gemdos.c#n2335
.... but never clears the error flag with clearerr().
Regards
Christian
/* --- BEGIN EXAMPLE --- */
#include <osbind.h>
#include <stdio.h>
char buf[16];
int main(void)
{
long res, h;
res = Fopen("existing.txt", 0); /* open read-only */
printf("Fopen: %ld\r\n", res);
h = res;
res = Fwrite(h, sizeof(buf), buf); /* might fail */
printf("Fwrite: %ld\r\n", res);
res = Fread(h, sizeof(buf), buf); /* expected to succeed */
printf("Fread: %ld\r\n", res);
Fclose(h);
return 0;
}
/* --- END EXAMPLE --- */
--
Christian Zietz - CHZ-Soft - czietz@xxxxxxx
WWW: https://www.chzsoft.de/
PGP/GnuPG-Key-ID: 0x52CB97F66DA025CA / 0x6DA025CA