X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglwrap.c;h=f801a20aae2b71b3c4561215da9f250035df2240;hb=ef5baa3143441b46f5d8e515adff16737bb9439d;hp=52c6552e1f5c0c007939e62f07a31e233ba8e587;hpb=03c86c2f632b642aa94f721e326787e91aa69c25;p=gldbg.git diff --git a/source/glwrap.c b/source/glwrap.c index 52c6552..f801a20 100644 --- a/source/glwrap.c +++ b/source/glwrap.c @@ -8,7 +8,9 @@ Distributed under the GPL #include #include #include +#include #include +#include #include #define INTERNAL __attribute__((visibility("internal"))) @@ -175,27 +177,64 @@ INTERNAL inline void begin_packet(int func) buffer = (char *)malloc(1024); if(!iovecs) iovecs = (struct iovec *)malloc(16*sizeof(struct iovec)); + write_pos = buffer; cur_vec = iovecs; cur_vec->iov_base = write_pos; length = 0; + write_int(0); write_short(func); } -INTERNAL inline void send_packet(void) +INTERNAL inline int get_out_fd(void) { static int fd = -1; + if(fd<0) { const char *var = getenv("GLWRAP_FD"); if(var) fd = strtol(var, NULL, 0); else - fd = 2; + { + var = getenv("GLWRAP_FILE"); + if(var) + { + fd = open(var, O_WRONLY|O_CREAT, 0644); + if(fd==-1) + { + fprintf(stderr, "Couldn't open dumpfile %s for output: %s", var, strerror(errno)); + abort(); + } + } + else + fd = 2; + } } + + return fd; +} + +INTERNAL inline void send_partial_packet(void) +{ + next_vec(); + write_pos = buffer; + write_int(length|0x80000000); + writev(get_out_fd(), iovecs, cur_vec-iovecs); + + write_pos = buffer; + cur_vec = iovecs; + cur_vec->iov_base = write_pos; + length = 0; + + write_int(0); +} + +INTERNAL inline void send_packet(void) +{ next_vec(); write_pos = buffer; write_int(length); - writev(fd, iovecs, cur_vec-iovecs); + writev(get_out_fd(), iovecs, cur_vec-iovecs); }