Cleanup: open_memstream and close_memstream compat is never used
[lttng-tools.git] / src / lib / lttng-ctl / filter / memstream.h
index 2cbb03559b154c322e0bb7f8f3c1518c72fa0f75..af2a5a77382e96b9e8e7f52764988a84bcab534f 100644 (file)
@@ -19,9 +19,6 @@
  * all copies or substantial portions of the Software.
  */
 
  * all copies or substantial portions of the Software.
  */
 
-#define _GNU_SOURCE
-#include <config.h>
-
 #ifdef LTTNG_HAVE_FMEMOPEN
 #include <stdio.h>
 
 #ifdef LTTNG_HAVE_FMEMOPEN
 #include <stdio.h>
 
@@ -73,156 +70,29 @@ FILE *lttng_fmemopen(void *buf, size_t size, const char *mode)
        }
        ret = fseek(fp, 0L, SEEK_SET);
        if (ret < 0) {
        }
        ret = fseek(fp, 0L, SEEK_SET);
        if (ret < 0) {
-               perror("fseek");
+               PERROR("fseek");
                goto error_close;
        }
        /* We keep the handle open, but can unlink the file on the VFS. */
        ret = unlink(tmpname);
        if (ret < 0) {
                goto error_close;
        }
        /* We keep the handle open, but can unlink the file on the VFS. */
        ret = unlink(tmpname);
        if (ret < 0) {
-               perror("unlink");
+               PERROR("unlink");
        }
        return fp;
 
 error_close:
        ret = fclose(fp);
        if (ret < 0) {
        }
        return fp;
 
 error_close:
        ret = fclose(fp);
        if (ret < 0) {
-               perror("close");
+               PERROR("close");
        }
 error_unlink:
        ret = unlink(tmpname);
        if (ret < 0) {
        }
 error_unlink:
        ret = unlink(tmpname);
        if (ret < 0) {
-               perror("unlink");
+               PERROR("unlink");
        }
        return NULL;
 }
 
 #endif /* LTTNG_HAVE_FMEMOPEN */
 
        }
        return NULL;
 }
 
 #endif /* LTTNG_HAVE_FMEMOPEN */
 
-#ifdef LTTNG_HAVE_OPEN_MEMSTREAM
-
-#include <stdio.h>
-
-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 <stdlib.h>
-#include <stdio.h>
-
-/*
- * 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 */
 #endif /* _LTTNG_CTL_MEMSTREAM_H */
This page took 0.02496 seconds and 4 git commands to generate.