#1 fopencookie write handler hangs on write failure

Ouvert
Créé il y a 5 ans par xtofl · 0 commentaires
xtofl a commenté il y a 5 ans

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.
Connectez-vous pour rejoindre cette conversation.
Pas d'étiquette
Aucun jalon
Pas d'assignataire
1 Participants
Chargement…
Annuler
Enregistrer
Il n'existe pas encore de contenu.