From 844a920090ff820f38a009573215080483e6e763 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Tue, 2 Jun 2020 17:56:21 -0700 Subject: [PATCH] remove unused gvbuffstderr.c The functions in this file seem to have only been used for past testing. They are not exposed in gvc.h, so we can safely assume no users are calling them. Fixes #1708. --- lib/gvc/Makefile.am | 1 - lib/gvc/gvbuffstderr.c | 95 ------------------------------------------ 2 files changed, 96 deletions(-) delete mode 100644 lib/gvc/gvbuffstderr.c diff --git a/lib/gvc/Makefile.am b/lib/gvc/Makefile.am index 7dca409b4..b4740eaad 100644 --- a/lib/gvc/Makefile.am +++ b/lib/gvc/Makefile.am @@ -35,7 +35,6 @@ pdf_DATA = gvc.3.pdf libgvc_C_la_SOURCES = gvrender.c gvlayout.c gvdevice.c gvloadimage.c \ gvcontext.c gvjobs.c gvevent.c gvplugin.c gvconfig.c \ gvtool_tred.c gvtextlayout.c gvusershape.c gvc.c -# gvbuffstderr.c libgvc_C_la_LIBADD = \ $(top_builddir)/lib/pack/libpack_C.la \ diff --git a/lib/gvc/gvbuffstderr.c b/lib/gvc/gvbuffstderr.c deleted file mode 100644 index 0ecb22303..000000000 --- a/lib/gvc/gvbuffstderr.c +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include -#include -#include -#include - -struct buff_s { - int fd; - fpos_t pos; - char *template; -}; - -/* switch stderr output to temporary file buffering - */ -void *buffstderr(void) -{ -#ifdef _WIN32 - char *p; -#else - int t; -#endif - struct buff_s *b; - - assert ((b = malloc(sizeof(struct buff_s)))); - assert ((b->template = strdup("/tmp/stderr_buffer_XXXXXX"))); -#ifdef _WIN32 - p = mktemp(b->template); - assert (p); -#else - t = mkstemp(b->template); - assert (t > 0); -#endif - fflush(stderr); - fgetpos(stderr, &(b->pos)); - b->fd = dup(fileno(stderr)); - freopen(b->template, "w+", stderr); - return (void *)b; -} - -/* switch stderr output back to normal, - * and return any buffered output in a malloc'ed buffer - */ -char *unbuffstderr(struct buff_s *b) -{ - long sz; - char *t = NULL; - FILE *f; - - fflush(stderr); - sz = ftell(stderr); - dup2(b->fd, fileno(stderr)); - close(b->fd); - clearerr(stderr); - fsetpos(stderr, &(b->pos)); - - if (sz) { - /* stderr has been restored; these asserts use normal stderr output */ - assert((t = malloc(sz+1))); - assert((f = fopen(b->template, "r"))); - assert( fread(t, 1, sz, f) == sz); - fclose(f); - t[sz]='\0'; - } - - unlink(b->template); - free(b->template); - free(b); - - return t; -} - -#if 0 /* FOR TESTING */ -int main (int argc, char *argv[]) { - - void *buff; - char *text; - - fprintf(stderr, "First message\n"); - - buff = buffstderr(); - fprintf(stderr, "Second message\n"); - - fprintf(stderr, "Third message\n"); - - text = unbuffstderr(buff); - fprintf(stderr, "Fourth message\n"); - - if (text) { - fprintf(stderr, text); - free(text); - } - - return 0; -} -#endif -- 2.40.0