#1 fopencookie write handler hangs on write failure

Open
opened 5 years ago by xtofl · 0 comments
xtofl commented 5 years ago

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.
Sign in to join this conversation.
No Label
No Milestone
No assignee
1 Participants
Loading...
Cancel
Save
There is no content yet.