#1 fopencookie write handler hangs on write failure

Atvērta
xtofl atvēra 5 gadi atpakaļ · 0 komentāri
xtofl komentēja 5 gadi atpakaļ

When registering a custom stream with fopencookie(c, 'a', hooks), when the write hook reports failure, the write action will busy loop.

static ssize_t my_write(
  void *cookie,
  const char *buffer,
  size_t size)
{
  return 0; // just fail
}

....
   cookie_io_functions_t hooks = {
        .read  = &my_read,
        .write = &my_write,
        .seek  = &my_seek,
        .close = &my_close
    };

At _WRITE.c:48, we can see why it loops:

	while (todo != 0) {
		stodo = (todo <= SSIZE_MAX) ? todo : SSIZE_MAX;
		rv = __WRITE(stream, (char *) buf, stodo);
		if (rv >= 0) { ... todo-=rv; }

Am I right to think this is a non-conformance? After all, the fopencookie man page tells me I should return Zero on failure.

When registering a custom stream with `fopencookie(c, 'a', hooks)`, when the write hook reports failure, the write action will busy loop. ``` static ssize_t my_write( void *cookie, const char *buffer, size_t size) { return 0; // just fail } .... cookie_io_functions_t hooks = { .read = &my_read, .write = &my_write, .seek = &my_seek, .close = &my_close }; ``` At [_WRITE.c:48](https://git.uclibc.org/uClibc/tree/libc/stdio/_WRITE.c#n32), we can see why it loops: ``` while (todo != 0) { stodo = (todo <= SSIZE_MAX) ? todo : SSIZE_MAX; rv = __WRITE(stream, (char *) buf, stodo); if (rv >= 0) { ... todo-=rv; } ``` Am I right to think this is a non-conformance? After all, the [fopencookie man page](http://man7.org/linux/man-pages/man3/fopencookie.3.html) tells me I should return Zero on failure.
Pierakstieties, lai pievienotos šai sarunai.
Nav etiķešu
Nav atskaites punktu
Nav atbildīgā
1 dalībnieki
Notiek ielāde...
Atcelt
Saglabāt
Vēl nav satura.