return bytes_read;
}
-static ssize_t pakfire_pty_send_line(struct pakfire_pty* self,
- struct pakfire_pty_stdio* stdio, const char* buffer, ssize_t length) {
- int r;
-
- // Call the callback
- r = stdio->callbacks.stdout_callback(self->ctx, stdio->callbacks.data, buffer, length);
- if (r < 0)
- return r;
-
- // We have consumed the entire line
- return length;
-}
-
/*
Writes as much data as possible from the buffer
*/
static int pakfire_pty_drain_buffer(struct pakfire_pty* pty, int fd, struct pakfire_pty_stdio* stdio) {
ssize_t bytes_written = 0;
- char* eol = NULL;
// Map any CRNL to just NL
if (stdio->io & PAKFIRE_PTY_MAP_CRNL)
// Call the callback if possible
if (stdio->callbacks.stdout_callback) {
- // Try finding the end of a line
- eol = memchr(stdio->buffer, '\n', stdio->buffered);
-
- // No newline found
- if (!eol) {
- if (!pakfire_pty_buffer_is_full(pty, stdio))
- return -ENOMSG;
-
- DEBUG(pty->ctx, "Buffer is full. Sending all content\n");
- eol = stdio->buffer + stdio->buffered - 1;
- }
-
// Send the line
- bytes_written = pakfire_pty_send_line(pty, stdio, stdio->buffer, eol - stdio->buffer + 1);
+ bytes_written = stdio->callbacks.stdout_callback(pty->ctx,
+ stdio->callbacks.data, stdio->buffer, stdio->buffered);
// Abort on error
if (bytes_written < 0)
}
break;
- // This is a special hack for when we have data in the buffer
- // but cannot send it to the callback, yet, because we have not
- // read to the end of the line.
- // To avoid getting stuck in this loop for forever, we simply
- // exit and let the loop call us again.
- case ENOMSG:
- break;
- // return 0;
-
default:
ERROR(pty->ctx, "Failed writing to standard output: %s\n", strerror(-r));
goto ERROR;