/* Copyright 2001 Mark Pulford * This file is subject to the terms and conditions of the GNU General Public * License. Read the file COPYING found in this archive for details, or * visit http://www.gnu.org/copyleft/gpl.html */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #ifdef HAVE_GETOPT_H #include #endif /* Split conditions */ int split_bytes = 0; int split_lines = 0; int padding_size = 1; char **command_argv; int command_count = 0; int fatal_code = 255; int pipe_exec(char **argv, int write); int split_output(int *fd, char *buf, int size); int safe_write(int *fd, const char *buf, int size); void write_zero(int fd, int size); void reap_child(int *fd); char next_arg(int argc, char **argv); void check_args(int argc, char **argv); int size2num(int *size, const char *s); int str2num(int *size, const char *s); void version(); void usage(); int main(int argc, char **argv) { char *buf; int bsize = 4096; int rsize; int fd = -1; int done = 0; check_args(argc, argv); buf = malloc(bsize); if(!buf) { fprintf(stderr, "xin: Out of memory\n"); exit(-1); } signal(SIGPIPE, SIG_IGN); /* Only exec the command if there is input that needs to be handled */ while( (rsize = read(0, buf, bsize)) ) { if(rsize < 0) { if(errno == EINTR) continue; perror("xin: read"); exit(-1); } done = split_output(&fd, buf, rsize); } if(fd != -1) { if(done % padding_size) write_zero(fd, padding_size - done % padding_size); reap_child(&fd); } return 0; } void write_zero(int fd, int size) { char buf[4096]; int s; memset(buf, 0, sizeof(buf)); while(size > 0) { s = sizeof(buf)