Rich Felker wrote:
> > This is not hypothetical at all. The __freading, __fwriting functions
> > exist in various libcs (glibc, Solaris, uClibc, musl). But only in musl
> > the value is different in some particular case. Therefore I ask you to
>
> Would you mind telling me how it's different and how that's a problem?
> I meant for these functions to follow the traditional stdio_ext.h API,
> and if they're not doing the right thing I'd rather fix them than have
> ugly workarounds going into gnulib.
Sure. You can reproduce the issues by applying the patch I sent to a
gnulib checkout, then do
$ ./gnulib-tool --create-testdir --dir=/tmp/testdir-stdioext --with-tests
--single-configure --avoid=havelib-tests fseterr freadable fwritable fbufmode
freading fwriting freadptr freadseek freadahead fpurge fseeko ftello fpending
fflush
then
$ cd /tmp/testdir-stdioext
$ ./configure CC=musl-gcc CPPFLAGS=-Wall
$ make
$ make check
1) If I attempt to write
bool
freading (FILE *fp)
{
return __freading (fp);
}
instead of the current code
bool
freading (FILE *fp)
{
return !__fwritable (fp) || __freading (fp);
}
then I get the test failure
test-freading.c:48: assertion failed
FAIL: test-freading
2) Independently of 1): If I attempt to write
bool
fwriting (FILE *fp)
{
return __fwriting (fp);
}
instead of the current code
bool
fwriting (FILE *fp)
{
return !__freadable (fp) || __fwriting (fp);
}
then I get the test failure
test-fwriting.c:41: assertion failed
FAIL: test-fwriting
> Is the issue that you want __fwriting to return 1 even if there's no
> data buffered as long as the last action on the file was a write? If
> so, I think I can easily fix that.
For 2), the issue is that for a stream opened in write-only mode,
immediately after the fopen() call, gnulib expects fwriting(fp) to be
true:
fp = fopen (TESTFILE, "w");
if (fp == NULL)
goto skip;
ASSERT (fwriting (fp)); // <== test-fwriting.c line 41
Bruno