From: Jonathan Rajotte Date: Wed, 14 Mar 2018 17:26:46 +0000 (-0400) Subject: Cleanup: open_memstream and close_memstream compat is never used X-Git-Tag: v2.11.0-rc1~200 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=75acbe19887436248352558828220eb88731d916;hp=979d476d33cfaf3b0a19b802f5f64d5c2649f1d7 Cleanup: open_memstream and close_memstream compat is never used Signed-off-by: Jonathan Rajotte --- diff --git a/configure.ac b/configure.ac index cb36d6b68..7c85cff4a 100644 --- a/configure.ac +++ b/configure.ac @@ -579,13 +579,6 @@ AC_CHECK_LIB([c], [fmemopen], ] ) -# Check for open_memstream -AC_CHECK_LIB([c], [open_memstream], -[ - AC_DEFINE_UNQUOTED([LTTNG_HAVE_OPEN_MEMSTREAM], 1, [Has open_memstream support.]) -] -) - # check for libpfm AC_CHECK_LIB([pfm], [pfm_initialize], [ diff --git a/src/lib/lttng-ctl/filter/memstream.h b/src/lib/lttng-ctl/filter/memstream.h index 6990b6fd7..af2a5a773 100644 --- a/src/lib/lttng-ctl/filter/memstream.h +++ b/src/lib/lttng-ctl/filter/memstream.h @@ -95,131 +95,4 @@ error_unlink: #endif /* LTTNG_HAVE_FMEMOPEN */ -#ifdef LTTNG_HAVE_OPEN_MEMSTREAM - -#include - -static inline -FILE *lttng_open_memstream(char **ptr, size_t *sizeloc) -{ - return open_memstream(ptr, sizeloc); -} - -static inline -int lttng_close_memstream(char **buf, size_t *size, FILE *fp) -{ - return fclose(fp); -} - -#else /* LTTNG_HAVE_OPEN_MEMSTREAM */ - -#include -#include - -/* - * Fallback for systems which don't have open_memstream. Create FILE * - * with lttng_open_memstream, but require call to - * lttng_close_memstream to flush all data written to the FILE * - * into the buffer (which we allocate). - */ -static inline -FILE *lttng_open_memstream(char **ptr, size_t *sizeloc) -{ - char tmpname[PATH_MAX]; - int ret; - FILE *fp; - - strncpy(tmpname, "/tmp/lttng-tmp-XXXXXX", PATH_MAX); - ret = mkstemp(tmpname); - if (ret < 0) { - return NULL; - } - fp = fdopen(ret, "w+"); - if (!fp) { - goto error_unlink; - } - /* - * lttng_flush_memstream will update the buffer content - * with read from fp. No need to keep the file around, just the - * handle. - */ - ret = unlink(tmpname); - if (ret < 0) { - PERROR("unlink"); - } - return fp; - -error_unlink: - ret = unlink(tmpname); - if (ret < 0) { - PERROR("unlink"); - } - return NULL; -} - -/* Get file size, allocate buffer, copy. */ -static inline -int lttng_close_memstream(char **buf, size_t *size, FILE *fp) -{ - size_t len, n; - long pos; - int ret; - - ret = fflush(fp); - if (ret < 0) { - PERROR("fflush"); - return ret; - } - ret = fseek(fp, 0L, SEEK_END); - if (ret < 0) { - PERROR("fseek"); - return ret; - } - pos = ftell(fp); - if (ret < 0) { - PERROR("ftell"); - return ret; - } - *size = pos; - /* add final \0 */ - *buf = calloc(pos + 1, sizeof(char)); - if (!*buf) { - return -ENOMEM; - } - ret = fseek(fp, 0L, SEEK_SET); - if (ret < 0) { - PERROR("fseek"); - goto error_free; - } - /* Copy the entire file into the buffer */ - n = 0; - clearerr(fp); - while (!feof(fp) && !ferror(fp) && (*size - n > 0)) { - len = fread(*buf, sizeof(char), *size - n, fp); - n += len; - } - if (n != *size) { - ret = -1; - goto error_close; - } - ret = fclose(fp); - if (ret < 0) { - PERROR("fclose"); - return ret; - } - return 0; - -error_close: - ret = fclose(fp); - if (ret < 0) { - PERROR("fclose"); - } -error_free: - free(*buf); - *buf = NULL; - return ret; -} - -#endif /* LTTNG_HAVE_OPEN_MEMSTREAM */ - #endif /* _LTTNG_CTL_MEMSTREAM_H */