aboutsummaryrefslogtreecommitdiffhomepage
path: root/io.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-11-18 16:30:30 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-11-18 16:30:30 -0800
commit9992b8eb0e3366ff8a3948aa0b66a19c3c12c737 (patch)
tree6dda0fef85812016fbba9ea067c9d586092b506d /io.cpp
parentbab69f26724028d16054a3daf5c78aad7c67bb2d (diff)
Apply new indentation, brace, and whitespace style
Diffstat (limited to 'io.cpp')
-rw-r--r--io.cpp199
1 files changed, 101 insertions, 98 deletions
diff --git a/io.cpp b/io.cpp
index 525f438b..704c4c05 100644
--- a/io.cpp
+++ b/io.cpp
@@ -51,78 +51,78 @@ Utilities for io redirection.
#include "io.h"
-void io_buffer_read( io_data_t *d )
+void io_buffer_read(io_data_t *d)
{
- exec_close(d->param1.pipe_fd[1] );
+ exec_close(d->param1.pipe_fd[1]);
- if( d->io_mode == IO_BUFFER )
- {
-/* if( fcntl( d->param1.pipe_fd[0], F_SETFL, 0 ) )
+ if (d->io_mode == IO_BUFFER)
{
- wperror( L"fcntl" );
- return;
- } */
- debug( 4, L"io_buffer_read: blocking read on fd %d", d->param1.pipe_fd[0] );
- while(1)
- {
- char b[4096];
- long l;
- l=read_blocked( d->param1.pipe_fd[0], b, 4096 );
- if( l==0 )
- {
- break;
- }
- else if( l<0 )
- {
- /*
- exec_read_io_buffer is only called on jobs that have
- exited, and will therefore never block. But a broken
- pipe seems to cause some flags to reset, causing the
- EOF flag to not be set. Therefore, EAGAIN is ignored
- and we exit anyway.
- */
- if( errno != EAGAIN )
+ /* if( fcntl( d->param1.pipe_fd[0], F_SETFL, 0 ) )
+ {
+ wperror( L"fcntl" );
+ return;
+ } */
+ debug(4, L"io_buffer_read: blocking read on fd %d", d->param1.pipe_fd[0]);
+ while (1)
{
- debug( 1,
- _(L"An error occured while reading output from code block on file descriptor %d"),
- d->param1.pipe_fd[0] );
- wperror( L"io_buffer_read" );
- }
+ char b[4096];
+ long l;
+ l=read_blocked(d->param1.pipe_fd[0], b, 4096);
+ if (l==0)
+ {
+ break;
+ }
+ else if (l<0)
+ {
+ /*
+ exec_read_io_buffer is only called on jobs that have
+ exited, and will therefore never block. But a broken
+ pipe seems to cause some flags to reset, causing the
+ EOF flag to not be set. Therefore, EAGAIN is ignored
+ and we exit anyway.
+ */
+ if (errno != EAGAIN)
+ {
+ debug(1,
+ _(L"An error occured while reading output from code block on file descriptor %d"),
+ d->param1.pipe_fd[0]);
+ wperror(L"io_buffer_read");
+ }
- break;
- }
- else
- {
- d->out_buffer_append( b, l );
- }
+ break;
+ }
+ else
+ {
+ d->out_buffer_append(b, l);
+ }
+ }
}
- }
}
-io_data_t *io_buffer_create( bool is_input )
+io_data_t *io_buffer_create(bool is_input)
{
bool success = true;
- io_data_t *buffer_redirect = new io_data_t;
- buffer_redirect->out_buffer_create();
- buffer_redirect->io_mode = IO_BUFFER;
- buffer_redirect->is_input = is_input ? true : false;
- buffer_redirect->fd=is_input?0:1;
-
- if( exec_pipe( buffer_redirect->param1.pipe_fd ) == -1 )
- {
- debug( 1, PIPE_ERROR );
- wperror (L"pipe");
- success = false;
- }
- else if( fcntl( buffer_redirect->param1.pipe_fd[0],
- F_SETFL,
- O_NONBLOCK ) )
- {
- debug( 1, PIPE_ERROR );
- wperror( L"fcntl" );
- success = false;
- }
+ io_data_t *buffer_redirect = new io_data_t;
+ buffer_redirect->out_buffer_create();
+ buffer_redirect->io_mode = IO_BUFFER;
+ buffer_redirect->is_input = is_input ? true : false;
+ buffer_redirect->fd=is_input?0:1;
+
+ if (exec_pipe(buffer_redirect->param1.pipe_fd) == -1)
+ {
+ debug(1, PIPE_ERROR);
+ wperror(L"pipe");
+ success = false;
+ }
+ else if (fcntl(buffer_redirect->param1.pipe_fd[0],
+ F_SETFL,
+ O_NONBLOCK))
+ {
+ debug(1, PIPE_ERROR);
+ wperror(L"fcntl");
+ success = false;
+ }
if (! success)
{
@@ -130,28 +130,28 @@ io_data_t *io_buffer_create( bool is_input )
buffer_redirect = NULL;
}
- return buffer_redirect;
+ return buffer_redirect;
}
-void io_buffer_destroy( io_data_t *io_buffer )
+void io_buffer_destroy(io_data_t *io_buffer)
{
- /**
- If this is an input buffer, then io_read_buffer will not have
- been called, and we need to close the output fd as well.
- */
- if( io_buffer->is_input )
- {
- exec_close(io_buffer->param1.pipe_fd[1] );
- }
-
- exec_close( io_buffer->param1.pipe_fd[0] );
-
- /*
- Dont free fd for writing. This should already be free'd before
- calling exec_read_io_buffer on the buffer
- */
- delete io_buffer;
+ /**
+ If this is an input buffer, then io_read_buffer will not have
+ been called, and we need to close the output fd as well.
+ */
+ if (io_buffer->is_input)
+ {
+ exec_close(io_buffer->param1.pipe_fd[1]);
+ }
+
+ exec_close(io_buffer->param1.pipe_fd[0]);
+
+ /*
+ Dont free fd for writing. This should already be free'd before
+ calling exec_read_io_buffer on the buffer
+ */
+ delete io_buffer;
}
void io_chain_t::remove(const io_data_t *element)
@@ -218,31 +218,32 @@ void io_print(const io_chain_t &chain)
}
fprintf(stderr, "Chain %p (%ld items):\n", &chain, (long)chain.size());
- for (size_t i=0; i < chain.size(); i++) {
+ for (size_t i=0; i < chain.size(); i++)
+ {
const io_data_t *io = chain.at(i);
fprintf(stderr, "\t%lu: fd:%d, input:%s, ", (unsigned long)i, io->fd, io->is_input ? "yes" : "no");
switch (io->io_mode)
{
- case IO_FILE:
- fprintf(stderr, "file (%s)\n", io->filename_cstr);
- break;
- case IO_PIPE:
- fprintf(stderr, "pipe {%d, %d}\n", io->param1.pipe_fd[0], io->param1.pipe_fd[1]);
- break;
- case IO_FD:
- fprintf(stderr, "FD map %d -> %d\n", io->param1.old_fd, io->fd);
- break;
- case IO_BUFFER:
- fprintf(stderr, "buffer %p (size %lu)\n", io->out_buffer_ptr(), io->out_buffer_size());
- break;
- case IO_CLOSE:
- fprintf(stderr, "close %d\n", io->fd);
- break;
+ case IO_FILE:
+ fprintf(stderr, "file (%s)\n", io->filename_cstr);
+ break;
+ case IO_PIPE:
+ fprintf(stderr, "pipe {%d, %d}\n", io->param1.pipe_fd[0], io->param1.pipe_fd[1]);
+ break;
+ case IO_FD:
+ fprintf(stderr, "FD map %d -> %d\n", io->param1.old_fd, io->fd);
+ break;
+ case IO_BUFFER:
+ fprintf(stderr, "buffer %p (size %lu)\n", io->out_buffer_ptr(), io->out_buffer_size());
+ break;
+ case IO_CLOSE:
+ fprintf(stderr, "close %d\n", io->fd);
+ break;
}
}
}
-void io_duplicate_prepend( const io_chain_t &src, io_chain_t &dst )
+void io_duplicate_prepend(const io_chain_t &src, io_chain_t &dst)
{
return dst.duplicate_prepend(src);
}
@@ -259,7 +260,8 @@ const io_data_t *io_chain_t::get_io_for_fd(int fd) const
while (idx--)
{
const io_data_t *data = this->at(idx);
- if (data->fd == fd) {
+ if (data->fd == fd)
+ {
return data;
}
}
@@ -272,7 +274,8 @@ io_data_t *io_chain_t::get_io_for_fd(int fd)
while (idx--)
{
io_data_t *data = this->at(idx);
- if (data->fd == fd) {
+ if (data->fd == fd)
+ {
return data;
}
}